The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2 | * |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | package com.android.internal.policy.impl; |
| 17 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 18 | import android.app.ActivityManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 19 | import android.app.ActivityManagerNative; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 20 | import android.app.AppOpsManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 21 | import android.app.IUiModeManager; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 22 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 23 | import android.app.SearchManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 24 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 25 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 26 | import android.content.BroadcastReceiver; |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 27 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 28 | import android.content.ContentResolver; |
| 29 | import android.content.Context; |
| 30 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 31 | import android.content.IntentFilter; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 32 | import android.content.ServiceConnection; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 33 | import android.content.pm.ActivityInfo; |
| 34 | import android.content.pm.PackageManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 35 | import android.content.pm.ResolveInfo; |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 36 | import android.content.pm.UserInfo; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 37 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 38 | import android.content.res.Configuration; |
| 39 | import android.content.res.Resources; |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 40 | import android.content.res.TypedArray; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 41 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 42 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 43 | import android.graphics.Rect; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 44 | import android.media.AudioManager; |
| 45 | import android.media.IAudioService; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 46 | import android.media.Ringtone; |
| 47 | import android.media.RingtoneManager; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 48 | import android.os.Bundle; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 49 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 50 | import android.os.Handler; |
| 51 | import android.os.IBinder; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 52 | import android.os.IRemoteCallback; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 53 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 54 | import android.os.Message; |
| 55 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 56 | import android.os.PowerManager; |
| 57 | import android.os.RemoteException; |
| 58 | import android.os.ServiceManager; |
| 59 | import android.os.SystemClock; |
| 60 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 61 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 62 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 63 | import android.os.Vibrator; |
| 64 | import android.provider.Settings; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 65 | import android.service.dreams.DreamService; |
| 66 | import android.service.dreams.IDreamManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 67 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 68 | import android.util.EventLog; |
| 69 | import android.util.Log; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 70 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 71 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 72 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 73 | import android.view.Gravity; |
| 74 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 75 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 76 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 77 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 78 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 79 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 80 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 81 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 82 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 83 | import android.view.KeyEvent; |
| 84 | import android.view.MotionEvent; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 85 | import android.view.Surface; |
| 86 | import android.view.View; |
| 87 | import android.view.ViewConfiguration; |
| 88 | import android.view.Window; |
| 89 | import android.view.WindowManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 90 | import android.view.WindowManagerGlobal; |
| 91 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 92 | import android.view.accessibility.AccessibilityEvent; |
| 93 | import android.view.animation.Animation; |
| 94 | import android.view.animation.AnimationUtils; |
| 95 | |
| 96 | import com.android.internal.R; |
| 97 | import com.android.internal.policy.PolicyManager; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 98 | import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 99 | import com.android.internal.statusbar.IStatusBarService; |
| 100 | import com.android.internal.telephony.ITelephony; |
| 101 | import com.android.internal.widget.PointerLocationView; |
| 102 | |
| 103 | import java.io.File; |
| 104 | import java.io.FileReader; |
| 105 | import java.io.IOException; |
| 106 | import java.io.PrintWriter; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 107 | import java.util.HashSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 108 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 109 | import static android.view.WindowManager.LayoutParams.*; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 110 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 111 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
| 112 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 113 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 114 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 115 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 116 | * introduces a new method suffix, Lp, for an internal lock of the |
| 117 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 118 | * can be acquired with either the Lw and Li lock held, so has the restrictions |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 119 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 120 | */ |
| 121 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 122 | static final String TAG = "WindowManager"; |
| 123 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 124 | static final boolean localLOGV = false; |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 125 | static final boolean DEBUG_LAYOUT = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 126 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 127 | static final boolean DEBUG_STARTING_WINDOW = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 128 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 129 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 130 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 131 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 132 | // No longer recommended for desk docks; still useful in car docks. |
| 133 | static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true; |
| 134 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 135 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 136 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 137 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 138 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 139 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 140 | |
| 141 | // These need to match the documentation/constant in |
| 142 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 143 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 144 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 145 | static final int LONG_PRESS_HOME_ASSIST = 2; |
| 146 | |
| 147 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 148 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 149 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 150 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 151 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 152 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 153 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 154 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 155 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 156 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 157 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 158 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 159 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 160 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 161 | /** |
| 162 | * These are the system UI flags that, when changing, can cause the layout |
| 163 | * of the screen to change. |
| 164 | */ |
| 165 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
| 166 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN; |
| 167 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 168 | /** |
| 169 | * Keyguard stuff |
| 170 | */ |
| 171 | private WindowState mKeyguardScrim; |
| 172 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 173 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 174 | * |
| 175 | * These are special keys that are used to launch particular kinds of applications, |
| 176 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 177 | * usage page. We don't support quite that many yet... |
| 178 | */ |
| 179 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 180 | static { |
| 181 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 182 | sApplicationLaunchKeyCategories.append( |
| 183 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 184 | sApplicationLaunchKeyCategories.append( |
| 185 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 186 | sApplicationLaunchKeyCategories.append( |
| 187 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 188 | sApplicationLaunchKeyCategories.append( |
| 189 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 190 | sApplicationLaunchKeyCategories.append( |
| 191 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 192 | sApplicationLaunchKeyCategories.append( |
| 193 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 194 | } |
| 195 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 196 | /** |
| 197 | * Lock protecting internal state. Must not call out into window |
| 198 | * manager with lock held. (This lock will be acquired in places |
| 199 | * where the window manager is calling in with its own lock held.) |
| 200 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 201 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 202 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 203 | Context mContext; |
| 204 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 205 | WindowManagerFuncs mWindowManagerFuncs; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 206 | PowerManager mPowerManager; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 207 | IStatusBarService mStatusBarService; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 208 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 209 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 210 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 211 | SearchManager mSearchManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 212 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 213 | // Vibrator pattern for haptic feedback of a long press. |
| 214 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 215 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 216 | // Vibrator pattern for haptic feedback of virtual key press. |
| 217 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 218 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 219 | // Vibrator pattern for a short vibration. |
| 220 | long[] mKeyboardTapVibePattern; |
| 221 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 222 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 223 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 224 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 225 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 226 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 227 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 228 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 229 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 230 | |
| 231 | boolean mHeadless; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 232 | boolean mSafeMode; |
| 233 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 234 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 235 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 236 | boolean mHasNavigationBar = false; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 237 | boolean mCanHideNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 238 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
| 239 | boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? |
| 240 | int[] mNavigationBarHeightForRotation = new int[4]; |
| 241 | int[] mNavigationBarWidthForRotation = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 242 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 243 | WindowState mKeyguard = null; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 244 | KeyguardServiceDelegate mKeyguardDelegate; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 245 | GlobalActions mGlobalActions; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 246 | volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread |
| 247 | boolean mPendingPowerKeyUpCanceled; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 248 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 249 | WindowState mLastInputMethodWindow = null; |
| 250 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 251 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 252 | static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0; |
| 253 | static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1; |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 254 | static final int RECENT_APPS_BEHAVIOR_DISMISS = 2; |
| 255 | static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 3; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 256 | |
| 257 | RecentApplicationsDialog mRecentAppsDialog; |
| 258 | int mRecentAppsDialogHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 259 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 260 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 261 | int mLidState = LID_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 262 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 263 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 264 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 265 | boolean mSystemBooted; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 266 | boolean mHdmiPlugged; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 267 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 268 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 269 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 270 | int mCarDockRotation; |
| 271 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 272 | int mUndockedHdmiRotation; |
| 273 | int mDemoHdmiRotation; |
| 274 | boolean mDemoHdmiRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 275 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 276 | // Default display does not rotate, apps that require non-default orientation will have to |
| 277 | // have the orientation emulated. |
| 278 | private boolean mForceDefaultOrientation = false; |
| 279 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 280 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 281 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 282 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 283 | |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 284 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 285 | boolean mCarDockEnablesAccelerometer; |
| 286 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 287 | int mLidKeyboardAccessibility; |
| 288 | int mLidNavigationAccessibility; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 289 | boolean mLidControlsSleep; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 290 | int mLongPressOnPowerBehavior = -1; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 291 | boolean mScreenOnEarly = false; |
| 292 | boolean mScreenOnFully = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 293 | boolean mOrientationSensorEnabled = false; |
| 294 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 295 | boolean mHasSoftInput = false; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 296 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 297 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 298 | |
| 299 | // The last window we were told about in focusChanged. |
| 300 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 301 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 302 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 303 | private final class PointerLocationPointerEventListener implements PointerEventListener { |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 304 | @Override |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 305 | public void onPointerEvent(MotionEvent motionEvent) { |
| 306 | if (mPointerLocationView != null) { |
| 307 | mPointerLocationView.addPointerEvent(motionEvent); |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 308 | } |
| 309 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 310 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 311 | |
| 312 | // Pointer location view state, only modified on the mHandler Looper. |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 313 | PointerLocationPointerEventListener mPointerLocationPointerEventListener; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 314 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 315 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 316 | // The current size of the screen; really; extends into the overscan area of |
| 317 | // the screen and doesn't account for any system elements like the status bar. |
| 318 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 319 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 320 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 321 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 322 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 323 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 324 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 325 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 326 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 327 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 328 | // if the status bar can't be hidden; in that case it effectively carves out |
| 329 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 330 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 331 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 332 | // During layout, the current screen borders accounting for any currently |
| 333 | // visible system UI elements. |
| 334 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 335 | // For applications requesting stable content insets, these are them. |
| 336 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 337 | // For applications requesting stable content insets but have also set the |
| 338 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 339 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 340 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 341 | // During layout, the current screen borders with all outer decoration |
| 342 | // (status bar, input method dock) accounted for. |
| 343 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 344 | // During layout, the frame in which content should be displayed |
| 345 | // to the user, accounting for all screen decoration except for any |
| 346 | // space they deem as available for other content. This is usually |
| 347 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 348 | // content insets. |
| 349 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 350 | // 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] | 351 | // windows are placed. |
| 352 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 353 | // During layout, the layer at which the doc window is placed. |
| 354 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 355 | // During layout, this is the layer of the status bar. |
| 356 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 357 | int mLastSystemUiFlags; |
| 358 | // Bits that we are in the process of clearing, so we want to prevent |
| 359 | // them from being set by applications until everything has been updated |
| 360 | // to have them clear. |
| 361 | int mResettingSystemUiFlags = 0; |
| 362 | // Bits that we are currently always keeping cleared. |
| 363 | int mForceClearedSystemUiFlags = 0; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 364 | // What we last reported to system UI about whether the compatibility |
| 365 | // menu needs to be displayed. |
| 366 | boolean mLastFocusNeedsMenu = false; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 367 | |
| 368 | FakeWindow mHideNavFakeWindow = null; |
| 369 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 370 | static final Rect mTmpParentFrame = new Rect(); |
| 371 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 372 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 373 | static final Rect mTmpContentFrame = new Rect(); |
| 374 | static final Rect mTmpVisibleFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 375 | static final Rect mTmpNavigationFrame = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 376 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 377 | WindowState mTopFullscreenOpaqueWindowState; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 378 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 379 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 380 | boolean mForceStatusBarFromKeyguard; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 381 | boolean mHideLockScreen; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 382 | boolean mForcingShowNavBar; |
| 383 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 384 | |
| 385 | // States of keyguard dismiss. |
| 386 | private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. |
| 387 | private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. |
| 388 | private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. |
| 389 | int mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
| 390 | |
| 391 | /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only |
| 392 | * be done once per window. */ |
| 393 | private WindowState mWinDismissingKeyguard; |
| 394 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 395 | boolean mShowingLockscreen; |
| 396 | boolean mShowingDream; |
| 397 | boolean mDreamingLockscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 398 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 399 | boolean mHomeConsumed; |
| 400 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 401 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 402 | Intent mCarDockIntent; |
| 403 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 404 | boolean mSearchKeyShortcutPending; |
| 405 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 406 | boolean mAssistKeyLongPressed; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 407 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 408 | // support for activating the lock screen while the screen is on |
| 409 | boolean mAllowLockscreenWhenOn; |
| 410 | int mLockScreenTimeout; |
| 411 | boolean mLockScreenTimerActive; |
| 412 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 413 | // 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] | 414 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 415 | |
| 416 | // Behavior of POWER button while in-call and screen on. |
| 417 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 418 | int mIncallPowerBehavior; |
| 419 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 420 | Display mDisplay; |
| 421 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 422 | int mLandscapeRotation = 0; // default landscape rotation |
| 423 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 424 | int mPortraitRotation = 0; // default portrait rotation |
| 425 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 426 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 427 | int mOverscanLeft = 0; |
| 428 | int mOverscanTop = 0; |
| 429 | int mOverscanRight = 0; |
| 430 | int mOverscanBottom = 0; |
| 431 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 432 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 433 | private int mLongPressOnHomeBehavior; |
| 434 | |
| 435 | // What we do when the user double-taps on home |
| 436 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 437 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 438 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 439 | // Time to volume and power must be pressed within this interval of each other. |
| 440 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 441 | // Increase the chord delay when taking a screenshot from the keyguard |
| 442 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 443 | private boolean mScreenshotChordEnabled; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 444 | private boolean mVolumeDownKeyTriggered; |
| 445 | private long mVolumeDownKeyTime; |
| 446 | private boolean mVolumeDownKeyConsumedByScreenshotChord; |
| 447 | private boolean mVolumeUpKeyTriggered; |
| 448 | private boolean mPowerKeyTriggered; |
| 449 | private long mPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 450 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 451 | /* The number of steps between min and max brightness */ |
| 452 | private static final int BRIGHTNESS_STEPS = 10; |
| 453 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 454 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 455 | ShortcutManager mShortcutManager; |
| 456 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 457 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 458 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 459 | // Maps global key codes to the components that will handle them. |
| 460 | private GlobalKeyManager mGlobalKeyManager; |
| 461 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 462 | // Fallback actions by key code. |
| 463 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 464 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 465 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 466 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 467 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 468 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 469 | 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] | 470 | |
| 471 | private class PolicyHandler extends Handler { |
| 472 | @Override |
| 473 | public void handleMessage(Message msg) { |
| 474 | switch (msg.what) { |
| 475 | case MSG_ENABLE_POINTER_LOCATION: |
| 476 | enablePointerLocation(); |
| 477 | break; |
| 478 | case MSG_DISABLE_POINTER_LOCATION: |
| 479 | disablePointerLocation(); |
| 480 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 481 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 482 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 483 | break; |
| 484 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 485 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 486 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 491 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 492 | @Override |
| 493 | public void onUEvent(UEventObserver.UEvent event) { |
| 494 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 495 | } |
| 496 | }; |
| 497 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 498 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 499 | SettingsObserver(Handler handler) { |
| 500 | super(handler); |
| 501 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 502 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 503 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 504 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 505 | ContentResolver resolver = mContext.getContentResolver(); |
| 506 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 507 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 508 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 509 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 510 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 511 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 512 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 513 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 514 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 515 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 516 | Settings.System.USER_ROTATION), false, this, |
| 517 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 518 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 519 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 520 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 521 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 522 | Settings.System.POINTER_LOCATION), false, this, |
| 523 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 524 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 525 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 526 | UserHandle.USER_ALL); |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 527 | resolver.registerContentObserver(Settings.System.getUriFor( |
John Spurlock | 245fd01 | 2013-05-31 10:31:04 -0400 | [diff] [blame] | 528 | OverlayTesting.ENABLED_SETTING), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 529 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 530 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 534 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 535 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 536 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 537 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 538 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 539 | class MyOrientationListener extends WindowOrientationListener { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 540 | MyOrientationListener(Context context, Handler handler) { |
| 541 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 542 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 543 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 544 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 545 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 546 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 547 | updateRotation(false); |
| 548 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 549 | } |
| 550 | MyOrientationListener mOrientationListener; |
| 551 | |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 552 | private static final int HIDEYBAR_NONE = 0; |
| 553 | private static final int HIDEYBAR_SHOWING = 1; |
| 554 | private static final int HIDEYBAR_HIDING = 2; |
| 555 | private int mStatusHideybar; |
| 556 | private int mNavigationHideybar; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 557 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 558 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 559 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 560 | IStatusBarService getStatusBarService() { |
| 561 | synchronized (mServiceAquireLock) { |
| 562 | if (mStatusBarService == null) { |
| 563 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 564 | ServiceManager.getService("statusbar")); |
| 565 | } |
| 566 | return mStatusBarService; |
| 567 | } |
| 568 | } |
| 569 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 570 | /* |
| 571 | * We always let the sensor be switched on by default except when |
| 572 | * the user has explicitly disabled sensor based rotation or when the |
| 573 | * screen is switched off. |
| 574 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 575 | boolean needSensorRunningLp() { |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 576 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 577 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 578 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 579 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 580 | // If the application has explicitly requested to follow the |
| 581 | // orientation, then we need to turn the sensor or. |
| 582 | return true; |
| 583 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 584 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 585 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 586 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 587 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 588 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 589 | // orientation management, |
| 590 | return true; |
| 591 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 592 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 593 | // If the setting for using the sensor by default is enabled, then |
| 594 | // we will always leave it on. Note that the user could go to |
| 595 | // a window that forces an orientation that does not use the |
| 596 | // sensor and in theory we could turn it off... however, when next |
| 597 | // turning it on we won't have a good value for the current |
| 598 | // orientation for a little bit, which can cause orientation |
| 599 | // changes to lag, so we'd like to keep it always on. (It will |
| 600 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 601 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 602 | } |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 603 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 604 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 605 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 606 | /* |
| 607 | * Various use cases for invoking this function |
| 608 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 609 | * screen turned on and current app has sensor based orientation, enable listeners |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 610 | * if not already enabled |
| 611 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 612 | * already enabled |
| 613 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 614 | * screen turning on and current app has nosensor based orientation, do nothing |
| 615 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 616 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 617 | if (!mOrientationListener.canDetectOrientation()) { |
| 618 | // If sensor is turned off or nonexistent for some reason |
| 619 | return; |
| 620 | } |
| 621 | //Could have been invoked due to screen turning on or off or |
| 622 | //change of the currently visible window's orientation |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 623 | if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 624 | ", current orientation="+mCurrentAppOrientation+ |
| 625 | ", SensorEnabled="+mOrientationSensorEnabled); |
| 626 | boolean disable = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 627 | if (mScreenOnEarly) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 628 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 629 | disable = false; |
| 630 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 631 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 632 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 633 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 634 | mOrientationSensorEnabled = true; |
| 635 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 636 | } |
| 637 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 638 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 639 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 640 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 641 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 642 | mOrientationSensorEnabled = false; |
| 643 | } |
| 644 | } |
| 645 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 646 | private void interceptPowerKeyDown(boolean handled) { |
| 647 | mPowerKeyHandled = handled; |
| 648 | if (!handled) { |
| 649 | mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout()); |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | private boolean interceptPowerKeyUp(boolean canceled) { |
| 654 | if (!mPowerKeyHandled) { |
| 655 | mHandler.removeCallbacks(mPowerLongPress); |
| 656 | return !canceled; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 657 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 658 | return false; |
| 659 | } |
| 660 | |
| 661 | private void cancelPendingPowerKeyAction() { |
| 662 | if (!mPowerKeyHandled) { |
| 663 | mHandler.removeCallbacks(mPowerLongPress); |
| 664 | } |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 665 | if (mPowerKeyTriggered) { |
| 666 | mPendingPowerKeyUpCanceled = true; |
| 667 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 671 | if (mScreenshotChordEnabled |
| 672 | && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 673 | final long now = SystemClock.uptimeMillis(); |
| 674 | if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 675 | && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 676 | mVolumeDownKeyConsumedByScreenshotChord = true; |
| 677 | cancelPendingPowerKeyAction(); |
| 678 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 679 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | } |
| 683 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 684 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 685 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 686 | // Double the time it takes to take a screenshot from the keyguard |
| 687 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
| 688 | ViewConfiguration.getGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 689 | } |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 690 | return ViewConfiguration.getGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 691 | } |
| 692 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 693 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 694 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | private final Runnable mPowerLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 698 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 699 | public void run() { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 700 | // The context isn't read |
| 701 | if (mLongPressOnPowerBehavior < 0) { |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 702 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 703 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 704 | } |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 705 | int resolvedBehavior = mLongPressOnPowerBehavior; |
| 706 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 707 | resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 708 | } |
| 709 | |
| 710 | switch (resolvedBehavior) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 711 | case LONG_PRESS_POWER_NOTHING: |
| 712 | break; |
| 713 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 714 | mPowerKeyHandled = true; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 715 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 716 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 717 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 718 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 719 | showGlobalActionsDialog(); |
| 720 | break; |
| 721 | case LONG_PRESS_POWER_SHUT_OFF: |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 722 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 723 | mPowerKeyHandled = true; |
| 724 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 725 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 726 | mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 727 | break; |
| 728 | } |
| 729 | } |
| 730 | }; |
| 731 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 732 | private final Runnable mScreenshotRunnable = new Runnable() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 733 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 734 | public void run() { |
| 735 | takeScreenshot(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 736 | } |
| 737 | }; |
| 738 | |
| 739 | void showGlobalActionsDialog() { |
| 740 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 741 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 742 | } |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 743 | final boolean keyguardShowing = keyguardIsShowingTq(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 744 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 745 | if (keyguardShowing) { |
| 746 | // since it took two seconds of long press to bring this up, |
| 747 | // poke the wake lock so they have some time to see the dialog. |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 748 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 749 | } |
| 750 | } |
| 751 | |
| 752 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 753 | return Settings.Global.getInt( |
| 754 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 755 | } |
| 756 | |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 757 | private void handleLongPressOnHome() { |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 758 | if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 759 | mHomeConsumed = true; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 760 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 761 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 762 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { |
| 763 | toggleRecentApps(); |
| 764 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) { |
| 765 | launchAssistAction(); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 766 | } |
| 767 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 768 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 769 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 770 | private void handleDoubleTapOnHome() { |
| 771 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 772 | mHomeConsumed = true; |
| 773 | toggleRecentApps(); |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 778 | @Override |
| 779 | public void run() { |
| 780 | if (mHomeDoubleTapPending) { |
| 781 | mHomeDoubleTapPending = false; |
| 782 | launchHomeFromHotKey(); |
| 783 | } |
| 784 | } |
| 785 | }; |
| 786 | |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 787 | /** |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 788 | * Create (if necessary) and show or dismiss the recent apps dialog according |
| 789 | * according to the requested behavior. |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 790 | */ |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 791 | void showOrHideRecentAppsDialog(final int behavior) { |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 792 | mHandler.post(new Runnable() { |
| 793 | @Override |
| 794 | public void run() { |
| 795 | if (mRecentAppsDialog == null) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 796 | mRecentAppsDialog = new RecentApplicationsDialog(mContext); |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 797 | } |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 798 | if (mRecentAppsDialog.isShowing()) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 799 | switch (behavior) { |
| 800 | case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS: |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 801 | case RECENT_APPS_BEHAVIOR_DISMISS: |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 802 | mRecentAppsDialog.dismiss(); |
| 803 | break; |
| 804 | case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH: |
| 805 | mRecentAppsDialog.dismissAndSwitch(); |
| 806 | break; |
| 807 | case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW: |
| 808 | default: |
| 809 | break; |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 810 | } |
| 811 | } else { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 812 | switch (behavior) { |
| 813 | case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS: |
| 814 | mRecentAppsDialog.show(); |
| 815 | break; |
| 816 | case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW: |
| 817 | try { |
| 818 | mWindowManager.setInTouchMode(false); |
| 819 | } catch (RemoteException e) { |
| 820 | } |
| 821 | mRecentAppsDialog.show(); |
| 822 | break; |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 823 | case RECENT_APPS_BEHAVIOR_DISMISS: |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 824 | case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH: |
| 825 | default: |
| 826 | break; |
| 827 | } |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 828 | } |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 829 | } |
| 830 | }); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 831 | } |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 832 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 833 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 834 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 835 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 836 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 837 | mContext = context; |
| 838 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 839 | mWindowManagerFuncs = windowManagerFuncs; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 840 | mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0")); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 841 | mHandler = new PolicyHandler(); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 842 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 843 | try { |
| 844 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 845 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 846 | mSettingsObserver = new SettingsObserver(mHandler); |
| 847 | mSettingsObserver.observe(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 848 | mShortcutManager = new ShortcutManager(context, mHandler); |
| 849 | mShortcutManager.observe(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 850 | mUiMode = context.getResources().getInteger( |
| 851 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 852 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 853 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 854 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 855 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 856 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 857 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 858 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 859 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 860 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 861 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 862 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 863 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 864 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 865 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 866 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 867 | "PhoneWindowManager.mBroadcastWakeLock"); |
| 868 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 869 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 870 | com.android.internal.R.integer.config_lidOpenRotation); |
| 871 | mCarDockRotation = readRotation( |
| 872 | com.android.internal.R.integer.config_carDockRotation); |
| 873 | mDeskDockRotation = readRotation( |
| 874 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 875 | mUndockedHdmiRotation = readRotation( |
| 876 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 877 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 878 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 879 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 880 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 881 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 882 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 883 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 884 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 885 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 886 | com.android.internal.R.bool.config_lidControlsSleep); |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 887 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 888 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 889 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 890 | IntentFilter filter = new IntentFilter(); |
| 891 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 892 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 893 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 894 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 895 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 896 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 897 | if (intent != null) { |
| 898 | // Retrieve current sticky dock event broadcast. |
| 899 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 900 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 901 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 902 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 903 | // register for dream-related broadcasts |
| 904 | filter = new IntentFilter(); |
| 905 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 906 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 907 | context.registerReceiver(mDreamReceiver, filter); |
| 908 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 909 | // register for multiuser-relevant broadcasts |
| 910 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 911 | context.registerReceiver(mMultiuserReceiver, filter); |
| 912 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 913 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 914 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 915 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 916 | @Override |
| 917 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 918 | if (mStatusBar != null) { |
| 919 | requestHideybars(mStatusBar); |
| 920 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 921 | } |
| 922 | @Override |
| 923 | public void onSwipeFromBottom() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 924 | if (mNavigationBar != null && mNavigationBarOnBottom) { |
| 925 | requestHideybars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 926 | } |
| 927 | } |
| 928 | @Override |
| 929 | public void onSwipeFromRight() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 930 | if (mNavigationBar != null && !mNavigationBarOnBottom) { |
| 931 | requestHideybars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 932 | } |
| 933 | } |
| 934 | @Override |
| 935 | public void onDebug() { |
John Spurlock | 245fd01 | 2013-05-31 10:31:04 -0400 | [diff] [blame] | 936 | if (OverlayTesting.enabled) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 937 | OverlayTesting.toggleForceOverlay(mFocusedWindow, mContext); |
| 938 | } |
| 939 | } |
| 940 | }); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 941 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 942 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 943 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 944 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 945 | com.android.internal.R.array.config_longPressVibePattern); |
| 946 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 947 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 948 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 949 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 950 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 951 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 952 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 953 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 954 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 955 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 956 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 957 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 958 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 959 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 960 | // Controls rotation and the like. |
| 961 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 962 | |
| 963 | // Match current screen state. |
| 964 | if (mPowerManager.isScreenOn()) { |
| 965 | screenTurningOn(null); |
| 966 | } else { |
| 967 | screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 968 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 969 | } |
| 970 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 971 | /** |
| 972 | * Read values from config.xml that may be overridden depending on |
| 973 | * the configuration of the device. |
| 974 | * eg. Disable long press on home goes to recents on sw600dp. |
| 975 | */ |
| 976 | private void readConfigurationDependentBehaviors() { |
| 977 | mLongPressOnHomeBehavior = mContext.getResources().getInteger( |
| 978 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 979 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
| 980 | mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) { |
| 981 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 982 | } |
| 983 | |
| 984 | mDoubleTapOnHomeBehavior = mContext.getResources().getInteger( |
| 985 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 986 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 987 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 988 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 989 | } |
| 990 | } |
| 991 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 992 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 993 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 994 | if (display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 995 | throw new IllegalArgumentException("Can only set the default display"); |
| 996 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 997 | mDisplay = display; |
| 998 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 999 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1000 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1001 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1002 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1003 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1004 | mLandscapeRotation = Surface.ROTATION_0; |
| 1005 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 1006 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1007 | mPortraitRotation = Surface.ROTATION_90; |
| 1008 | mUpsideDownRotation = Surface.ROTATION_270; |
| 1009 | } else { |
| 1010 | mPortraitRotation = Surface.ROTATION_270; |
| 1011 | mUpsideDownRotation = Surface.ROTATION_90; |
| 1012 | } |
| 1013 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1014 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1015 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1016 | mPortraitRotation = Surface.ROTATION_0; |
| 1017 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 1018 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1019 | mLandscapeRotation = Surface.ROTATION_270; |
| 1020 | mSeascapeRotation = Surface.ROTATION_90; |
| 1021 | } else { |
| 1022 | mLandscapeRotation = Surface.ROTATION_90; |
| 1023 | mSeascapeRotation = Surface.ROTATION_270; |
| 1024 | } |
| 1025 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1026 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 1027 | mStatusBarHeight = |
| 1028 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1029 | |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1030 | // Height of the navigation bar when presented horizontally at bottom |
| 1031 | mNavigationBarHeightForRotation[mPortraitRotation] = |
| 1032 | mNavigationBarHeightForRotation[mUpsideDownRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 1033 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1034 | mNavigationBarHeightForRotation[mLandscapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 1035 | mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize( |
| 1036 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1037 | |
| 1038 | // Width of the navigation bar when presented vertically along one side |
| 1039 | mNavigationBarWidthForRotation[mPortraitRotation] = |
| 1040 | mNavigationBarWidthForRotation[mUpsideDownRotation] = |
| 1041 | mNavigationBarWidthForRotation[mLandscapeRotation] = |
| 1042 | mNavigationBarWidthForRotation[mSeascapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 1043 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1044 | |
| 1045 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1046 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 1047 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1048 | |
Craig Mautner | d4ec3324 | 2013-07-22 10:37:43 -0700 | [diff] [blame] | 1049 | // Allow the navigation bar to move on small devices (phones). |
| 1050 | mNavigationBarCanMove = shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 1051 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 1052 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1053 | // Allow a system property to override this. Used by the emulator. |
| 1054 | // See also hasNavigationBar(). |
| 1055 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 1056 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1057 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1058 | } else if ("0".equals(navBarOverride)) { |
| 1059 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1060 | } |
| 1061 | |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1062 | if (mHasNavigationBar) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1063 | // The navigation bar is at the right in landscape; it seems always |
| 1064 | // useful to hide it for showing a video. |
| 1065 | mCanHideNavigationBar = true; |
| 1066 | } else { |
| 1067 | mCanHideNavigationBar = false; |
| 1068 | } |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1069 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1070 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1071 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1072 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1073 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1074 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1075 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1076 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1077 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 1078 | |
| 1079 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 1080 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 1081 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 1082 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 1083 | // For debug purposes the next line turns this feature off with: |
| 1084 | // $ adb shell setprop config.override_forced_orient true |
| 1085 | // $ adb shell wm size reset |
| 1086 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 1087 | } |
| 1088 | |
| 1089 | @Override |
| 1090 | public boolean isDefaultOrientationForced() { |
| 1091 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1094 | @Override |
| 1095 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1096 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1097 | mOverscanLeft = left; |
| 1098 | mOverscanTop = top; |
| 1099 | mOverscanRight = right; |
| 1100 | mOverscanBottom = bottom; |
| 1101 | } |
| 1102 | } |
| 1103 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1104 | public void updateSettings() { |
| 1105 | ContentResolver resolver = mContext.getContentResolver(); |
| 1106 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1107 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1108 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1109 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1110 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1111 | UserHandle.USER_CURRENT); |
| 1112 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1113 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1114 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1115 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1116 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1117 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1118 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1119 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1120 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1121 | if (mUserRotation != userRotation) { |
| 1122 | mUserRotation = userRotation; |
| 1123 | updateRotation = true; |
| 1124 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1125 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1126 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1127 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1128 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1129 | if (mUserRotationMode != userRotationMode) { |
| 1130 | mUserRotationMode = userRotationMode; |
| 1131 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1132 | updateOrientationListenerLp(); |
| 1133 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1134 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1135 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1136 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1137 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1138 | if (mPointerLocationMode != pointerLocation) { |
| 1139 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1140 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1141 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1142 | } |
| 1143 | } |
| 1144 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1145 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1146 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1147 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1148 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1149 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1150 | if (mHasSoftInput != hasSoftInput) { |
| 1151 | mHasSoftInput = hasSoftInput; |
| 1152 | updateRotation = true; |
| 1153 | } |
John Spurlock | 245fd01 | 2013-05-31 10:31:04 -0400 | [diff] [blame] | 1154 | OverlayTesting.enabled = Settings.System.getIntForUser(resolver, |
| 1155 | OverlayTesting.ENABLED_SETTING, 0, UserHandle.USER_CURRENT) != 0; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1156 | } |
| 1157 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1158 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1159 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | private void enablePointerLocation() { |
| 1163 | if (mPointerLocationView == null) { |
| 1164 | mPointerLocationView = new PointerLocationView(mContext); |
| 1165 | mPointerLocationView.setPrintCoords(false); |
| 1166 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1167 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1168 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1169 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1170 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1171 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1172 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1173 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1174 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1175 | if (ActivityManager.isHighEndGfx()) { |
| 1176 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1177 | lp.privateFlags |= |
| 1178 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 1179 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1180 | lp.format = PixelFormat.TRANSLUCENT; |
| 1181 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1182 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1183 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1184 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1185 | wm.addView(mPointerLocationView, lp); |
| 1186 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1187 | mPointerLocationPointerEventListener = new PointerLocationPointerEventListener(); |
| 1188 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationPointerEventListener); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1189 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1190 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1191 | |
| 1192 | private void disablePointerLocation() { |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 1193 | if (mPointerLocationPointerEventListener != null) { |
| 1194 | mWindowManagerFuncs.unregisterPointerEventListener( |
| 1195 | mPointerLocationPointerEventListener); |
| 1196 | mPointerLocationPointerEventListener = null; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | if (mPointerLocationView != null) { |
| 1200 | WindowManager wm = (WindowManager) |
| 1201 | mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1202 | wm.removeView(mPointerLocationView); |
| 1203 | mPointerLocationView = null; |
| 1204 | } |
| 1205 | } |
| 1206 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1207 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1208 | try { |
| 1209 | int rotation = mContext.getResources().getInteger(resID); |
| 1210 | switch (rotation) { |
| 1211 | case 0: |
| 1212 | return Surface.ROTATION_0; |
| 1213 | case 90: |
| 1214 | return Surface.ROTATION_90; |
| 1215 | case 180: |
| 1216 | return Surface.ROTATION_180; |
| 1217 | case 270: |
| 1218 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1219 | } |
| 1220 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1221 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1222 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1223 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1227 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1228 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1229 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1230 | |
| 1231 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 1232 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1233 | if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW |
| 1234 | || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1235 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1236 | } |
| 1237 | String permission = null; |
| 1238 | switch (type) { |
| 1239 | case TYPE_TOAST: |
| 1240 | // XXX right now the app process has complete control over |
| 1241 | // this... should introduce a token to let the system |
| 1242 | // monitor/control what they are doing. |
| 1243 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 1244 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1245 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1246 | case TYPE_WALLPAPER: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1247 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1248 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1249 | break; |
| 1250 | case TYPE_PHONE: |
| 1251 | case TYPE_PRIORITY_PHONE: |
| 1252 | case TYPE_SYSTEM_ALERT: |
| 1253 | case TYPE_SYSTEM_ERROR: |
| 1254 | case TYPE_SYSTEM_OVERLAY: |
| 1255 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1256 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1257 | break; |
| 1258 | default: |
| 1259 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 1260 | } |
| 1261 | if (permission != null) { |
| 1262 | if (mContext.checkCallingOrSelfPermission(permission) |
| 1263 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1264 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1265 | } |
| 1266 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1267 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1268 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1269 | |
| 1270 | @Override |
| 1271 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 1272 | |
| 1273 | // If this switch statement is modified, modify the comment in the declarations of |
| 1274 | // the type in {@link WindowManager.LayoutParams} as well. |
| 1275 | switch (attrs.type) { |
| 1276 | default: |
| 1277 | // These are the windows that by default are shown only to the user that created |
| 1278 | // them. If this needs to be overridden, set |
| 1279 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 1280 | // {@link WindowManager.LayoutParams}. Note that permission |
| 1281 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 1282 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 1283 | return true; |
| 1284 | } |
| 1285 | break; |
| 1286 | |
| 1287 | // These are the windows that by default are shown to all users. However, to |
| 1288 | // protect against spoofing, check permissions below. |
| 1289 | case TYPE_APPLICATION_STARTING: |
| 1290 | case TYPE_BOOT_PROGRESS: |
| 1291 | case TYPE_DISPLAY_OVERLAY: |
| 1292 | case TYPE_HIDDEN_NAV_CONSUMER: |
| 1293 | case TYPE_KEYGUARD: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1294 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1295 | case TYPE_KEYGUARD_DIALOG: |
| 1296 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1297 | case TYPE_NAVIGATION_BAR: |
| 1298 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1299 | case TYPE_PHONE: |
| 1300 | case TYPE_POINTER: |
| 1301 | case TYPE_PRIORITY_PHONE: |
| 1302 | case TYPE_RECENTS_OVERLAY: |
| 1303 | case TYPE_SEARCH_BAR: |
| 1304 | case TYPE_STATUS_BAR: |
| 1305 | case TYPE_STATUS_BAR_PANEL: |
| 1306 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1307 | case TYPE_SYSTEM_DIALOG: |
| 1308 | case TYPE_UNIVERSE_BACKGROUND: |
| 1309 | case TYPE_VOLUME_OVERLAY: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1310 | case TYPE_PRIVATE_PRESENTATION: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1311 | break; |
| 1312 | } |
| 1313 | |
| 1314 | // Check if third party app has set window to system window type. |
| 1315 | return mContext.checkCallingOrSelfPermission( |
| 1316 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 1317 | != PackageManager.PERMISSION_GRANTED; |
| 1318 | } |
| 1319 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1320 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1321 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 1322 | switch (attrs.type) { |
| 1323 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1324 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1325 | // These types of windows can't receive input events. |
| 1326 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1327 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1328 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1329 | break; |
| 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 1334 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1335 | } |
| 1336 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1337 | private boolean isHidden(int accessibilityMode) { |
| 1338 | switch (accessibilityMode) { |
| 1339 | case 1: |
| 1340 | return mLidState == LID_CLOSED; |
| 1341 | case 2: |
| 1342 | return mLidState == LID_OPEN; |
| 1343 | default: |
| 1344 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1345 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1346 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1347 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1348 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1349 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1350 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 1351 | int navigationPresence) { |
| 1352 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 1353 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1354 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1355 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1356 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1357 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1358 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 1359 | || (keyboardPresence == PRESENCE_INTERNAL |
| 1360 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1361 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1362 | if (!mHasSoftInput) { |
| 1363 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 1364 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1365 | } |
| 1366 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1367 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 1368 | || (navigationPresence == PRESENCE_INTERNAL |
| 1369 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1370 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1371 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1372 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1373 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1374 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1375 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1376 | public int windowTypeToLayerLw(int type) { |
| 1377 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1378 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1379 | } |
| 1380 | switch (type) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1381 | case TYPE_UNIVERSE_BACKGROUND: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1382 | return 1; |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1383 | case TYPE_PRIVATE_PRESENTATION: |
| 1384 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1385 | case TYPE_WALLPAPER: |
| 1386 | // wallpaper is at the bottom, though the window manager may move it. |
| 1387 | return 2; |
| 1388 | case TYPE_PHONE: |
| 1389 | return 3; |
| 1390 | case TYPE_SEARCH_BAR: |
| 1391 | return 4; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1392 | case TYPE_RECENTS_OVERLAY: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1393 | case TYPE_SYSTEM_DIALOG: |
| 1394 | return 5; |
| 1395 | case TYPE_TOAST: |
| 1396 | // toasts and the plugged-in battery thing |
| 1397 | return 6; |
| 1398 | case TYPE_PRIORITY_PHONE: |
| 1399 | // SIM errors and unlock. Not sure if this really should be in a high layer. |
| 1400 | return 7; |
| 1401 | case TYPE_DREAM: |
| 1402 | // used for Dreams (screensavers with TYPE_DREAM windows) |
| 1403 | return 8; |
| 1404 | case TYPE_SYSTEM_ALERT: |
| 1405 | // like the ANR / app crashed dialogs |
| 1406 | return 9; |
| 1407 | case TYPE_INPUT_METHOD: |
| 1408 | // on-screen keyboards and other such input method user interfaces go here. |
| 1409 | return 10; |
| 1410 | case TYPE_INPUT_METHOD_DIALOG: |
| 1411 | // on-screen keyboards and other such input method user interfaces go here. |
| 1412 | return 11; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1413 | case TYPE_KEYGUARD_SCRIM: |
| 1414 | // the safety window that shows behind keyguard while keyguard is starting |
| 1415 | return 12; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1416 | case TYPE_KEYGUARD: |
| 1417 | // the keyguard; nothing on top of these can take focus, since they are |
| 1418 | // responsible for power management when displayed. |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1419 | return 13; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1420 | case TYPE_KEYGUARD_DIALOG: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1421 | return 14; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1422 | case TYPE_STATUS_BAR_SUB_PANEL: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1423 | return 15; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1424 | case TYPE_STATUS_BAR: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1425 | return 16; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1426 | case TYPE_STATUS_BAR_PANEL: |
| 1427 | return 17; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1428 | case TYPE_VOLUME_OVERLAY: |
| 1429 | // the on-screen volume indicator and controller shown when the user |
| 1430 | // changes the device volume |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1431 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1432 | case TYPE_SYSTEM_OVERLAY: |
| 1433 | // the on-screen volume indicator and controller shown when the user |
| 1434 | // changes the device volume |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1435 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1436 | case TYPE_NAVIGATION_BAR: |
| 1437 | // the navigation bar, if available, shows atop most things |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1438 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1439 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1440 | // some panels (e.g. search) need to show on top of the navigation bar |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1441 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1442 | case TYPE_SYSTEM_ERROR: |
| 1443 | // system-level error dialogs |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1444 | return 22; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1445 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1446 | // used to highlight the magnified portion of a display |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1447 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1448 | case TYPE_DISPLAY_OVERLAY: |
| 1449 | // used to simulate secondary display devices |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1450 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1451 | case TYPE_DRAG: |
| 1452 | // the drag layer: input for drag-and-drop is associated with this window, |
| 1453 | // which sits above all other focusable windows |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1454 | return 25; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1455 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1456 | return 26; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1457 | case TYPE_BOOT_PROGRESS: |
| 1458 | return 27; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1459 | case TYPE_POINTER: |
| 1460 | // the (mouse) pointer layer |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1461 | return 28; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1462 | case TYPE_HIDDEN_NAV_CONSUMER: |
| 1463 | return 29; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1464 | } |
| 1465 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1466 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1467 | } |
| 1468 | |
| 1469 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 1470 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1471 | public int subWindowTypeToLayerLw(int type) { |
| 1472 | switch (type) { |
| 1473 | case TYPE_APPLICATION_PANEL: |
| 1474 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 1475 | return APPLICATION_PANEL_SUBLAYER; |
| 1476 | case TYPE_APPLICATION_MEDIA: |
| 1477 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 1478 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 1479 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1480 | case TYPE_APPLICATION_SUB_PANEL: |
| 1481 | return APPLICATION_SUB_PANEL_SUBLAYER; |
| 1482 | } |
| 1483 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 1484 | return 0; |
| 1485 | } |
| 1486 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 1487 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1488 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1489 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1490 | } |
| 1491 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 1492 | @Override |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1493 | public int getAboveUniverseLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1494 | return windowTypeToLayerLw(TYPE_SYSTEM_ERROR); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1497 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1498 | if (mHasNavigationBar) { |
| 1499 | // For a basic navigation bar, when we are in landscape mode we place |
| 1500 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1501 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
| 1502 | return fullWidth - mNavigationBarWidthForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1503 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1504 | } |
| 1505 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1506 | } |
| 1507 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1508 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1509 | if (mHasNavigationBar) { |
| 1510 | // For a basic navigation bar, when we are in portrait mode we place |
| 1511 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1512 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
| 1513 | return fullHeight - mNavigationBarHeightForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1514 | } |
| 1515 | } |
| 1516 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1519 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
| 1520 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1521 | } |
| 1522 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1523 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1524 | // There is a separate status bar at the top of the display. We don't count that as part |
| 1525 | // of the fixed decor, since it can hide; however, for purposes of configurations, |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1526 | // we do want to exclude it since applications can't generally use that part |
| 1527 | // of the screen. |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1528 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1529 | } |
| 1530 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1531 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1532 | public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) { |
| 1533 | return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD; |
| 1534 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1535 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1536 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1537 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1538 | switch (attrs.type) { |
| 1539 | case TYPE_STATUS_BAR: |
| 1540 | case TYPE_NAVIGATION_BAR: |
| 1541 | case TYPE_WALLPAPER: |
| 1542 | case TYPE_DREAM: |
| 1543 | case TYPE_UNIVERSE_BACKGROUND: |
| 1544 | case TYPE_KEYGUARD: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1545 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1546 | return false; |
| 1547 | default: |
| 1548 | return true; |
| 1549 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1550 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1551 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1552 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1553 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1554 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 1555 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1556 | int icon, int logo, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1557 | if (!SHOW_STARTING_ANIMATIONS) { |
| 1558 | return null; |
| 1559 | } |
| 1560 | if (packageName == null) { |
| 1561 | return null; |
| 1562 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1563 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1564 | WindowManager wm = null; |
| 1565 | View view = null; |
| 1566 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1567 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1568 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1569 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 1570 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 1571 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1572 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1573 | try { |
| 1574 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1575 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1576 | } catch (PackageManager.NameNotFoundException e) { |
| 1577 | // Ignore |
| 1578 | } |
| 1579 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1580 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1581 | Window win = PolicyManager.makeNewWindow(context); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1582 | final TypedArray ta = win.getWindowStyle(); |
| 1583 | if (ta.getBoolean( |
| 1584 | com.android.internal.R.styleable.Window_windowDisablePreview, false) |
| 1585 | || ta.getBoolean( |
| 1586 | com.android.internal.R.styleable.Window_windowShowWallpaper,false)) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1587 | return null; |
| 1588 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1589 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1590 | Resources r = context.getResources(); |
| 1591 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1592 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1593 | win.setType( |
| 1594 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
| 1595 | // Force the window flags: this is a fake window, so it is not really |
| 1596 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 1597 | // flag because we do know that the next window will take input |
| 1598 | // focus, so we want to get the IME window up on top of us right away. |
| 1599 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1600 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1601 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 1602 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 1603 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1604 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1605 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 1606 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 1607 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1608 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1609 | if (!compatInfo.supportsScreen()) { |
| 1610 | win.addFlags(WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW); |
| 1611 | } |
| 1612 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1613 | win.setDefaultIcon(icon); |
| 1614 | win.setDefaultLogo(logo); |
| 1615 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1616 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1617 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1618 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1619 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 1620 | params.token = appToken; |
| 1621 | params.packageName = packageName; |
| 1622 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 1623 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 1624 | params.privateFlags |= |
| 1625 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1626 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1627 | params.setTitle("Starting " + packageName); |
| 1628 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1629 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 1630 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1631 | |
| 1632 | if (win.isFloating()) { |
| 1633 | // Whoops, there is no way to display an animation/preview |
| 1634 | // of such a thing! After all that work... let's skip it. |
| 1635 | // (Note that we must do this here because it is in |
| 1636 | // getDecorView() where the theme is evaluated... maybe |
| 1637 | // we should peek the floating attribute from the theme |
| 1638 | // earlier.) |
| 1639 | return null; |
| 1640 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1641 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1642 | if (DEBUG_STARTING_WINDOW) Slog.d( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1643 | TAG, "Adding starting window for " + packageName |
| 1644 | + " / " + appToken + ": " |
| 1645 | + (view.getParent() != null ? view : null)); |
| 1646 | |
| 1647 | wm.addView(view, params); |
| 1648 | |
| 1649 | // Only return the view if it was successfully added to the |
| 1650 | // window manager... which we can tell by it having a parent. |
| 1651 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1652 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1653 | // ignore |
| 1654 | Log.w(TAG, appToken + " already running, starting window not displayed"); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1655 | } catch (RuntimeException e) { |
| 1656 | // don't crash if something else bad happens, for example a |
| 1657 | // failure loading resources because we are loading from an app |
| 1658 | // on external storage that has been unmounted. |
| 1659 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1660 | } finally { |
| 1661 | if (view != null && view.getParent() == null) { |
| 1662 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 1663 | wm.removeViewImmediate(view); |
| 1664 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | return null; |
| 1668 | } |
| 1669 | |
| 1670 | /** {@inheritDoc} */ |
| 1671 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1672 | if (DEBUG_STARTING_WINDOW) { |
| 1673 | RuntimeException e = new RuntimeException("here"); |
| 1674 | e.fillInStackTrace(); |
| 1675 | Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e); |
| 1676 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1677 | |
| 1678 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1679 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1680 | wm.removeView(window); |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | /** |
| 1685 | * Preflight adding a window to the system. |
| 1686 | * |
| 1687 | * Currently enforces that three window types are singletons: |
| 1688 | * <ul> |
| 1689 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1690 | * <li>KEYGUARD_TYPE</li> |
| 1691 | * </ul> |
| 1692 | * |
| 1693 | * @param win The window to be added |
| 1694 | * @param attrs Information about the window to be added |
| 1695 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1696 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 1697 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1698 | */ |
| 1699 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 1700 | switch (attrs.type) { |
| 1701 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 1702 | mContext.enforceCallingOrSelfPermission( |
| 1703 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1704 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1705 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1706 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1707 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1708 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1709 | } |
| 1710 | mStatusBar = win; |
| 1711 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1712 | case TYPE_NAVIGATION_BAR: |
| 1713 | mContext.enforceCallingOrSelfPermission( |
| 1714 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1715 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1716 | if (mNavigationBar != null) { |
| 1717 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1718 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1719 | } |
| 1720 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1721 | mNavigationBar = win; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1722 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1723 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 1724 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1725 | mContext.enforceCallingOrSelfPermission( |
| 1726 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1727 | "PhoneWindowManager"); |
| 1728 | break; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1729 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 1730 | mContext.enforceCallingOrSelfPermission( |
| 1731 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1732 | "PhoneWindowManager"); |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1733 | break; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1734 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1735 | mContext.enforceCallingOrSelfPermission( |
| 1736 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1737 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1738 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1739 | case TYPE_KEYGUARD: |
| 1740 | if (mKeyguard != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1741 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1742 | } |
| 1743 | mKeyguard = win; |
| 1744 | break; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1745 | case TYPE_KEYGUARD_SCRIM: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1746 | if (mKeyguardScrim != null) { |
| 1747 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 1748 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1749 | mKeyguardScrim = win; |
| 1750 | break; |
| 1751 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1752 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1753 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | /** {@inheritDoc} */ |
| 1757 | public void removeWindowLw(WindowState win) { |
| 1758 | if (mStatusBar == win) { |
| 1759 | mStatusBar = null; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1760 | } else if (mKeyguard == win) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1761 | Log.v(TAG, "Removing keyguard window (Did it crash?)"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1762 | mKeyguard = null; |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 1763 | mKeyguardDelegate.showScrim(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1764 | } else if (mKeyguardScrim == win) { |
| 1765 | Log.v(TAG, "Removing keyguard scrim"); |
| 1766 | mKeyguardScrim = null; |
| 1767 | } if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1768 | mNavigationBar = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1769 | } |
| 1770 | } |
| 1771 | |
| 1772 | static final boolean PRINT_ANIM = false; |
| 1773 | |
| 1774 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1775 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1776 | public int selectAnimationLw(WindowState win, int transit) { |
| 1777 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 1778 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1779 | if (win == mStatusBar) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1780 | if (transit == TRANSIT_EXIT |
| 1781 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1782 | return R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1783 | } else if (transit == TRANSIT_ENTER |
| 1784 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1785 | return R.anim.dock_top_enter; |
| 1786 | } |
| 1787 | } else if (win == mNavigationBar) { |
| 1788 | // This can be on either the bottom or the right. |
| 1789 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1790 | if (transit == TRANSIT_EXIT |
| 1791 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1792 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1793 | } else if (transit == TRANSIT_ENTER |
| 1794 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1795 | return R.anim.dock_bottom_enter; |
| 1796 | } |
| 1797 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1798 | if (transit == TRANSIT_EXIT |
| 1799 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1800 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1801 | } else if (transit == TRANSIT_ENTER |
| 1802 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1803 | return R.anim.dock_right_enter; |
| 1804 | } |
| 1805 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1809 | if (win.hasAppShownWindows()) { |
| 1810 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 1811 | return com.android.internal.R.anim.app_starting_exit; |
| 1812 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 1813 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1814 | && transit == TRANSIT_ENTER) { |
| 1815 | // Special case: we are animating in a dream, while the keyguard |
| 1816 | // is shown. We don't want an animation on the dream, because |
| 1817 | // we need it shown immediately with the keyguard animating away |
| 1818 | // to reveal it. |
| 1819 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | return 0; |
| 1823 | } |
| 1824 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 1825 | @Override |
| 1826 | public void selectRotationAnimationLw(int anim[]) { |
| 1827 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 1828 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 1829 | + (mTopFullscreenOpaqueWindowState == null ? |
| 1830 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 1831 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 1832 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 1833 | case ROTATION_ANIMATION_CROSSFADE: |
| 1834 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 1835 | anim[1] = R.anim.rotation_animation_enter; |
| 1836 | break; |
| 1837 | case ROTATION_ANIMATION_JUMPCUT: |
| 1838 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 1839 | anim[1] = R.anim.rotation_animation_enter; |
| 1840 | break; |
| 1841 | case ROTATION_ANIMATION_ROTATE: |
| 1842 | default: |
| 1843 | anim[0] = anim[1] = 0; |
| 1844 | break; |
| 1845 | } |
| 1846 | } else { |
| 1847 | anim[0] = anim[1] = 0; |
| 1848 | } |
| 1849 | } |
| 1850 | |
| 1851 | @Override |
| 1852 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 1853 | boolean forceDefault) { |
| 1854 | switch (exitAnimId) { |
| 1855 | case R.anim.rotation_animation_xfade_exit: |
| 1856 | case R.anim.rotation_animation_jump_exit: |
| 1857 | // These are the only cases that matter. |
| 1858 | if (forceDefault) { |
| 1859 | return false; |
| 1860 | } |
| 1861 | int anim[] = new int[2]; |
| 1862 | selectRotationAnimationLw(anim); |
| 1863 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 1864 | default: |
| 1865 | return true; |
| 1866 | } |
| 1867 | } |
| 1868 | |
| 1869 | @Override |
Dianne Hackborn | 0c2acff | 2012-04-12 15:17:07 -0700 | [diff] [blame] | 1870 | public Animation createForceHideEnterAnimation(boolean onWallpaper) { |
| 1871 | return AnimationUtils.loadAnimation(mContext, onWallpaper |
| 1872 | ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter |
| 1873 | : com.android.internal.R.anim.lock_screen_behind_enter); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1874 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 1875 | |
| 1876 | private static void awakenDreams() { |
| 1877 | IDreamManager dreamManager = getDreamManager(); |
| 1878 | if (dreamManager != null) { |
| 1879 | try { |
| 1880 | dreamManager.awaken(); |
| 1881 | } catch (RemoteException e) { |
| 1882 | // fine, stay asleep then |
| 1883 | } |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | static IDreamManager getDreamManager() { |
| 1888 | return IDreamManager.Stub.asInterface( |
| 1889 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 1890 | } |
| 1891 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1892 | static ITelephony getTelephonyService() { |
Mike Lockwood | f5f4ec9 | 2011-11-08 14:05:31 -0800 | [diff] [blame] | 1893 | return ITelephony.Stub.asInterface( |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1894 | ServiceManager.checkService(Context.TELEPHONY_SERVICE)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1895 | } |
| 1896 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1897 | static IAudioService getAudioService() { |
| 1898 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 1899 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 1900 | if (audioService == null) { |
| 1901 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 1902 | } |
| 1903 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | boolean keyguardOn() { |
| 1907 | return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode(); |
| 1908 | } |
| 1909 | |
| 1910 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 1911 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 1912 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 1913 | }; |
| 1914 | |
| 1915 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1916 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1917 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1918 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1919 | final int keyCode = event.getKeyCode(); |
| 1920 | final int repeatCount = event.getRepeatCount(); |
| 1921 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1922 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1923 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 1924 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1925 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 1926 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1927 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 1928 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 1929 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1930 | } |
| 1931 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1932 | // If we think we might have a volume down & power key chord on the way |
| 1933 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 1934 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1935 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1936 | if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) { |
| 1937 | final long now = SystemClock.uptimeMillis(); |
| 1938 | final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
| 1939 | if (now < timeoutTime) { |
| 1940 | return timeoutTime - now; |
| 1941 | } |
| 1942 | } |
| 1943 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 1944 | && mVolumeDownKeyConsumedByScreenshotChord) { |
| 1945 | if (!down) { |
| 1946 | mVolumeDownKeyConsumedByScreenshotChord = false; |
| 1947 | } |
| 1948 | return -1; |
| 1949 | } |
| 1950 | } |
| 1951 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1952 | // First we always handle the home key here, so applications |
| 1953 | // can never break it, although if keyguard is on, we do let |
| 1954 | // it handle it, because that gives us the correct 5 second |
| 1955 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1956 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1957 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1958 | // If we have released the home key, and didn't do anything else |
| 1959 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1960 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1961 | cancelPreloadRecentApps(); |
| 1962 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1963 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1964 | if (mHomeConsumed) { |
| 1965 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1966 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1967 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1968 | |
| 1969 | if (canceled) { |
| 1970 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 1971 | return -1; |
| 1972 | } |
| 1973 | |
| 1974 | // If an incoming call is ringing, HOME is totally disabled. |
| 1975 | // (The user is already on the InCallScreen at this point, |
| 1976 | // and his ONLY options are to answer or reject the call.) |
| 1977 | try { |
| 1978 | ITelephony telephonyService = getTelephonyService(); |
| 1979 | if (telephonyService != null && telephonyService.isRinging()) { |
| 1980 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 1981 | return -1; |
| 1982 | } |
| 1983 | } catch (RemoteException ex) { |
| 1984 | Log.w(TAG, "RemoteException from getPhoneInterface()", ex); |
| 1985 | } |
| 1986 | |
| 1987 | // Delay handling home if a double-tap is possible. |
| 1988 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 1989 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 1990 | mHomeDoubleTapPending = true; |
| 1991 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 1992 | ViewConfiguration.getDoubleTapTimeout()); |
| 1993 | return -1; |
| 1994 | } |
| 1995 | |
| 1996 | // Go home! |
| 1997 | launchHomeFromHotKey(); |
| 1998 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1999 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2000 | |
| 2001 | // If a system window has focus, then it doesn't make sense |
| 2002 | // right now to interact with applications. |
| 2003 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 2004 | if (attrs != null) { |
| 2005 | final int type = attrs.type; |
| 2006 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2007 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2008 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) { |
| 2009 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2010 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2011 | } |
| 2012 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 2013 | for (int i=0; i<typeCount; i++) { |
| 2014 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 2015 | // 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] | 2016 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2017 | } |
| 2018 | } |
| 2019 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2020 | |
| 2021 | // Remember that home is pressed and handle special actions. |
| 2022 | if (repeatCount == 0) { |
| 2023 | mHomePressed = true; |
| 2024 | if (mHomeDoubleTapPending) { |
| 2025 | mHomeDoubleTapPending = false; |
| 2026 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 2027 | handleDoubleTapOnHome(); |
| 2028 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 2029 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2030 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2031 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2032 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 2033 | if (!keyguardOn) { |
| 2034 | handleLongPressOnHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2035 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2036 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2037 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2038 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2039 | // Hijack modified menu keys for debugging features |
| 2040 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 2041 | |
| 2042 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2043 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2044 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2045 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 2046 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2047 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2048 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2049 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2050 | Intent service = new Intent(); |
| 2051 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 2052 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2053 | boolean shown = Settings.Global.getInt( |
| 2054 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2055 | if (!shown) { |
| 2056 | mContext.startService(service); |
| 2057 | } else { |
| 2058 | mContext.stopService(service); |
| 2059 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2060 | Settings.Global.putInt( |
| 2061 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2062 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2063 | } |
| 2064 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2065 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2066 | if (down) { |
| 2067 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2068 | mSearchKeyShortcutPending = true; |
| 2069 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2070 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2071 | } else { |
| 2072 | mSearchKeyShortcutPending = false; |
| 2073 | if (mConsumeSearchKeyUp) { |
| 2074 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2075 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2076 | } |
| 2077 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2078 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2079 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2080 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2081 | if (down && repeatCount == 0) { |
| 2082 | preloadRecentApps(); |
| 2083 | } else if (!down) { |
| 2084 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2085 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2086 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2087 | return -1; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2088 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 2089 | if (down) { |
| 2090 | if (repeatCount == 0) { |
| 2091 | mAssistKeyLongPressed = false; |
| 2092 | } else if (repeatCount == 1) { |
| 2093 | mAssistKeyLongPressed = true; |
| 2094 | if (!keyguardOn) { |
| 2095 | launchAssistLongPressAction(); |
| 2096 | } |
| 2097 | } |
| 2098 | } else { |
| 2099 | if (mAssistKeyLongPressed) { |
| 2100 | mAssistKeyLongPressed = false; |
| 2101 | } else { |
| 2102 | if (!keyguardOn) { |
| 2103 | launchAssistAction(); |
| 2104 | } |
| 2105 | } |
| 2106 | } |
| 2107 | return -1; |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 2108 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 2109 | if (down && repeatCount == 0) { |
| 2110 | mHandler.post(mScreenshotRunnable); |
| 2111 | } |
| 2112 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2113 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 2114 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 2115 | if (down) { |
| 2116 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 2117 | |
| 2118 | // Disable autobrightness if it's on |
| 2119 | int auto = Settings.System.getIntForUser( |
| 2120 | mContext.getContentResolver(), |
| 2121 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2122 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2123 | UserHandle.USER_CURRENT_OR_SELF); |
| 2124 | if (auto != 0) { |
| 2125 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2126 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2127 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2128 | UserHandle.USER_CURRENT_OR_SELF); |
| 2129 | } |
| 2130 | |
| 2131 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 2132 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 2133 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 2134 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 2135 | Settings.System.SCREEN_BRIGHTNESS, |
| 2136 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 2137 | UserHandle.USER_CURRENT_OR_SELF); |
| 2138 | brightness += step; |
| 2139 | // Make sure we don't go beyond the limits. |
| 2140 | brightness = Math.min(max, brightness); |
| 2141 | brightness = Math.max(min, brightness); |
| 2142 | |
| 2143 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2144 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 2145 | UserHandle.USER_CURRENT_OR_SELF); |
| 2146 | Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG); |
| 2147 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF); |
| 2148 | } |
| 2149 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2150 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2151 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2152 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2153 | // Any printing key that is chorded with Search should be consumed |
| 2154 | // even if no shortcut was invoked. This prevents text from being |
| 2155 | // inadvertently inserted when using a keyboard that has built-in macro |
| 2156 | // 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] | 2157 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2158 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 2159 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2160 | mConsumeSearchKeyUp = true; |
| 2161 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2162 | if (down && repeatCount == 0 && !keyguardOn) { |
| 2163 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 2164 | if (shortcutIntent != null) { |
| 2165 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2166 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2167 | mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2168 | } catch (ActivityNotFoundException ex) { |
| 2169 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2170 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2171 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2172 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2173 | } else { |
| 2174 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2175 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2176 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2177 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2178 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2179 | } |
| 2180 | } |
| 2181 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2182 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2183 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2184 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 2185 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2186 | if (kcm.isPrintingKey(keyCode)) { |
| 2187 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 2188 | metaState & ~(KeyEvent.META_META_ON |
| 2189 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 2190 | if (shortcutIntent != null) { |
| 2191 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2192 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2193 | mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2194 | } catch (ActivityNotFoundException ex) { |
| 2195 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2196 | + "the activity to which it is registered was not found: " |
| 2197 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 2198 | } |
| 2199 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2200 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2201 | } |
| 2202 | } |
| 2203 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2204 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2205 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2206 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 2207 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 2208 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2209 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2210 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2211 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2212 | } catch (ActivityNotFoundException ex) { |
| 2213 | Slog.w(TAG, "Dropping application launch key because " |
| 2214 | + "the activity to which it is registered was not found: " |
| 2215 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 2216 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2217 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2218 | } |
| 2219 | } |
| 2220 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2221 | // Display task switcher for ALT-TAB or Meta-TAB. |
| 2222 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2223 | if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2224 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
| 2225 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON) |
| 2226 | || KeyEvent.metaStateHasModifiers( |
| 2227 | shiftlessModifiers, KeyEvent.META_META_ON)) { |
| 2228 | mRecentAppsDialogHeldModifiers = shiftlessModifiers; |
| 2229 | showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW); |
| 2230 | return -1; |
| 2231 | } |
| 2232 | } |
| 2233 | } else if (!down && mRecentAppsDialogHeldModifiers != 0 |
| 2234 | && (metaState & mRecentAppsDialogHeldModifiers) == 0) { |
| 2235 | mRecentAppsDialogHeldModifiers = 0; |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2236 | showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS : |
| 2237 | RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2238 | } |
| 2239 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 2240 | // Handle keyboard language switching. |
| 2241 | if (down && repeatCount == 0 |
| 2242 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2243 | || (keyCode == KeyEvent.KEYCODE_SPACE |
| 2244 | && (metaState & KeyEvent.META_CTRL_MASK) != 0))) { |
| 2245 | int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; |
| 2246 | mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); |
| 2247 | return -1; |
| 2248 | } |
| 2249 | if (mLanguageSwitchKeyPressed && !down |
| 2250 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2251 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 2252 | mLanguageSwitchKeyPressed = false; |
| 2253 | return -1; |
| 2254 | } |
| 2255 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 2256 | if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
| 2257 | return -1; |
| 2258 | } |
| 2259 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2260 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2261 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2262 | } |
| 2263 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2264 | /** {@inheritDoc} */ |
| 2265 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2266 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2267 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2268 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2269 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 2270 | + ", flags=" + event.getFlags() |
| 2271 | + ", keyCode=" + event.getKeyCode() |
| 2272 | + ", scanCode=" + event.getScanCode() |
| 2273 | + ", metaState=" + event.getMetaState() |
| 2274 | + ", repeatCount=" + event.getRepeatCount() |
| 2275 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2276 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2277 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2278 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2279 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 2280 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2281 | final int keyCode = event.getKeyCode(); |
| 2282 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2283 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 2284 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2285 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2286 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2287 | final FallbackAction fallbackAction; |
| 2288 | if (initialDown) { |
| 2289 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 2290 | } else { |
| 2291 | fallbackAction = mFallbackActions.get(keyCode); |
| 2292 | } |
| 2293 | |
| 2294 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2295 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2296 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 2297 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2298 | } |
| 2299 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2300 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 2301 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2302 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2303 | event.getAction(), fallbackAction.keyCode, |
| 2304 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2305 | event.getDeviceId(), event.getScanCode(), |
| 2306 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2307 | |
| 2308 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 2309 | fallbackEvent.recycle(); |
| 2310 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2311 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2312 | |
| 2313 | if (initialDown) { |
| 2314 | mFallbackActions.put(keyCode, fallbackAction); |
| 2315 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2316 | mFallbackActions.remove(keyCode); |
| 2317 | fallbackAction.recycle(); |
| 2318 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2319 | } |
| 2320 | } |
| 2321 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2322 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2323 | if (fallbackEvent == null) { |
| 2324 | Slog.d(TAG, "No fallback."); |
| 2325 | } else { |
| 2326 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 2327 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2328 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2329 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2332 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
| 2333 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true); |
| 2334 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 2335 | long delayMillis = interceptKeyBeforeDispatching( |
| 2336 | win, fallbackEvent, policyFlags); |
| 2337 | if (delayMillis == 0) { |
| 2338 | return true; |
| 2339 | } |
| 2340 | } |
| 2341 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2342 | } |
| 2343 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2344 | private void launchAssistLongPressAction() { |
| 2345 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 2346 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 2347 | |
| 2348 | // launch the search activity |
| 2349 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 2350 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2351 | try { |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2352 | // TODO: This only stops the factory-installed search manager. |
| 2353 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2354 | SearchManager searchManager = getSearchManager(); |
| 2355 | if (searchManager != null) { |
| 2356 | searchManager.stopSearch(); |
| 2357 | } |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2358 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2359 | } catch (ActivityNotFoundException e) { |
| 2360 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 2361 | } |
| 2362 | } |
| 2363 | |
| 2364 | private void launchAssistAction() { |
| 2365 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 2366 | Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2367 | .getAssistIntent(mContext, true, UserHandle.USER_CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2368 | if (intent != null) { |
| 2369 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2370 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 2371 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 2372 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2373 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2374 | } catch (ActivityNotFoundException e) { |
| 2375 | Slog.w(TAG, "No activity to handle assist action.", e); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2376 | } |
| 2377 | } |
| 2378 | } |
| 2379 | |
| 2380 | private SearchManager getSearchManager() { |
| 2381 | if (mSearchManager == null) { |
| 2382 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 2383 | } |
| 2384 | return mSearchManager; |
| 2385 | } |
| 2386 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2387 | private void preloadRecentApps() { |
| 2388 | mPreloadedRecentApps = true; |
| 2389 | try { |
| 2390 | IStatusBarService statusbar = getStatusBarService(); |
| 2391 | if (statusbar != null) { |
| 2392 | statusbar.preloadRecentApps(); |
| 2393 | } |
| 2394 | } catch (RemoteException e) { |
| 2395 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
| 2396 | // re-acquire status bar service next time it is needed. |
| 2397 | mStatusBarService = null; |
| 2398 | } |
| 2399 | } |
| 2400 | |
| 2401 | private void cancelPreloadRecentApps() { |
| 2402 | if (mPreloadedRecentApps) { |
| 2403 | mPreloadedRecentApps = false; |
| 2404 | try { |
| 2405 | IStatusBarService statusbar = getStatusBarService(); |
| 2406 | if (statusbar != null) { |
| 2407 | statusbar.cancelPreloadRecentApps(); |
| 2408 | } |
| 2409 | } catch (RemoteException e) { |
| 2410 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 2411 | // re-acquire status bar service next time it is needed. |
| 2412 | mStatusBarService = null; |
| 2413 | } |
| 2414 | } |
| 2415 | } |
| 2416 | |
| 2417 | private void toggleRecentApps() { |
| 2418 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 2419 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS); |
| 2420 | try { |
| 2421 | IStatusBarService statusbar = getStatusBarService(); |
| 2422 | if (statusbar != null) { |
| 2423 | statusbar.toggleRecentApps(); |
| 2424 | } |
| 2425 | } catch (RemoteException e) { |
| 2426 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 2427 | // re-acquire status bar service next time it is needed. |
| 2428 | mStatusBarService = null; |
| 2429 | } |
| 2430 | } |
| 2431 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2432 | /** |
| 2433 | * A home key -> launch home action was detected. Take the appropriate action |
| 2434 | * given the situation with the keyguard. |
| 2435 | */ |
| 2436 | void launchHomeFromHotKey() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2437 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotHidden()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2438 | // don't launch home if keyguard showing |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2439 | } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2440 | // when in keyguard restricted mode, must first verify unlock |
| 2441 | // before launching home |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2442 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2443 | public void onKeyguardExitResult(boolean success) { |
| 2444 | if (success) { |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2445 | try { |
| 2446 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2447 | } catch (RemoteException e) { |
| 2448 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 2449 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2450 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2451 | } |
| 2452 | } |
| 2453 | }); |
| 2454 | } else { |
| 2455 | // no keyguard stuff to worry about, just launch home! |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2456 | try { |
| 2457 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2458 | } catch (RemoteException e) { |
| 2459 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 2460 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2461 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2462 | } |
| 2463 | } |
| 2464 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2465 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 2466 | @Override |
| 2467 | public void run() { |
| 2468 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2469 | // Clear flags. |
| 2470 | mForceClearedSystemUiFlags &= |
| 2471 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 2472 | } |
| 2473 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2474 | } |
| 2475 | }; |
| 2476 | |
| 2477 | /** |
| 2478 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 2479 | * to determine when the nav bar should be shown and prevent applications from |
| 2480 | * receiving those touches. |
| 2481 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2482 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 2483 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 2484 | super(inputChannel, looper); |
| 2485 | } |
| 2486 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2487 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2488 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2489 | boolean handled = false; |
| 2490 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 2491 | if (event instanceof MotionEvent |
| 2492 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 2493 | final MotionEvent motionEvent = (MotionEvent)event; |
| 2494 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2495 | // When the user taps down, we re-show the nav bar. |
| 2496 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2497 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2498 | // Any user activity always causes us to show the |
| 2499 | // navigation controls, if they had been hidden. |
| 2500 | // We also clear the low profile and only content |
| 2501 | // flags so that tapping on the screen will atomically |
| 2502 | // restore all currently hidden screen decorations. |
| 2503 | int newVal = mResettingSystemUiFlags | |
| 2504 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 2505 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 2506 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2507 | if (mResettingSystemUiFlags != newVal) { |
| 2508 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2509 | changed = true; |
| 2510 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2511 | // We don't allow the system's nav bar to be hidden |
| 2512 | // again for 1 second, to prevent applications from |
| 2513 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2514 | newVal = mForceClearedSystemUiFlags | |
| 2515 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2516 | if (mForceClearedSystemUiFlags != newVal) { |
| 2517 | mForceClearedSystemUiFlags = newVal; |
| 2518 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2519 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2520 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2521 | } |
| 2522 | if (changed) { |
| 2523 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 2524 | } |
| 2525 | } |
| 2526 | } |
| 2527 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2528 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2529 | } |
| 2530 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2531 | } |
| 2532 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 2533 | new InputEventReceiver.Factory() { |
| 2534 | @Override |
| 2535 | public InputEventReceiver createInputEventReceiver( |
| 2536 | InputChannel inputChannel, Looper looper) { |
| 2537 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 2538 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2539 | }; |
| 2540 | |
| 2541 | @Override |
| 2542 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2543 | if (mStatusBar != null && mStatusHideybar == HIDEYBAR_SHOWING && |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2544 | 0 == (visibility & View.STATUS_BAR_OVERLAY)) { |
| 2545 | mStatusHideybar = HIDEYBAR_HIDING; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 2546 | mStatusBar.hideLw(true); |
| 2547 | } |
John Spurlock | e3b642e | 2013-05-09 15:51:32 -0400 | [diff] [blame] | 2548 | if (mNavigationBar != null && mNavigationHideybar == HIDEYBAR_SHOWING && |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2549 | 0 == (visibility & View.NAVIGATION_BAR_OVERLAY)) { |
| 2550 | mNavigationHideybar = HIDEYBAR_HIDING; |
| 2551 | mNavigationBar.hideLw(true); |
| 2552 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2553 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 2554 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2555 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2556 | // Clear any bits in the new visibility that are currently being |
| 2557 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2558 | return visibility & ~mResettingSystemUiFlags |
| 2559 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2560 | } |
| 2561 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2562 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2563 | public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) { |
| 2564 | final int fl = attrs.flags; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2565 | final int systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2566 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2567 | 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] | 2568 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2569 | int availRight, availBottom; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2570 | if (mCanHideNavigationBar && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2571 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2572 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 2573 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 2574 | } else { |
| 2575 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 2576 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 2577 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2578 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 2579 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 2580 | contentInset.set(mStableFullscreenLeft, mStableFullscreenTop, |
| 2581 | availRight - mStableFullscreenRight, |
| 2582 | availBottom - mStableFullscreenBottom); |
| 2583 | } else { |
| 2584 | contentInset.set(mStableLeft, mStableTop, |
| 2585 | availRight - mStableRight, availBottom - mStableBottom); |
| 2586 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2587 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2588 | contentInset.setEmpty(); |
| 2589 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2590 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
| 2591 | contentInset.set(mCurLeft, mCurTop, |
| 2592 | availRight - mCurRight, availBottom - mCurBottom); |
| 2593 | } else { |
| 2594 | contentInset.set(mCurLeft, mCurTop, |
| 2595 | availRight - mCurRight, availBottom - mCurBottom); |
| 2596 | } |
| 2597 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2598 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2599 | contentInset.setEmpty(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2600 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2601 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2602 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2603 | @Override |
| 2604 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
| 2605 | int displayRotation) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2606 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 2607 | if (isDefaultDisplay) { |
| 2608 | switch (displayRotation) { |
| 2609 | case Surface.ROTATION_90: |
| 2610 | overscanLeft = mOverscanTop; |
| 2611 | overscanTop = mOverscanRight; |
| 2612 | overscanRight = mOverscanBottom; |
| 2613 | overscanBottom = mOverscanLeft; |
| 2614 | break; |
| 2615 | case Surface.ROTATION_180: |
| 2616 | overscanLeft = mOverscanRight; |
| 2617 | overscanTop = mOverscanBottom; |
| 2618 | overscanRight = mOverscanLeft; |
| 2619 | overscanBottom = mOverscanTop; |
| 2620 | break; |
| 2621 | case Surface.ROTATION_270: |
| 2622 | overscanLeft = mOverscanBottom; |
| 2623 | overscanTop = mOverscanLeft; |
| 2624 | overscanRight = mOverscanTop; |
| 2625 | overscanBottom = mOverscanRight; |
| 2626 | break; |
| 2627 | default: |
| 2628 | overscanLeft = mOverscanLeft; |
| 2629 | overscanTop = mOverscanTop; |
| 2630 | overscanRight = mOverscanRight; |
| 2631 | overscanBottom = mOverscanBottom; |
| 2632 | break; |
| 2633 | } |
| 2634 | } else { |
| 2635 | overscanLeft = 0; |
| 2636 | overscanTop = 0; |
| 2637 | overscanRight = 0; |
| 2638 | overscanBottom = 0; |
| 2639 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2640 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 2641 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 2642 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 2643 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2644 | mSystemLeft = 0; |
| 2645 | mSystemTop = 0; |
| 2646 | mSystemRight = displayWidth; |
| 2647 | mSystemBottom = displayHeight; |
| 2648 | mUnrestrictedScreenLeft = overscanLeft; |
| 2649 | mUnrestrictedScreenTop = overscanTop; |
| 2650 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 2651 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 2652 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 2653 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2654 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 2655 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2656 | mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2657 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2658 | mDockTop = mContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2659 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2660 | mDockRight = mContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2661 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2662 | mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2663 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2664 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2665 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2666 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2667 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 2668 | final Rect pf = mTmpParentFrame; |
| 2669 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2670 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2671 | final Rect vf = mTmpVisibleFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2672 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 2673 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 2674 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 2675 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2676 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2677 | if (isDefaultDisplay) { |
| 2678 | // For purposes of putting out fake window up to steal focus, we will |
| 2679 | // drive nav being hidden only by whether it is requested. |
| 2680 | boolean navVisible = (mLastSystemUiFlags&View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2681 | boolean overlayAllowed = (mLastSystemUiFlags&View.SYSTEM_UI_FLAG_ALLOW_OVERLAY) != 0; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2682 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2683 | // When the navigation bar isn't visible, we put up a fake |
| 2684 | // input window to catch all touch events. This way we can |
| 2685 | // detect when the user presses anywhere to bring back the nav |
| 2686 | // bar and ensure the application doesn't see the event. |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2687 | if (navVisible || overlayAllowed) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2688 | if (mHideNavFakeWindow != null) { |
| 2689 | mHideNavFakeWindow.dismiss(); |
| 2690 | mHideNavFakeWindow = null; |
| 2691 | } |
| 2692 | } else if (mHideNavFakeWindow == null) { |
| 2693 | mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow( |
| 2694 | mHandler.getLooper(), mHideNavInputEventReceiverFactory, |
| 2695 | "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, |
| 2696 | 0, false, false, true); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2697 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2698 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2699 | // For purposes of positioning and showing the nav bar, if we have |
| 2700 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 2701 | // then take that into account. |
| 2702 | navVisible |= !mCanHideNavigationBar; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2703 | |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2704 | boolean updateSysUiVisibility = false; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2705 | if (mNavigationBar != null) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2706 | boolean navBarHideyShowing = mNavigationHideybar == HIDEYBAR_SHOWING; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2707 | // Force the navigation bar to its appropriate place and |
| 2708 | // size. We need to do this directly, instead of relying on |
| 2709 | // it to bubble up from the nav bar, because this needs to |
| 2710 | // change atomically with screen rotations. |
| 2711 | mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight); |
| 2712 | if (mNavigationBarOnBottom) { |
| 2713 | // 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] | 2714 | int top = displayHeight - overscanBottom |
| 2715 | - mNavigationBarHeightForRotation[displayRotation]; |
| 2716 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2717 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2718 | if (navBarHideyShowing) { |
| 2719 | mNavigationBar.showLw(true); |
| 2720 | } else if (navVisible) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2721 | mNavigationBar.showLw(true); |
| 2722 | mDockBottom = mTmpNavigationFrame.top; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2723 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 2724 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2725 | } else { |
| 2726 | // We currently want to hide the navigation UI. |
| 2727 | mNavigationBar.hideLw(true); |
| 2728 | } |
| 2729 | if (navVisible && !mNavigationBar.isAnimatingLw()) { |
| 2730 | // If the nav bar is currently requested to be visible, |
| 2731 | // and not in the process of animating on or off, then |
| 2732 | // we can tell the app that it is covered by it. |
| 2733 | mSystemBottom = mTmpNavigationFrame.top; |
| 2734 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2735 | } else { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2736 | // Landscape screen; nav bar goes to the right. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2737 | int left = displayWidth - overscanRight |
| 2738 | - mNavigationBarWidthForRotation[displayRotation]; |
| 2739 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2740 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2741 | if (navBarHideyShowing) { |
| 2742 | mNavigationBar.showLw(true); |
| 2743 | } else if (navVisible) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2744 | mNavigationBar.showLw(true); |
| 2745 | mDockRight = mTmpNavigationFrame.left; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2746 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 2747 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2748 | } else { |
| 2749 | // We currently want to hide the navigation UI. |
| 2750 | mNavigationBar.hideLw(true); |
| 2751 | } |
| 2752 | if (navVisible && !mNavigationBar.isAnimatingLw()) { |
| 2753 | // If the nav bar is currently requested to be visible, |
| 2754 | // and not in the process of animating on or off, then |
| 2755 | // we can tell the app that it is covered by it. |
| 2756 | mSystemRight = mTmpNavigationFrame.left; |
| 2757 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2758 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2759 | // Make sure the content and current rectangles are updated to |
| 2760 | // account for the restrictions from the navigation bar. |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2761 | mContentTop = mCurTop = mDockTop; |
| 2762 | mContentBottom = mCurBottom = mDockBottom; |
| 2763 | mContentLeft = mCurLeft = mDockLeft; |
| 2764 | mContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2765 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 2766 | // And compute the final frame. |
| 2767 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2768 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2769 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2770 | if (mNavigationHideybar == HIDEYBAR_HIDING && !mNavigationBar.isVisibleLw()) { |
| 2771 | // Finished animating out, clean up and reset alpha |
| 2772 | mNavigationHideybar = HIDEYBAR_NONE; |
| 2773 | updateSysUiVisibility = true; |
| 2774 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2775 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2776 | if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)", |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2777 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
| 2778 | |
| 2779 | // decide where the status bar goes ahead of time |
| 2780 | if (mStatusBar != null) { |
| 2781 | // apply any navigation bar insets |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2782 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 2783 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 2784 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 2785 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 2786 | + mUnrestrictedScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2787 | vf.left = mStableLeft; |
| 2788 | vf.top = mStableTop; |
| 2789 | vf.right = mStableRight; |
| 2790 | vf.bottom = mStableBottom; |
| 2791 | |
| 2792 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 2793 | |
| 2794 | // Let the status bar determine its size. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2795 | mStatusBar.computeFrameLw(pf, df, vf, vf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2796 | |
| 2797 | // For layout, the status bar is always at the top with our fixed height. |
| 2798 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 2799 | |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 2800 | boolean statusBarOverlay = (mLastSystemUiFlags & View.STATUS_BAR_OVERLAY) != 0; |
| 2801 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2802 | // If the status bar is hidden, we don't want to cause |
| 2803 | // windows behind it to scroll. |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 2804 | if (mStatusBar.isVisibleLw() && !statusBarOverlay) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2805 | // Status bar may go away, so the screen area it occupies |
| 2806 | // is available to apps but just covering them when the |
| 2807 | // status bar is visible. |
| 2808 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 2809 | |
| 2810 | mContentTop = mCurTop = mDockTop; |
| 2811 | mContentBottom = mCurBottom = mDockBottom; |
| 2812 | mContentLeft = mCurLeft = mDockLeft; |
| 2813 | mContentRight = mCurRight = mDockRight; |
| 2814 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2815 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2816 | String.format( |
| 2817 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 2818 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 2819 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 2820 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 2821 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 2822 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() && !statusBarOverlay) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2823 | // If the status bar is currently requested to be visible, |
| 2824 | // and not in the process of animating on or off, then |
| 2825 | // we can tell the app that it is covered by it. |
| 2826 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 2827 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2828 | |
| 2829 | if (mStatusHideybar == HIDEYBAR_HIDING && !mStatusBar.isVisibleLw()) { |
| 2830 | // Finished animating out, clean up and reset alpha |
| 2831 | mStatusHideybar = HIDEYBAR_NONE; |
| 2832 | updateSysUiVisibility = true; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 2833 | } |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2834 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2835 | if (updateSysUiVisibility) { |
| 2836 | updateSystemUiVisibilityLw(); |
| 2837 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2838 | } |
| 2839 | } |
| 2840 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 2841 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2842 | @Override |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 2843 | public int getSystemDecorRectLw(Rect systemRect) { |
| 2844 | systemRect.left = mSystemLeft; |
| 2845 | systemRect.top = mSystemTop; |
| 2846 | systemRect.right = mSystemRight; |
| 2847 | systemRect.bottom = mSystemBottom; |
| 2848 | if (mStatusBar != null) return mStatusBar.getSurfaceLayer(); |
| 2849 | if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer(); |
| 2850 | return 0; |
| 2851 | } |
| 2852 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2853 | @Override |
| 2854 | public void getContentRectLw(Rect r) { |
| 2855 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 2856 | } |
| 2857 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2858 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 2859 | 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] | 2860 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 2861 | // Here's a special case: if this attached window is a panel that is |
| 2862 | // above the dock window, and the window it is attached to is below |
| 2863 | // the dock window, then the frames we computed for the window it is |
| 2864 | // attached to can not be used because the dock is effectively part |
| 2865 | // of the underlying window and the attached window is floating on top |
| 2866 | // of the whole thing. So, we ignore the attached window and explicitly |
| 2867 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2868 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 2869 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 2870 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 2871 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2872 | } else { |
| 2873 | // The effective display frame of the attached window depends on |
| 2874 | // whether it is taking care of insetting its content. If not, |
| 2875 | // we need to use the parent's content frame so that the entire |
| 2876 | // window is positioned within that content. Otherwise we can use |
| 2877 | // the display frame and let the attached window take care of |
| 2878 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 2879 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2880 | cf.set(attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2881 | } else { |
| 2882 | // If the window is resizing, then we want to base the content |
| 2883 | // frame on our attached content frame to resize... however, |
| 2884 | // things can be tricky if the attached window is NOT in resize |
| 2885 | // mode, in which case its content frame will be larger. |
| 2886 | // Ungh. So to deal with that, make sure the content frame |
| 2887 | // we end up using is not covering the IM dock. |
| 2888 | cf.set(attached.getContentFrameLw()); |
| 2889 | if (attached.getSurfaceLayer() < mDockLayer) { |
| 2890 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 2891 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 2892 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 2893 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 2894 | } |
| 2895 | } |
| 2896 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2897 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2898 | vf.set(attached.getVisibleFrameLw()); |
| 2899 | } |
| 2900 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 2901 | // window should be positioned relative to its parent or the entire |
| 2902 | // screen. |
| 2903 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 2904 | ? attached.getFrameLw() : df); |
| 2905 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2906 | |
| 2907 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 2908 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 2909 | // If app is requesting a stable layout, don't let the |
| 2910 | // content insets go below the stable values. |
| 2911 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 2912 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 2913 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 2914 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 2915 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 2916 | } else { |
| 2917 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 2918 | if (r.top < mStableTop) r.top = mStableTop; |
| 2919 | if (r.right > mStableRight) r.right = mStableRight; |
| 2920 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 2921 | } |
| 2922 | } |
| 2923 | } |
| 2924 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2925 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2926 | @Override |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 2927 | public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs, |
| 2928 | WindowState attached) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2929 | // we've already done the status bar |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2930 | if (win == mStatusBar || win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2931 | return; |
| 2932 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2933 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 2934 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 2935 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 2936 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2937 | if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state"); |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 2938 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 2939 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2940 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2941 | final int fl = attrs.flags; |
| 2942 | final int sim = attrs.softInputMode; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2943 | final int sysUiFl = win.getSystemUiVisibility(); |
| 2944 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2945 | final Rect pf = mTmpParentFrame; |
| 2946 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2947 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2948 | final Rect cf = mTmpContentFrame; |
| 2949 | final Rect vf = mTmpVisibleFrame; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2950 | |
| 2951 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 2952 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2953 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 2954 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 2955 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2956 | if (!isDefaultDisplay) { |
| 2957 | if (attached != null) { |
| 2958 | // If this window is attached to another, our display |
| 2959 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2960 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2961 | } else { |
| 2962 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2963 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 2964 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 2965 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2966 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2967 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2968 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2969 | } |
| 2970 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2971 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 2972 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 2973 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
| 2974 | 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] | 2975 | // IM dock windows always go to the bottom of the screen. |
| 2976 | attrs.gravity = Gravity.BOTTOM; |
| 2977 | mDockLayer = win.getSurfaceLayer(); |
| 2978 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2979 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 2980 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2981 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2982 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2983 | // This is the case for a normal activity window: we want it |
| 2984 | // to cover all of the screen space, and it can take care of |
| 2985 | // moving its contents to account for screen decorations that |
| 2986 | // intrude into that space. |
| 2987 | if (attached != null) { |
| 2988 | // If this window is attached to another, our display |
| 2989 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2990 | 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] | 2991 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2992 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 2993 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 2994 | // Status bar panels are the only windows who can go on top of |
| 2995 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 2996 | // permission, so they have the same privileges as the status |
| 2997 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2998 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 2999 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3000 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3001 | pf.left = df.left = of.left = hasNavBar |
| 3002 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3003 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3004 | pf.right = df.right = of.right = hasNavBar |
| 3005 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 3006 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3007 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 3008 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 3009 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3010 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3011 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3012 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 3013 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3014 | } else if ((attrs.flags&FLAG_LAYOUT_IN_OVERSCAN) != 0 |
| 3015 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3016 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3017 | // Asking to layout into the overscan region, so give it that pure |
| 3018 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3019 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 3020 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 3021 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3022 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 3023 | + mOverscanScreenHeight; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3024 | } else if (mCanHideNavigationBar |
| 3025 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3026 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3027 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3028 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3029 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3030 | // only do this for application windows to ensure no window that |
| 3031 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3032 | pf.left = df.left = mOverscanScreenLeft; |
| 3033 | pf.top = df.top = mOverscanScreenTop; |
| 3034 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3035 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3036 | // We need to tell the app about where the frame inside the overscan |
| 3037 | // is, so it can inset its content by that amount -- it didn't ask |
| 3038 | // to actually extend itself into the overscan region. |
| 3039 | of.left = mUnrestrictedScreenLeft; |
| 3040 | of.top = mUnrestrictedScreenTop; |
| 3041 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3042 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3043 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3044 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 3045 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 3046 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 3047 | + mRestrictedOverscanScreenWidth; |
| 3048 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 3049 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3050 | // We need to tell the app about where the frame inside the overscan |
| 3051 | // is, so it can inset its content by that amount -- it didn't ask |
| 3052 | // to actually extend itself into the overscan region. |
| 3053 | of.left = mUnrestrictedScreenLeft; |
| 3054 | of.top = mUnrestrictedScreenTop; |
| 3055 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3056 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3057 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3058 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3059 | if ((attrs.flags&FLAG_FULLSCREEN) == 0) { |
| 3060 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 3061 | cf.left = mDockLeft; |
| 3062 | cf.top = mDockTop; |
| 3063 | cf.right = mDockRight; |
| 3064 | cf.bottom = mDockBottom; |
| 3065 | } else { |
| 3066 | cf.left = mContentLeft; |
| 3067 | cf.top = mContentTop; |
| 3068 | cf.right = mContentRight; |
| 3069 | cf.bottom = mContentBottom; |
| 3070 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3071 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3072 | // Full screen windows are always given a layout that is as if the |
| 3073 | // status bar and other transient decors are gone. This is to avoid |
| 3074 | // bad states when moving from a window that is not hding the |
| 3075 | // status bar to one that is. |
| 3076 | cf.left = mRestrictedScreenLeft; |
| 3077 | cf.top = mRestrictedScreenTop; |
| 3078 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3079 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3080 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3081 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3082 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3083 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3084 | vf.left = mCurLeft; |
| 3085 | vf.top = mCurTop; |
| 3086 | vf.right = mCurRight; |
| 3087 | vf.bottom = mCurBottom; |
| 3088 | } else { |
| 3089 | vf.set(cf); |
| 3090 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3091 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3092 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 3093 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 3094 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3095 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3096 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3097 | // A window that has requested to fill the entire screen just |
| 3098 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3099 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3100 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3101 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 3102 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3103 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3104 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3105 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3106 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3107 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3108 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3109 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3110 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3111 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 3112 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 3113 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 3114 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3115 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3116 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3117 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3118 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 3119 | + mUnrestrictedScreenWidth; |
| 3120 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 3121 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3122 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3123 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 3124 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3125 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
| 3126 | || attrs.type == TYPE_BOOT_PROGRESS) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 3127 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 3128 | // Fullscreen secure system overlays get what they ask for. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3129 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3130 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3131 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3132 | + mOverscanScreenWidth; |
| 3133 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3134 | + mOverscanScreenHeight; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 3135 | } else if (attrs.type == TYPE_BOOT_PROGRESS |
| 3136 | || attrs.type == TYPE_UNIVERSE_BACKGROUND) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3137 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3138 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3139 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3140 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3141 | + mOverscanScreenWidth; |
| 3142 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3143 | + mOverscanScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3144 | } else if (attrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER) { |
| 3145 | // The wallpaper mostly goes into the overscan region. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3146 | pf.left = df.left = of.left = cf.left = mRestrictedOverscanScreenLeft; |
| 3147 | pf.top = df.top = of.top = cf.top = mRestrictedOverscanScreenTop; |
| 3148 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3149 | = mRestrictedOverscanScreenLeft + mRestrictedOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3150 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3151 | = mRestrictedOverscanScreenTop + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3152 | } else if ((attrs.flags & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
| 3153 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3154 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3155 | // Asking to layout into the overscan region, so give it that pure |
| 3156 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3157 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3158 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3159 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3160 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3161 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3162 | = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3163 | } else if (mCanHideNavigationBar |
| 3164 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3165 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3166 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3167 | // Asking for layout as if the nav bar is hidden, lets the |
| 3168 | // application extend into the unrestricted screen area. We |
| 3169 | // only do this for application windows to ensure no window that |
| 3170 | // can be above the nav bar can do this. |
| 3171 | // XXX This assumes that an app asking for this will also |
| 3172 | // ask for layout in only content. We can't currently figure out |
| 3173 | // 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] | 3174 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3175 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3176 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 3177 | + mUnrestrictedScreenWidth; |
| 3178 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 3179 | + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3180 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3181 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3182 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3183 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3184 | + mRestrictedScreenWidth; |
| 3185 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3186 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3187 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3188 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3189 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3190 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3191 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3192 | vf.left = mCurLeft; |
| 3193 | vf.top = mCurTop; |
| 3194 | vf.right = mCurRight; |
| 3195 | vf.bottom = mCurBottom; |
| 3196 | } else { |
| 3197 | vf.set(cf); |
| 3198 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3199 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3200 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3201 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3202 | // A child window should be placed inside of the same visible |
| 3203 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3204 | 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] | 3205 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3206 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3207 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3208 | // Otherwise, a normal window must be placed inside the content |
| 3209 | // of all screen decorations. |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3210 | if (attrs.type == TYPE_STATUS_BAR_PANEL) { |
| 3211 | // Status bar panels are the only windows who can go on top of |
| 3212 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3213 | // permission, so they have the same privileges as the status |
| 3214 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3215 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3216 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3217 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3218 | + mRestrictedScreenWidth; |
| 3219 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3220 | + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3221 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3222 | pf.left = mContentLeft; |
| 3223 | pf.top = mContentTop; |
| 3224 | pf.right = mContentRight; |
| 3225 | pf.bottom = mContentBottom; |
| 3226 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3227 | df.left = of.left = cf.left = mDockLeft; |
| 3228 | df.top = of.top = cf.top = mDockTop; |
| 3229 | df.right = of.right = cf.right = mDockRight; |
| 3230 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3231 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3232 | df.left = of.left = cf.left = mContentLeft; |
| 3233 | df.top = of.top = cf.top = mContentTop; |
| 3234 | df.right = of.right = cf.right = mContentRight; |
| 3235 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3236 | } |
| 3237 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3238 | vf.left = mCurLeft; |
| 3239 | vf.top = mCurTop; |
| 3240 | vf.right = mCurRight; |
| 3241 | vf.bottom = mCurBottom; |
| 3242 | } else { |
| 3243 | vf.set(cf); |
| 3244 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3245 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3246 | } |
| 3247 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3248 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 3249 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
| 3250 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3251 | df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 3252 | df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom |
| 3253 | = vf.right = vf.bottom = 10000; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3254 | } |
| 3255 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3256 | if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle() |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3257 | + ": sim=#" + Integer.toHexString(sim) |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3258 | + " attach=" + attached + " type=" + attrs.type |
| 3259 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3260 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3261 | + " of=" + of.toShortString() |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3262 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3263 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3264 | win.computeFrameLw(pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3265 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3266 | // Dock windows carve out the bottom of the screen, so normal windows |
| 3267 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 3268 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
| 3269 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3270 | setLastInputMethodWindowLw(null, null); |
| 3271 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3272 | } |
| 3273 | } |
| 3274 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3275 | private void offsetInputMethodWindowLw(WindowState win) { |
| 3276 | int top = win.getContentFrameLw().top; |
| 3277 | top += win.getGivenContentInsetsLw().top; |
| 3278 | if (mContentBottom > top) { |
| 3279 | mContentBottom = top; |
| 3280 | } |
| 3281 | top = win.getVisibleFrameLw().top; |
| 3282 | top += win.getGivenVisibleInsetsLw().top; |
| 3283 | if (mCurBottom > top) { |
| 3284 | mCurBottom = top; |
| 3285 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3286 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3287 | + mDockBottom + " mContentBottom=" |
| 3288 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 3289 | } |
| 3290 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3291 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 3292 | @Override |
| 3293 | public void finishLayoutLw() { |
| 3294 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3295 | } |
| 3296 | |
| 3297 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3298 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3299 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3300 | mTopFullscreenOpaqueWindowState = null; |
| 3301 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3302 | mForceStatusBarFromKeyguard = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3303 | mForcingShowNavBar = false; |
| 3304 | mForcingShowNavBarLayer = -1; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3305 | |
| 3306 | mHideLockScreen = false; |
| 3307 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3308 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3309 | mShowingLockscreen = false; |
| 3310 | mShowingDream = false; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3311 | } |
| 3312 | |
| 3313 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3314 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3315 | public void applyPostLayoutPolicyLw(WindowState win, |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3316 | WindowManager.LayoutParams attrs) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3317 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 3318 | + win.isVisibleOrBehindKeyguardLw()); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3319 | if (mTopFullscreenOpaqueWindowState == null && (win.getAttrs().privateFlags |
| 3320 | &WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_SHOW_NAV_BAR) != 0) { |
| 3321 | if (mForcingShowNavBarLayer < 0) { |
| 3322 | mForcingShowNavBar = true; |
| 3323 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
| 3324 | } |
| 3325 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3326 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 3327 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3328 | if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3329 | if (attrs.type == TYPE_KEYGUARD) { |
| 3330 | mForceStatusBarFromKeyguard = true; |
| 3331 | } else { |
| 3332 | mForceStatusBar = true; |
| 3333 | } |
| 3334 | } |
| 3335 | if (attrs.type == TYPE_KEYGUARD) { |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3336 | mShowingLockscreen = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3337 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3338 | boolean applyWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
| 3339 | && attrs.type <= LAST_APPLICATION_WINDOW; |
| 3340 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 3341 | // If the lockscreen was showing when the dream started then wait |
| 3342 | // for the dream to draw before hiding the lockscreen. |
| 3343 | if (!mDreamingLockscreen |
| 3344 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 3345 | mShowingDream = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3346 | applyWindow = true; |
| 3347 | } |
| 3348 | } |
| 3349 | if (applyWindow |
Dianne Hackborn | 6493e64 | 2010-10-01 13:06:30 -0700 | [diff] [blame] | 3350 | && attrs.x == 0 && attrs.y == 0 |
| 3351 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 3352 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3353 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3354 | mTopFullscreenOpaqueWindowState = win; |
| 3355 | if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3356 | if (DEBUG_LAYOUT) Slog.v(TAG, "Setting mHideLockScreen to true by win " + win); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3357 | mHideLockScreen = true; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3358 | mForceStatusBarFromKeyguard = false; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3359 | } |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3360 | if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0 |
| 3361 | && mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3362 | if (DEBUG_LAYOUT) Slog.v(TAG, "Setting mDismissKeyguard true by win " + win); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3363 | mDismissKeyguard = mWinDismissingKeyguard == win ? |
| 3364 | DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
| 3365 | mWinDismissingKeyguard = win; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3366 | mForceStatusBarFromKeyguard = mShowingLockscreen && isKeyguardSecure(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3367 | } |
| 3368 | if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
| 3369 | mAllowLockscreenWhenOn = true; |
| 3370 | } |
| 3371 | } |
| 3372 | } |
| 3373 | } |
| 3374 | |
| 3375 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3376 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3377 | public int finishPostLayoutPolicyLw() { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3378 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3379 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3380 | |
| 3381 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 3382 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 3383 | : null; |
| 3384 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 3385 | // If we are not currently showing a dream then remember the current |
| 3386 | // lockscreen state. We will use this to determine whether the dream |
| 3387 | // started while the lockscreen was showing and remember this state |
| 3388 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3389 | if (!mShowingDream) { |
| 3390 | mDreamingLockscreen = mShowingLockscreen; |
| 3391 | } |
| 3392 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3393 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3394 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3395 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 3396 | + " top=" + mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3397 | if (mForceStatusBar || mForceStatusBarFromKeyguard) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3398 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3399 | if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3400 | } else if (mTopFullscreenOpaqueWindowState != null) { |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3401 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3402 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3403 | + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3404 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3405 | + " lp.flags=0x" + Integer.toHexString(lp.flags)); |
| 3406 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3407 | topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
| 3408 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3409 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
| 3410 | // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window |
| 3411 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 3412 | // case though. |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 3413 | if (mStatusHideybar == HIDEYBAR_SHOWING) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3414 | if (mStatusBar.showLw(true)) { |
| 3415 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3416 | } |
| 3417 | } else if (topIsFullscreen) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3418 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3419 | if (mStatusBar.hideLw(true)) { |
| 3420 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Daniel Sandler | 9c00d5b | 2011-09-13 14:04:26 -0400 | [diff] [blame] | 3421 | |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3422 | mHandler.post(new Runnable() { |
| 3423 | @Override |
| 3424 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3425 | try { |
| 3426 | IStatusBarService statusbar = getStatusBarService(); |
| 3427 | if (statusbar != null) { |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 3428 | statusbar.collapsePanels(); |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 3429 | } |
| 3430 | } catch (RemoteException ex) { |
| 3431 | // re-acquire status bar service next time it is needed. |
| 3432 | mStatusBarService = null; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3433 | } |
| 3434 | }}); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3435 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 3436 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 3437 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3438 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3439 | if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen"); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3440 | if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3441 | } |
| 3442 | } |
| 3443 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3444 | |
Joe Onorato | 644f9c3 | 2011-01-25 12:06:23 -0800 | [diff] [blame] | 3445 | mTopIsFullscreen = topIsFullscreen; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3446 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3447 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 3448 | // displayed when the screen is locked. |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 3449 | if (mKeyguard != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3450 | if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3451 | + mHideLockScreen); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3452 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardDelegate.isSecure()) { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3453 | if (mKeyguard.hideLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3454 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3455 | | FINISH_LAYOUT_REDO_CONFIG |
| 3456 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3457 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3458 | if (mKeyguardDelegate.isShowing()) { |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 3459 | mHandler.post(new Runnable() { |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3460 | @Override |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 3461 | public void run() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3462 | mKeyguardDelegate.keyguardDone(false, false); |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 3463 | } |
| 3464 | }); |
| 3465 | } |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 3466 | } else if (mHideLockScreen) { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3467 | if (mKeyguard.hideLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3468 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3469 | | FINISH_LAYOUT_REDO_CONFIG |
| 3470 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3471 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3472 | mKeyguardDelegate.setHidden(true); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3473 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
| 3474 | // This is the case of keyguard isSecure() and not mHideLockScreen. |
| 3475 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 3476 | // Only launch the next keyguard unlock window once per window. |
| 3477 | if (mKeyguard.showLw(true)) { |
| 3478 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3479 | | FINISH_LAYOUT_REDO_CONFIG |
| 3480 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3481 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3482 | mKeyguardDelegate.setHidden(false); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3483 | mHandler.post(new Runnable() { |
| 3484 | @Override |
| 3485 | public void run() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3486 | mKeyguardDelegate.dismiss(); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3487 | } |
| 3488 | }); |
| 3489 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 3490 | } else { |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3491 | mWinDismissingKeyguard = null; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3492 | if (mKeyguard.showLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3493 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3494 | | FINISH_LAYOUT_REDO_CONFIG |
| 3495 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3496 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3497 | mKeyguardDelegate.setHidden(false); |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 3498 | } |
| 3499 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3500 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3501 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3502 | // If the navigation bar has been hidden or shown, we need to do another |
| 3503 | // layout pass to update that window. |
| 3504 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3505 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3506 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 3507 | // update since mAllowLockscreenWhenOn might have changed |
| 3508 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3509 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3510 | } |
| 3511 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3512 | public boolean allowAppAnimationsLw() { |
Craig Mautner | f03e4c5 | 2012-06-14 14:11:27 -0700 | [diff] [blame] | 3513 | if (mKeyguard != null && mKeyguard.isVisibleLw() && !mKeyguard.isAnimatingLw()) { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3514 | // If keyguard is currently visible, no reason to animate |
| 3515 | // behind it. |
| 3516 | return false; |
| 3517 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3518 | return true; |
| 3519 | } |
| 3520 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3521 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3522 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3523 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3524 | // If the navigation bar has been hidden or shown, we need to do another |
| 3525 | // layout pass to update that window. |
| 3526 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 3527 | } |
| 3528 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3529 | } |
| 3530 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 3531 | /** {@inheritDoc} */ |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3532 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 3533 | // do nothing if headless |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 3534 | if (mHeadless) return; |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 3535 | |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3536 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3537 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 3538 | if (newLidState == mLidState) { |
| 3539 | return; |
| 3540 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 3541 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3542 | mLidState = newLidState; |
| 3543 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 3544 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3545 | |
| 3546 | if (lidOpen) { |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 3547 | mPowerManager.wakeUp(SystemClock.uptimeMillis()); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3548 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3549 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3550 | } |
| 3551 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3552 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3553 | void setHdmiPlugged(boolean plugged) { |
| 3554 | if (mHdmiPlugged != plugged) { |
| 3555 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3556 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3557 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 3558 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3559 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 3560 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3561 | } |
| 3562 | } |
| 3563 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 3564 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 3565 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 3566 | // watch for HDMI plug messages if the hdmi switch exists |
| 3567 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 3568 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 3569 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 3570 | final String filename = "/sys/class/switch/hdmi/state"; |
| 3571 | FileReader reader = null; |
| 3572 | try { |
| 3573 | reader = new FileReader(filename); |
| 3574 | char[] buf = new char[15]; |
| 3575 | int n = reader.read(buf); |
| 3576 | if (n > 1) { |
| 3577 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 3578 | } |
| 3579 | } catch (IOException ex) { |
| 3580 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 3581 | } catch (NumberFormatException ex) { |
| 3582 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 3583 | } finally { |
| 3584 | if (reader != null) { |
| 3585 | try { |
| 3586 | reader.close(); |
| 3587 | } catch (IOException ex) { |
| 3588 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 3589 | } |
| 3590 | } |
| 3591 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 3592 | // This dance forces the code in setHdmiPlugged to run. |
| 3593 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 3594 | mHdmiPlugged = !plugged; |
| 3595 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 3596 | } |
| 3597 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3598 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3599 | * @return Whether music is being played right now. |
| 3600 | */ |
| 3601 | boolean isMusicActive() { |
Eric Laurent | 413cb9d | 2009-07-17 11:52:43 -0700 | [diff] [blame] | 3602 | final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); |
| 3603 | if (am == null) { |
| 3604 | Log.w(TAG, "isMusicActive: couldn't get AudioManager reference"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3605 | return false; |
| 3606 | } |
Eric Laurent | 413cb9d | 2009-07-17 11:52:43 -0700 | [diff] [blame] | 3607 | return am.isMusicActive(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3608 | } |
| 3609 | |
| 3610 | /** |
| 3611 | * Tell the audio service to adjust the volume appropriate to the event. |
| 3612 | * @param keycode |
| 3613 | */ |
Mike Lockwood | a53e381 | 2009-09-25 10:51:39 -0400 | [diff] [blame] | 3614 | void handleVolumeKey(int stream, int keycode) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3615 | IAudioService audioService = getAudioService(); |
| 3616 | if (audioService == null) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3617 | return; |
| 3618 | } |
| 3619 | try { |
| 3620 | // since audio is playing, we shouldn't have to hold a wake lock |
| 3621 | // during the call, but we do it as a precaution for the rare possibility |
| 3622 | // that the music stops right before we call this |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 3623 | // TODO: Actually handle MUTE. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3624 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3625 | audioService.adjustStreamVolume(stream, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3626 | keycode == KeyEvent.KEYCODE_VOLUME_UP |
| 3627 | ? AudioManager.ADJUST_RAISE |
| 3628 | : AudioManager.ADJUST_LOWER, |
Dianne Hackborn | ba50b97c | 2013-04-30 15:04:46 -0700 | [diff] [blame] | 3629 | 0, |
| 3630 | mContext.getBasePackageName()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3631 | } catch (RemoteException e) { |
| 3632 | Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e); |
| 3633 | } finally { |
| 3634 | mBroadcastWakeLock.release(); |
| 3635 | } |
| 3636 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3637 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 3638 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 3639 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 3640 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3641 | final Runnable mScreenshotTimeout = new Runnable() { |
| 3642 | @Override public void run() { |
| 3643 | synchronized (mScreenshotLock) { |
| 3644 | if (mScreenshotConnection != null) { |
| 3645 | mContext.unbindService(mScreenshotConnection); |
| 3646 | mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 3647 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3648 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3649 | } |
| 3650 | }; |
| 3651 | |
| 3652 | // Assume this is called from the Handler thread. |
| 3653 | private void takeScreenshot() { |
| 3654 | synchronized (mScreenshotLock) { |
| 3655 | if (mScreenshotConnection != null) { |
| 3656 | return; |
| 3657 | } |
| 3658 | ComponentName cn = new ComponentName("com.android.systemui", |
| 3659 | "com.android.systemui.screenshot.TakeScreenshotService"); |
| 3660 | Intent intent = new Intent(); |
| 3661 | intent.setComponent(cn); |
| 3662 | ServiceConnection conn = new ServiceConnection() { |
| 3663 | @Override |
| 3664 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 3665 | synchronized (mScreenshotLock) { |
| 3666 | if (mScreenshotConnection != this) { |
| 3667 | return; |
| 3668 | } |
| 3669 | Messenger messenger = new Messenger(service); |
| 3670 | Message msg = Message.obtain(null, 1); |
| 3671 | final ServiceConnection myConn = this; |
| 3672 | Handler h = new Handler(mHandler.getLooper()) { |
| 3673 | @Override |
| 3674 | public void handleMessage(Message msg) { |
| 3675 | synchronized (mScreenshotLock) { |
| 3676 | if (mScreenshotConnection == myConn) { |
| 3677 | mContext.unbindService(mScreenshotConnection); |
| 3678 | mScreenshotConnection = null; |
| 3679 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 3680 | } |
| 3681 | } |
| 3682 | } |
| 3683 | }; |
| 3684 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 3685 | msg.arg1 = msg.arg2 = 0; |
| 3686 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 3687 | msg.arg1 = 1; |
| 3688 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 3689 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3690 | try { |
| 3691 | messenger.send(msg); |
| 3692 | } catch (RemoteException e) { |
| 3693 | } |
| 3694 | } |
| 3695 | } |
| 3696 | @Override |
| 3697 | public void onServiceDisconnected(ComponentName name) {} |
| 3698 | }; |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 3699 | if (mContext.bindServiceAsUser( |
| 3700 | intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3701 | mScreenshotConnection = conn; |
| 3702 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 3703 | } |
| 3704 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3705 | } |
| 3706 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3707 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3708 | @Override |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3709 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3710 | if (!mSystemBooted) { |
| 3711 | // If we have not yet booted, don't let key events do anything. |
| 3712 | return 0; |
| 3713 | } |
| 3714 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3715 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 3716 | final boolean canceled = event.isCanceled(); |
| 3717 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 3718 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 3719 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 3720 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 3721 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 3722 | // the same as if it were open and in front. |
| 3723 | // This will prevent any keys other than the power button from waking the screen |
| 3724 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3725 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 3726 | (isScreenOn ? |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3727 | mKeyguardDelegate.isShowingAndNotHidden() : |
| 3728 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3729 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3730 | if (keyCode == KeyEvent.KEYCODE_POWER) { |
| 3731 | policyFlags |= WindowManagerPolicy.FLAG_WAKE; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 3732 | } |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3733 | final boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE |
| 3734 | | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 3735 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3736 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3737 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3738 | + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive |
| 3739 | + " policyFlags=" + Integer.toHexString(policyFlags) |
| 3740 | + " isWakeKey=" + isWakeKey); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3741 | } |
| 3742 | |
Jeff Brown | 98392ef | 2011-09-12 18:24:59 -0700 | [diff] [blame] | 3743 | if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 3744 | && event.getRepeatCount() == 0) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3745 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 3746 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3747 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3748 | // Basic policy based on screen state and keyguard. |
| 3749 | // FIXME: This policy isn't quite correct. We shouldn't care whether the screen |
| 3750 | // is on or off, really. We should care about whether the device is in an |
| 3751 | // interactive state or is in suspend pretending to be "off". |
| 3752 | // The primary screen might be turned off due to proximity sensor or |
| 3753 | // because we are presenting media on an auxiliary screen or remotely controlling |
| 3754 | // the device some other way (which is why we have an exemption here for injected |
| 3755 | // events). |
| 3756 | int result; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 3757 | if ((isScreenOn && !mHeadless) || (isInjected && !isWakeKey)) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3758 | // When the screen is on or if the key is injected pass the key to the application. |
| 3759 | result = ACTION_PASS_TO_USER; |
| 3760 | } else { |
| 3761 | // When the screen is off and the key is not injected, determine whether |
| 3762 | // to wake the device but don't pass the key to the application. |
| 3763 | result = 0; |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 3764 | if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) { |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 3765 | result |= ACTION_WAKE_UP; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3766 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3767 | } |
| 3768 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 3769 | // If the key would be handled globally, just return the result, don't worry about special |
| 3770 | // key processing. |
| 3771 | if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
| 3772 | return result; |
| 3773 | } |
| 3774 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3775 | // Handle special keys. |
| 3776 | switch (keyCode) { |
| 3777 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 3778 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 3779 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3780 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 3781 | if (down) { |
| 3782 | if (isScreenOn && !mVolumeDownKeyTriggered |
| 3783 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3784 | mVolumeDownKeyTriggered = true; |
| 3785 | mVolumeDownKeyTime = event.getDownTime(); |
| 3786 | mVolumeDownKeyConsumedByScreenshotChord = false; |
| 3787 | cancelPendingPowerKeyAction(); |
| 3788 | interceptScreenshotChord(); |
| 3789 | } |
| 3790 | } else { |
| 3791 | mVolumeDownKeyTriggered = false; |
| 3792 | cancelPendingScreenshotChordAction(); |
| 3793 | } |
| 3794 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 3795 | if (down) { |
| 3796 | if (isScreenOn && !mVolumeUpKeyTriggered |
| 3797 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3798 | mVolumeUpKeyTriggered = true; |
| 3799 | cancelPendingPowerKeyAction(); |
| 3800 | cancelPendingScreenshotChordAction(); |
| 3801 | } |
| 3802 | } else { |
| 3803 | mVolumeUpKeyTriggered = false; |
| 3804 | cancelPendingScreenshotChordAction(); |
| 3805 | } |
| 3806 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3807 | if (down) { |
| 3808 | ITelephony telephonyService = getTelephonyService(); |
| 3809 | if (telephonyService != null) { |
| 3810 | try { |
| 3811 | if (telephonyService.isRinging()) { |
| 3812 | // If an incoming call is ringing, either VOLUME key means |
| 3813 | // "silence ringer". We handle these keys here, rather than |
| 3814 | // in the InCallScreen, to make sure we'll respond to them |
| 3815 | // even if the InCallScreen hasn't come to the foreground yet. |
| 3816 | // Look for the DOWN event here, to agree with the "fallback" |
| 3817 | // behavior in the InCallScreen. |
| 3818 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 3819 | + " VOLUME key-down while ringing: Silence ringer!"); |
| 3820 | |
| 3821 | // Silence the ringer. (It's safe to call this |
| 3822 | // even if the ringer has already been silenced.) |
| 3823 | telephonyService.silenceRinger(); |
| 3824 | |
| 3825 | // And *don't* pass this key thru to the current activity |
| 3826 | // (which is probably the InCallScreen.) |
| 3827 | result &= ~ACTION_PASS_TO_USER; |
| 3828 | break; |
| 3829 | } |
| 3830 | if (telephonyService.isOffhook() |
| 3831 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 3832 | // If we are in call but we decided not to pass the key to |
| 3833 | // the application, handle the volume change here. |
| 3834 | handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode); |
| 3835 | break; |
| 3836 | } |
| 3837 | } catch (RemoteException ex) { |
| 3838 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 3839 | } |
| 3840 | } |
| 3841 | |
| 3842 | if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) { |
| 3843 | // If music is playing but we decided not to pass the key to the |
| 3844 | // application, handle the volume change here. |
| 3845 | handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode); |
| 3846 | break; |
| 3847 | } |
| 3848 | } |
| 3849 | break; |
| 3850 | } |
| 3851 | |
| 3852 | case KeyEvent.KEYCODE_ENDCALL: { |
| 3853 | result &= ~ACTION_PASS_TO_USER; |
| 3854 | if (down) { |
| 3855 | ITelephony telephonyService = getTelephonyService(); |
| 3856 | boolean hungUp = false; |
| 3857 | if (telephonyService != null) { |
| 3858 | try { |
| 3859 | hungUp = telephonyService.endCall(); |
| 3860 | } catch (RemoteException ex) { |
| 3861 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 3862 | } |
| 3863 | } |
| 3864 | interceptPowerKeyDown(!isScreenOn || hungUp); |
| 3865 | } else { |
| 3866 | if (interceptPowerKeyUp(canceled)) { |
| 3867 | if ((mEndcallBehavior |
| 3868 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 3869 | if (goHome()) { |
| 3870 | break; |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 3871 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3872 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3873 | if ((mEndcallBehavior |
| 3874 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3875 | result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3876 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3877 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3878 | } |
| 3879 | break; |
| 3880 | } |
| 3881 | |
| 3882 | case KeyEvent.KEYCODE_POWER: { |
| 3883 | result &= ~ACTION_PASS_TO_USER; |
| 3884 | if (down) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3885 | if (isScreenOn && !mPowerKeyTriggered |
| 3886 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3887 | mPowerKeyTriggered = true; |
| 3888 | mPowerKeyTime = event.getDownTime(); |
| 3889 | interceptScreenshotChord(); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3890 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3891 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3892 | ITelephony telephonyService = getTelephonyService(); |
| 3893 | boolean hungUp = false; |
| 3894 | if (telephonyService != null) { |
| 3895 | try { |
| 3896 | if (telephonyService.isRinging()) { |
| 3897 | // Pressing Power while there's a ringing incoming |
| 3898 | // call should silence the ringer. |
| 3899 | telephonyService.silenceRinger(); |
| 3900 | } else if ((mIncallPowerBehavior |
| 3901 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 3902 | && telephonyService.isOffhook()) { |
| 3903 | // Otherwise, if "Power button ends call" is enabled, |
| 3904 | // the Power button will hang up any current active call. |
| 3905 | hungUp = telephonyService.endCall(); |
| 3906 | } |
| 3907 | } catch (RemoteException ex) { |
| 3908 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 3909 | } |
| 3910 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3911 | interceptPowerKeyDown(!isScreenOn || hungUp |
| 3912 | || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3913 | } else { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3914 | mPowerKeyTriggered = false; |
| 3915 | cancelPendingScreenshotChordAction(); |
| 3916 | if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3917 | result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3918 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3919 | mPendingPowerKeyUpCanceled = false; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3920 | } |
| 3921 | break; |
| 3922 | } |
| 3923 | |
| 3924 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 3925 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 3926 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 3927 | if (down) { |
| 3928 | ITelephony telephonyService = getTelephonyService(); |
| 3929 | if (telephonyService != null) { |
| 3930 | try { |
| 3931 | if (!telephonyService.isIdle()) { |
| 3932 | // Suppress PLAY/PAUSE toggle when phone is ringing or in-call |
| 3933 | // to avoid music playback. |
| 3934 | break; |
| 3935 | } |
| 3936 | } catch (RemoteException ex) { |
| 3937 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 3938 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3939 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3940 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3941 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 3942 | case KeyEvent.KEYCODE_MUTE: |
| 3943 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 3944 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 3945 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 3946 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 3947 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 3948 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 3949 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3950 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 3951 | // Only do this if we would otherwise not pass it to the user. In that |
| 3952 | // case, the PhoneWindow class will do the same thing, except it will |
| 3953 | // 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] | 3954 | // Note that we need to make a copy of the key event here because the |
| 3955 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3956 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3957 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 3958 | new KeyEvent(event)); |
| 3959 | msg.setAsynchronous(true); |
| 3960 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3961 | } |
| 3962 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3963 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3964 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3965 | case KeyEvent.KEYCODE_CALL: { |
| 3966 | if (down) { |
| 3967 | ITelephony telephonyService = getTelephonyService(); |
| 3968 | if (telephonyService != null) { |
| 3969 | try { |
| 3970 | if (telephonyService.isRinging()) { |
| 3971 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 3972 | + " CALL key-down while ringing: Answer the call!"); |
| 3973 | telephonyService.answerRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3974 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3975 | // And *don't* pass this key thru to the current activity |
| 3976 | // (which is presumably the InCallScreen.) |
| 3977 | result &= ~ACTION_PASS_TO_USER; |
| 3978 | } |
| 3979 | } catch (RemoteException ex) { |
| 3980 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3981 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3982 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3983 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3984 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3985 | } |
| 3986 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3987 | return result; |
| 3988 | } |
| 3989 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 3990 | /** |
| 3991 | * When the screen is off we ignore some keys that might otherwise typically |
| 3992 | * be considered wake keys. We filter them out here. |
| 3993 | * |
| 3994 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 3995 | * is always considered a wake key. |
| 3996 | */ |
| 3997 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 3998 | switch (keyCode) { |
| 3999 | // ignore volume keys unless docked |
| 4000 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4001 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 4002 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 4003 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 4004 | |
| 4005 | // ignore media and camera keys |
| 4006 | case KeyEvent.KEYCODE_MUTE: |
| 4007 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4008 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4009 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4010 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 4011 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4012 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4013 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4014 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4015 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 4016 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4017 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4018 | case KeyEvent.KEYCODE_CAMERA: |
| 4019 | return false; |
| 4020 | } |
| 4021 | return true; |
| 4022 | } |
| 4023 | |
| 4024 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4025 | /** {@inheritDoc} */ |
| 4026 | @Override |
| 4027 | public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) { |
| 4028 | int result = 0; |
| 4029 | |
| 4030 | final boolean isWakeMotion = (policyFlags |
| 4031 | & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0; |
| 4032 | if (isWakeMotion) { |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 4033 | result |= ACTION_WAKE_UP; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4034 | } |
| 4035 | return result; |
| 4036 | } |
| 4037 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4038 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 4039 | if (DEBUG_INPUT) { |
| 4040 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4041 | } |
| 4042 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4043 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 4044 | if (DEBUG_INPUT) { |
| 4045 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 4046 | } |
| 4047 | |
| 4048 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 4049 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 4050 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 4051 | } |
| 4052 | |
| 4053 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 4054 | |
| 4055 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 4056 | && event.getRepeatCount() == 0) { |
| 4057 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 4058 | |
| 4059 | Message msg = mHandler.obtainMessage( |
| 4060 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 4061 | msg.setAsynchronous(true); |
| 4062 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 4063 | } else { |
| 4064 | mBroadcastWakeLock.release(); |
| 4065 | } |
| 4066 | } |
| 4067 | |
| 4068 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 4069 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 4070 | |
| 4071 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 4072 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 4073 | if (DEBUG_INPUT) { |
| 4074 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 4075 | } |
| 4076 | |
| 4077 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 4078 | mBroadcastWakeLock.release(); |
| 4079 | } |
| 4080 | |
| 4081 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 4082 | if (ActivityManagerNative.isSystemReady()) { |
| 4083 | IAudioService audioService = getAudioService(); |
| 4084 | if (audioService != null) { |
| 4085 | try { |
| 4086 | audioService.dispatchMediaKeyEventUnderWakelock(event); |
| 4087 | } catch (RemoteException e) { |
| 4088 | Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e); |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 4089 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4090 | } |
| 4091 | } |
| 4092 | } |
| 4093 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4094 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 4095 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4096 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 4097 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 4098 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 4099 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4100 | } else { |
| 4101 | try { |
| 4102 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 4103 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 4104 | mUiMode = uiModeService.getCurrentModeType(); |
| 4105 | } catch (RemoteException e) { |
| 4106 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 4107 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4108 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 4109 | synchronized (mLock) { |
| 4110 | updateOrientationListenerLp(); |
| 4111 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4112 | } |
| 4113 | }; |
| 4114 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4115 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 4116 | @Override |
| 4117 | public void onReceive(Context context, Intent intent) { |
| 4118 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4119 | if (mKeyguardDelegate != null) { |
| 4120 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4121 | } |
| 4122 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4123 | if (mKeyguardDelegate != null) { |
| 4124 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4125 | } |
| 4126 | } |
| 4127 | } |
| 4128 | }; |
| 4129 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4130 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 4131 | @Override |
| 4132 | public void onReceive(Context context, Intent intent) { |
| 4133 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 4134 | // tickle the settings observer: this first ensures that we're |
| 4135 | // observing the relevant settings for the newly-active user, |
| 4136 | // and then updates our own bookkeeping based on the now- |
| 4137 | // current user. |
| 4138 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 4139 | |
| 4140 | // force a re-application of focused window sysui visibility. |
| 4141 | // the window may never have been shown for this user |
| 4142 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4143 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 4144 | mLastSystemUiFlags = 0; |
| 4145 | updateSystemUiVisibilityLw(); |
| 4146 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4147 | } |
| 4148 | } |
| 4149 | }; |
| 4150 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4151 | private void requestHideybars(WindowState swipeTarget) { |
| 4152 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4153 | boolean sb = checkShowHideybar("status", mStatusHideybar, mStatusBar); |
| 4154 | boolean nb = checkShowHideybar("navigation", mNavigationHideybar, mNavigationBar); |
| 4155 | if (sb || nb) { |
| 4156 | WindowState hideyTarget = sb ? mStatusBar : mNavigationBar; |
| 4157 | if (sb ^ nb && hideyTarget != swipeTarget) { |
| 4158 | if (DEBUG) Slog.d(TAG, "Not showing hideybar, wrong swipe target"); |
| 4159 | return; |
| 4160 | } |
| 4161 | mStatusHideybar = sb ? HIDEYBAR_SHOWING : mStatusHideybar; |
| 4162 | mNavigationHideybar = nb ? HIDEYBAR_SHOWING : mNavigationHideybar; |
| 4163 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4164 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4165 | } |
| 4166 | } |
| 4167 | |
| 4168 | private boolean checkShowHideybar(String tag, int hideybar, WindowState win) { |
| 4169 | if (hideybar == HIDEYBAR_SHOWING) { |
| 4170 | if (DEBUG) Slog.d(TAG, "Not showing " + tag + " hideybar, already shown"); |
| 4171 | return false; |
John Spurlock | e3b642e | 2013-05-09 15:51:32 -0400 | [diff] [blame] | 4172 | } else if (win == null) { |
| 4173 | if (DEBUG) Slog.d(TAG, "Not showing " + tag + " hideybar, bar doesn't exist"); |
| 4174 | return false; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4175 | } else if (win.isDisplayedLw()) { |
| 4176 | if (DEBUG) Slog.d(TAG, "Not showing " + tag + " hideybar, bar already visible"); |
| 4177 | return false; |
| 4178 | } else { |
| 4179 | return true; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4180 | } |
| 4181 | } |
| 4182 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4183 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4184 | public void screenTurnedOff(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 4185 | EventLog.writeEvent(70000, 0); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4186 | synchronized (mLock) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4187 | mScreenOnEarly = false; |
| 4188 | mScreenOnFully = false; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4189 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4190 | if (mKeyguardDelegate != null) { |
| 4191 | mKeyguardDelegate.onScreenTurnedOff(why); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4192 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4193 | synchronized (mLock) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4194 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4195 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4196 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4197 | } |
| 4198 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4199 | @Override |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 4200 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 4201 | EventLog.writeEvent(70000, 1); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 4202 | if (false) { |
| 4203 | RuntimeException here = new RuntimeException("here"); |
| 4204 | here.fillInStackTrace(); |
| 4205 | Slog.i(TAG, "Screen turning on...", here); |
| 4206 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4207 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4208 | synchronized (mLock) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4209 | mScreenOnEarly = true; |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4210 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4211 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4212 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4213 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4214 | waitForKeyguard(screenOnListener); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4215 | } |
| 4216 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4217 | private void waitForKeyguard(final ScreenOnListener screenOnListener) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4218 | if (mKeyguardDelegate != null) { |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4219 | if (screenOnListener != null) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4220 | mKeyguardDelegate.onScreenTurnedOn(new KeyguardServiceDelegate.ShowListener() { |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4221 | @Override |
| 4222 | public void onShown(IBinder windowToken) { |
| 4223 | waitForKeyguardWindowDrawn(windowToken, screenOnListener); |
| 4224 | } |
| 4225 | }); |
| 4226 | return; |
| 4227 | } else { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4228 | mKeyguardDelegate.onScreenTurnedOn(null); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4229 | } |
| 4230 | } else { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4231 | Slog.i(TAG, "No keyguard interface!"); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4232 | } |
| 4233 | finishScreenTurningOn(screenOnListener); |
| 4234 | } |
| 4235 | |
| 4236 | private void waitForKeyguardWindowDrawn(IBinder windowToken, |
| 4237 | final ScreenOnListener screenOnListener) { |
| 4238 | if (windowToken != null) { |
| 4239 | try { |
| 4240 | if (mWindowManager.waitForWindowDrawn( |
| 4241 | windowToken, new IRemoteCallback.Stub() { |
| 4242 | @Override |
| 4243 | public void sendResult(Bundle data) { |
| 4244 | Slog.i(TAG, "Lock screen displayed!"); |
| 4245 | finishScreenTurningOn(screenOnListener); |
| 4246 | } |
| 4247 | })) { |
| 4248 | return; |
| 4249 | } |
| 4250 | } catch (RemoteException ex) { |
| 4251 | // Can't happen in system process. |
| 4252 | } |
| 4253 | } |
| 4254 | |
| 4255 | Slog.i(TAG, "No lock screen!"); |
| 4256 | finishScreenTurningOn(screenOnListener); |
| 4257 | } |
| 4258 | |
| 4259 | private void finishScreenTurningOn(ScreenOnListener screenOnListener) { |
| 4260 | synchronized (mLock) { |
| 4261 | mScreenOnFully = true; |
| 4262 | } |
| 4263 | |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 4264 | try { |
| 4265 | mWindowManager.setEventDispatching(true); |
| 4266 | } catch (RemoteException unhandled) { |
| 4267 | } |
| 4268 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4269 | if (screenOnListener != null) { |
| 4270 | screenOnListener.onScreenOn(); |
| 4271 | } |
| 4272 | } |
| 4273 | |
| 4274 | @Override |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4275 | public boolean isScreenOnEarly() { |
| 4276 | return mScreenOnEarly; |
| 4277 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4278 | |
| 4279 | @Override |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4280 | public boolean isScreenOnFully() { |
| 4281 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4282 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4283 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4284 | /** {@inheritDoc} */ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4285 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4286 | if (mKeyguardDelegate != null) { |
| 4287 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4288 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4289 | } |
| 4290 | |
| 4291 | /** {@inheritDoc} */ |
| 4292 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4293 | if (mKeyguardDelegate != null) { |
| 4294 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4295 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4296 | } |
| 4297 | |
Mike Lockwood | f791330 | 2009-11-28 22:27:10 -0500 | [diff] [blame] | 4298 | private boolean keyguardIsShowingTq() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4299 | if (mKeyguardDelegate == null) return false; |
| 4300 | return mKeyguardDelegate.isShowingAndNotHidden(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4301 | } |
| 4302 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4303 | |
| 4304 | /** {@inheritDoc} */ |
| 4305 | public boolean isKeyguardLocked() { |
| 4306 | return keyguardOn(); |
| 4307 | } |
| 4308 | |
| 4309 | /** {@inheritDoc} */ |
| 4310 | public boolean isKeyguardSecure() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4311 | if (mKeyguardDelegate == null) return false; |
| 4312 | return mKeyguardDelegate.isSecure(); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4313 | } |
| 4314 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4315 | /** {@inheritDoc} */ |
| 4316 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4317 | if (mKeyguardDelegate == null) return false; |
| 4318 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4319 | } |
| 4320 | |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4321 | public void dismissKeyguardLw() { |
Jim Miller | 195b551 | 2013-02-28 03:35:57 -0800 | [diff] [blame] | 4322 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4323 | mHandler.post(new Runnable() { |
| 4324 | public void run() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4325 | if (mKeyguardDelegate.isDismissable()) { |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4326 | // Can we just finish the keyguard straight away? |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4327 | mKeyguardDelegate.keyguardDone(false, true); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4328 | } else { |
| 4329 | // ask the keyguard to prompt the user to authenticate if necessary |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4330 | mKeyguardDelegate.dismiss(); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4331 | } |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4332 | } |
| 4333 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4334 | } |
| 4335 | } |
| 4336 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4337 | void sendCloseSystemWindows() { |
| 4338 | sendCloseSystemWindows(mContext, null); |
| 4339 | } |
| 4340 | |
| 4341 | void sendCloseSystemWindows(String reason) { |
| 4342 | sendCloseSystemWindows(mContext, reason); |
| 4343 | } |
| 4344 | |
| 4345 | static void sendCloseSystemWindows(Context context, String reason) { |
| 4346 | if (ActivityManagerNative.isSystemReady()) { |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 4347 | try { |
| 4348 | ActivityManagerNative.getDefault().closeSystemDialogs(reason); |
| 4349 | } catch (RemoteException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4350 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4351 | } |
| 4352 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 4353 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4354 | @Override |
| 4355 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4356 | if (false) { |
| 4357 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 4358 | + orientation + ", last=" + lastRotation |
| 4359 | + "); user=" + mUserRotation + " " |
| 4360 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 4361 | ? "USER_ROTATION_LOCKED" : "") |
| 4362 | ); |
| 4363 | } |
| 4364 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame^] | 4365 | if (mForceDefaultOrientation) { |
| 4366 | return Surface.ROTATION_0; |
| 4367 | } |
| 4368 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4369 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4370 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 4371 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 4372 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4373 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4374 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4375 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 4376 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4377 | // Ignore sensor when lid switch is open and rotation is forced. |
| 4378 | preferredRotation = mLidOpenRotation; |
| 4379 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4380 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4381 | // Ignore sensor when in car dock unless explicitly enabled. |
| 4382 | // This case can override the behavior of NOSENSOR, and can also |
| 4383 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4384 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4385 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 4386 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 4387 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 4388 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4389 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4390 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 4391 | // This case can override the behavior of NOSENSOR, and can also |
| 4392 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4393 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4394 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 4395 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 4396 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 4397 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 4398 | preferredRotation = mDemoHdmiRotation; |
| 4399 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 4400 | && mUndockedHdmiRotation >= 0) { |
| 4401 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 4402 | // been specified in the configuration (only for legacy devices without |
| 4403 | // full multi-display support). |
| 4404 | // Note that the dock orientation overrides the HDMI orientation. |
| 4405 | preferredRotation = mUndockedHdmiRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4406 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 4407 | // Application just wants to remain locked in the last rotation. |
| 4408 | preferredRotation = lastRotation; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 4409 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4410 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4411 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 4412 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 4413 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 4414 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4415 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 4416 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 4417 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 4418 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 4419 | // Otherwise, use sensor only if requested by the application or enabled |
| 4420 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 4421 | if (mAllowAllRotations < 0) { |
| 4422 | // Can't read this during init() because the context doesn't |
| 4423 | // have display metrics at that time so we cannot determine |
| 4424 | // tablet vs. phone then. |
| 4425 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 4426 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 4427 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4428 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 4429 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4430 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 4431 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4432 | preferredRotation = sensorRotation; |
| 4433 | } else { |
| 4434 | preferredRotation = lastRotation; |
| 4435 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 4436 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 4437 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 4438 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 4439 | // The idea is that the user rotation expresses a weak preference for the direction |
| 4440 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 4441 | // NOSENSOR be affected by rotation lock (although it will be affected by docks). |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 4442 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4443 | } else { |
| 4444 | // No overriding preference. |
| 4445 | // We will do exactly what the application asked us to do. |
| 4446 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4447 | } |
| 4448 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4449 | switch (orientation) { |
| 4450 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4451 | // Return portrait unless overridden. |
| 4452 | if (isAnyPortrait(preferredRotation)) { |
| 4453 | return preferredRotation; |
| 4454 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4455 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4456 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4457 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4458 | // Return landscape unless overridden. |
| 4459 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4460 | return preferredRotation; |
| 4461 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4462 | return mLandscapeRotation; |
| 4463 | |
| 4464 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4465 | // Return reverse portrait unless overridden. |
| 4466 | if (isAnyPortrait(preferredRotation)) { |
| 4467 | return preferredRotation; |
| 4468 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4469 | return mUpsideDownRotation; |
| 4470 | |
| 4471 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4472 | // Return seascape unless overridden. |
| 4473 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4474 | return preferredRotation; |
| 4475 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4476 | return mSeascapeRotation; |
| 4477 | |
| 4478 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4479 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4480 | // Return either landscape rotation. |
| 4481 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4482 | return preferredRotation; |
| 4483 | } |
| 4484 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 4485 | return lastRotation; |
| 4486 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4487 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4488 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4489 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4490 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4491 | // Return either portrait rotation. |
| 4492 | if (isAnyPortrait(preferredRotation)) { |
| 4493 | return preferredRotation; |
| 4494 | } |
| 4495 | if (isAnyPortrait(lastRotation)) { |
| 4496 | return lastRotation; |
| 4497 | } |
| 4498 | return mPortraitRotation; |
| 4499 | |
| 4500 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 4501 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 4502 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4503 | if (preferredRotation >= 0) { |
| 4504 | return preferredRotation; |
| 4505 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 4506 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 4507 | } |
| 4508 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 4509 | } |
| 4510 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4511 | @Override |
| 4512 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 4513 | switch (orientation) { |
| 4514 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 4515 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 4516 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 4517 | return isAnyPortrait(rotation); |
| 4518 | |
| 4519 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 4520 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 4521 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 4522 | return isLandscapeOrSeascape(rotation); |
| 4523 | |
| 4524 | default: |
| 4525 | return true; |
| 4526 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 4527 | } |
| 4528 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4529 | @Override |
| 4530 | public void setRotationLw(int rotation) { |
| 4531 | mOrientationListener.setCurrentRotation(rotation); |
| 4532 | } |
| 4533 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4534 | private boolean isLandscapeOrSeascape(int rotation) { |
| 4535 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4536 | } |
| 4537 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4538 | private boolean isAnyPortrait(int rotation) { |
| 4539 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4540 | } |
| 4541 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 4542 | public int getUserRotationMode() { |
| 4543 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 4544 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 4545 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 4546 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 4547 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4548 | |
| 4549 | // User rotation: to be used when all else fails in assigning an orientation to the device |
| 4550 | public void setUserRotationMode(int mode, int rot) { |
| 4551 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4552 | |
| 4553 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4554 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4555 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4556 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4557 | rot, |
| 4558 | UserHandle.USER_CURRENT); |
| 4559 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4560 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4561 | 0, |
| 4562 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4563 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4564 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4565 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4566 | 1, |
| 4567 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4568 | } |
| 4569 | } |
| 4570 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 4571 | public void setSafeMode(boolean safeMode) { |
| 4572 | mSafeMode = safeMode; |
| 4573 | performHapticFeedbackLw(null, safeMode |
| 4574 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 4575 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4576 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4577 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 4578 | static long[] getLongIntArray(Resources r, int resid) { |
| 4579 | int[] ar = r.getIntArray(resid); |
| 4580 | if (ar == null) { |
| 4581 | return null; |
| 4582 | } |
| 4583 | long[] out = new long[ar.length]; |
| 4584 | for (int i=0; i<ar.length; i++) { |
| 4585 | out[i] = ar[i]; |
| 4586 | } |
| 4587 | return out; |
| 4588 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4589 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4590 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4591 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4592 | public void systemReady() { |
Jim Miller | 195b551 | 2013-02-28 03:35:57 -0800 | [diff] [blame] | 4593 | if (!mHeadless) { |
| 4594 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4595 | mKeyguardDelegate.onSystemReady(); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4596 | } |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 4597 | synchronized (mLock) { |
| 4598 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 4599 | mSystemReady = true; |
| 4600 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4601 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 4602 | public void run() { |
| 4603 | updateSettings(); |
| 4604 | } |
| 4605 | }); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4606 | } |
| 4607 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4608 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 4609 | /** {@inheritDoc} */ |
| 4610 | public void systemBooted() { |
| 4611 | synchronized (mLock) { |
| 4612 | mSystemBooted = true; |
| 4613 | } |
| 4614 | } |
| 4615 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4616 | ProgressDialog mBootMsgDialog = null; |
| 4617 | |
| 4618 | /** {@inheritDoc} */ |
| 4619 | public void showBootMessage(final CharSequence msg, final boolean always) { |
Mike Lockwood | aa5bf14 | 2011-09-21 13:03:40 -0400 | [diff] [blame] | 4620 | if (mHeadless) return; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4621 | mHandler.post(new Runnable() { |
| 4622 | @Override public void run() { |
| 4623 | if (mBootMsgDialog == null) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 4624 | mBootMsgDialog = new ProgressDialog(mContext) { |
| 4625 | // This dialog will consume all events coming in to |
| 4626 | // it, to avoid it trying to do things too early in boot. |
| 4627 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 4628 | return true; |
| 4629 | } |
| 4630 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 4631 | return true; |
| 4632 | } |
| 4633 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 4634 | return true; |
| 4635 | } |
| 4636 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 4637 | return true; |
| 4638 | } |
| 4639 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 4640 | return true; |
| 4641 | } |
| 4642 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 4643 | AccessibilityEvent event) { |
| 4644 | return true; |
| 4645 | } |
| 4646 | }; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4647 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 4648 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 4649 | mBootMsgDialog.setIndeterminate(true); |
| 4650 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4651 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4652 | mBootMsgDialog.getWindow().addFlags( |
| 4653 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 4654 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 4655 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 4656 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 4657 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 4658 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4659 | mBootMsgDialog.setCancelable(false); |
| 4660 | mBootMsgDialog.show(); |
| 4661 | } |
| 4662 | mBootMsgDialog.setMessage(msg); |
| 4663 | } |
| 4664 | }); |
| 4665 | } |
| 4666 | |
| 4667 | /** {@inheritDoc} */ |
| 4668 | public void hideBootMessages() { |
| 4669 | mHandler.post(new Runnable() { |
| 4670 | @Override public void run() { |
| 4671 | if (mBootMsgDialog != null) { |
| 4672 | mBootMsgDialog.dismiss(); |
| 4673 | mBootMsgDialog = null; |
| 4674 | } |
| 4675 | } |
| 4676 | }); |
| 4677 | } |
| 4678 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4679 | /** {@inheritDoc} */ |
| 4680 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4681 | // *************************************** |
| 4682 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 4683 | // *************************************** |
| 4684 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 4685 | // WITH ITS LOCKS HELD. |
| 4686 | // |
| 4687 | // This code must be VERY careful about the locks |
| 4688 | // it acquires. |
| 4689 | // In fact, the current code acquires way too many, |
| 4690 | // and probably has lurking deadlocks. |
| 4691 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4692 | synchronized (mScreenLockTimeout) { |
| 4693 | if (mLockScreenTimerActive) { |
| 4694 | // reset the timer |
| 4695 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 4696 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 4697 | } |
| 4698 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 4699 | } |
| 4700 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4701 | class ScreenLockTimeout implements Runnable { |
| 4702 | Bundle options; |
| 4703 | |
| 4704 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4705 | public void run() { |
| 4706 | synchronized (this) { |
| 4707 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4708 | if (mKeyguardDelegate != null) { |
| 4709 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4710 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4711 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4712 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4713 | } |
| 4714 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4715 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4716 | public void setLockOptions(Bundle options) { |
| 4717 | this.options = options; |
| 4718 | } |
| 4719 | } |
| 4720 | |
| 4721 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 4722 | |
| 4723 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 4724 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 4725 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4726 | if (options != null) { |
| 4727 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 4728 | // until the runnable actually executes. |
| 4729 | mScreenLockTimeout.setLockOptions(options); |
| 4730 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 4731 | mHandler.post(mScreenLockTimeout); |
| 4732 | } |
| 4733 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4734 | private void updateLockScreenTimeout() { |
| 4735 | synchronized (mScreenLockTimeout) { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4736 | boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly && |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4737 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4738 | if (mLockScreenTimerActive != enable) { |
| 4739 | if (enable) { |
| 4740 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
| 4741 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 4742 | } else { |
| 4743 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 4744 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 4745 | } |
| 4746 | mLockScreenTimerActive = enable; |
| 4747 | } |
| 4748 | } |
| 4749 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4750 | |
| 4751 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4752 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4753 | public void enableScreenAfterBoot() { |
| 4754 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4755 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4756 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4757 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 4758 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4759 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4760 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
| 4761 | mPowerManager.goToSleep(SystemClock.uptimeMillis()); |
| 4762 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4763 | } |
| 4764 | |
| 4765 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4766 | try { |
| 4767 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4768 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 4769 | } catch (RemoteException e) { |
| 4770 | // Ignore |
| 4771 | } |
| 4772 | } |
| 4773 | |
| 4774 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 4775 | try { |
| 4776 | //set orientation on WindowManager |
| 4777 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4778 | } catch (RemoteException e) { |
| 4779 | // Ignore |
| 4780 | } |
| 4781 | } |
| 4782 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4783 | /** |
| 4784 | * Return an Intent to launch the currently active dock app as home. Returns |
| 4785 | * null if the standard home should be launched, which is the case if any of the following is |
| 4786 | * true: |
| 4787 | * <ul> |
| 4788 | * <li>The device is not in either car mode or desk mode |
| 4789 | * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false |
| 4790 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 4791 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 4792 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 4793 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4794 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4795 | */ |
| 4796 | Intent createHomeDockIntent() { |
| 4797 | Intent intent = null; |
| 4798 | |
| 4799 | // What home does is based on the mode, not the dock state. That |
| 4800 | // is, when in car mode you should be taken to car home regardless |
| 4801 | // of whether we are actually in a car dock. |
| 4802 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
| 4803 | if (ENABLE_CAR_DOCK_HOME_CAPTURE) { |
| 4804 | intent = mCarDockIntent; |
| 4805 | } |
| 4806 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 4807 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 4808 | intent = mDeskDockIntent; |
| 4809 | } |
| 4810 | } |
| 4811 | |
| 4812 | if (intent == null) { |
| 4813 | return null; |
| 4814 | } |
| 4815 | |
| 4816 | ActivityInfo ai = null; |
| 4817 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 4818 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 4819 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
| 4820 | getCurrentUserId()); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4821 | if (info != null) { |
| 4822 | ai = info.activityInfo; |
| 4823 | } |
| 4824 | if (ai != null |
| 4825 | && ai.metaData != null |
| 4826 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 4827 | intent = new Intent(intent); |
| 4828 | intent.setClassName(ai.packageName, ai.name); |
| 4829 | return intent; |
| 4830 | } |
| 4831 | |
| 4832 | return null; |
| 4833 | } |
| 4834 | |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 4835 | private int getCurrentUserId() { |
| 4836 | try { |
| 4837 | UserInfo user = ActivityManagerNative.getDefault().getCurrentUser(); |
| 4838 | return user != null ? user.id : UserHandle.USER_NULL; |
| 4839 | } catch (RemoteException e) { |
| 4840 | // noop |
| 4841 | } |
| 4842 | return UserHandle.USER_NULL; |
| 4843 | } |
| 4844 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4845 | void startDockOrHome() { |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 4846 | awakenDreams(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4847 | |
| 4848 | Intent dock = createHomeDockIntent(); |
| 4849 | if (dock != null) { |
| 4850 | try { |
| 4851 | mContext.startActivityAsUser(dock, UserHandle.CURRENT); |
| 4852 | return; |
| 4853 | } catch (ActivityNotFoundException e) { |
| 4854 | } |
| 4855 | } |
| 4856 | |
Dianne Hackborn | d888399 | 2012-09-07 15:58:52 -0700 | [diff] [blame] | 4857 | mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4858 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4859 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4860 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4861 | * goes to the home screen |
| 4862 | * @return whether it did anything |
| 4863 | */ |
| 4864 | boolean goHome() { |
| 4865 | if (false) { |
| 4866 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 4867 | try { |
| 4868 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 4869 | } catch (RemoteException e) { |
| 4870 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 4871 | sendCloseSystemWindows(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4872 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4873 | } else { |
| 4874 | // This code brings home to the front or, if it is already |
| 4875 | // at the front, puts the device to sleep. |
| 4876 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 4877 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 4878 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 4879 | Log.d(TAG, "UTS-TEST-MODE"); |
| 4880 | } else { |
| 4881 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 4882 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4883 | Intent dock = createHomeDockIntent(); |
| 4884 | if (dock != null) { |
| 4885 | int result = ActivityManagerNative.getDefault() |
| 4886 | .startActivityAsUser(null, null, dock, |
| 4887 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 4888 | null, null, 0, |
| 4889 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
| 4890 | null, null, null, UserHandle.USER_CURRENT); |
| 4891 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 4892 | return false; |
| 4893 | } |
| 4894 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4895 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4896 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 4897 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4898 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4899 | null, null, 0, |
| 4900 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Dianne Hackborn | 5e03e2c | 2012-09-06 14:21:19 -0700 | [diff] [blame] | 4901 | null, null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 4902 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4903 | return false; |
| 4904 | } |
| 4905 | } catch (RemoteException ex) { |
| 4906 | // bummer, the activity manager, which is in this process, is dead |
| 4907 | } |
| 4908 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4909 | return true; |
| 4910 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4911 | |
| 4912 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4913 | public void setCurrentOrientationLw(int newOrientation) { |
| 4914 | synchronized (mLock) { |
| 4915 | if (newOrientation != mCurrentAppOrientation) { |
| 4916 | mCurrentAppOrientation = newOrientation; |
| 4917 | updateOrientationListenerLp(); |
| 4918 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4919 | } |
| 4920 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4921 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 4922 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 4923 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 4924 | return; |
| 4925 | } |
| 4926 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 4927 | Context.AUDIO_SERVICE); |
| 4928 | if (audioManager.isSilentMode()) { |
| 4929 | return; |
| 4930 | } |
| 4931 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 4932 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 4933 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 4934 | ringTone.play(); |
| 4935 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4936 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 4937 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 4938 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 4939 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 4940 | } |
| 4941 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4942 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4943 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 4944 | if (!mVibrator.hasVibrator()) { |
| 4945 | return false; |
| 4946 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4947 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 4948 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4949 | if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotHidden())) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4950 | return false; |
| 4951 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4952 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4953 | switch (effectId) { |
| 4954 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4955 | pattern = mLongPressVibePattern; |
| 4956 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 4957 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4958 | pattern = mVirtualKeyVibePattern; |
| 4959 | break; |
| 4960 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 4961 | pattern = mKeyboardTapVibePattern; |
| 4962 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 4963 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4964 | pattern = mSafeModeDisabledVibePattern; |
| 4965 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 4966 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4967 | pattern = mSafeModeEnabledVibePattern; |
| 4968 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4969 | default: |
| 4970 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4971 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 4972 | int owningUid; |
| 4973 | String owningPackage; |
| 4974 | if (win != null) { |
| 4975 | owningUid = win.getOwningUid(); |
| 4976 | owningPackage = win.getOwningPackage(); |
| 4977 | } else { |
| 4978 | owningUid = android.os.Process.myUid(); |
| 4979 | owningPackage = mContext.getBasePackageName(); |
| 4980 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4981 | if (pattern.length == 1) { |
| 4982 | // One-shot vibration |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 4983 | mVibrator.vibrate(owningUid, owningPackage, pattern[0]); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4984 | } else { |
| 4985 | // Pattern vibration |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 4986 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 4987 | } |
| 4988 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4989 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4990 | |
| 4991 | @Override |
| 4992 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 4993 | } |
| 4994 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4995 | @Override |
| 4996 | public void keepScreenOnStoppedLw() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4997 | if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotHidden()) { |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4998 | long curTime = SystemClock.uptimeMillis(); |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 4999 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5000 | } |
| 5001 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 5002 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5003 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5004 | // If there is no window focused, there will be nobody to handle the events |
| 5005 | // 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] | 5006 | if (mFocusedWindow == null) { |
| 5007 | return 0; |
| 5008 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5009 | if (mFocusedWindow.getAttrs().type == TYPE_KEYGUARD && mHideLockScreen == true) { |
| 5010 | // We are updating at a point where the keyguard has gotten |
| 5011 | // focus, but we were last in a state where the top window is |
| 5012 | // hiding it. This is probably because the keyguard as been |
| 5013 | // shown while the top window was displayed, so we want to ignore |
| 5014 | // it here because this is just a very transient change and it |
| 5015 | // will quickly lose focus once it correctly gets hidden. |
| 5016 | return 0; |
| 5017 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5018 | |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5019 | int tmpVisibility = mFocusedWindow.getSystemUiVisibility() |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5020 | & ~mResettingSystemUiFlags |
| 5021 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5022 | if (mForcingShowNavBar && mFocusedWindow.getSurfaceLayer() < mForcingShowNavBarLayer) { |
| 5023 | tmpVisibility &= ~View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 5024 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5025 | final int visibility = updateHideybarsLw(tmpVisibility); |
| 5026 | final int diff = visibility ^ mLastSystemUiFlags; |
Dianne Hackborn | 73ab6a4 | 2011-12-13 11:16:23 -0800 | [diff] [blame] | 5027 | final boolean needsMenu = mFocusedWindow.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 5028 | if (diff == 0 && mLastFocusNeedsMenu == needsMenu |
| 5029 | && mFocusedApp == mFocusedWindow.getAppToken()) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5030 | return 0; |
| 5031 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5032 | mLastSystemUiFlags = visibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 5033 | mLastFocusNeedsMenu = needsMenu; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 5034 | mFocusedApp = mFocusedWindow.getAppToken(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5035 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5036 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5037 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 5038 | try { |
| 5039 | IStatusBarService statusbar = getStatusBarService(); |
| 5040 | if (statusbar != null) { |
| 5041 | statusbar.setSystemUiVisibility(visibility, 0xffffffff); |
| 5042 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5043 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 5044 | } catch (RemoteException e) { |
| 5045 | // re-acquire status bar service next time it is needed. |
| 5046 | mStatusBarService = null; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5047 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5048 | } |
| 5049 | }); |
| 5050 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5051 | } |
| 5052 | |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5053 | private int updateHideybarsLw(int tmpVisibility) { |
John Spurlock | 245fd01 | 2013-05-31 10:31:04 -0400 | [diff] [blame] | 5054 | if (OverlayTesting.enabled) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5055 | tmpVisibility = OverlayTesting.applyForced(mFocusedWindow, tmpVisibility); |
| 5056 | } |
| 5057 | boolean statusBarHasFocus = |
| 5058 | mFocusedWindow.getAttrs().type == TYPE_STATUS_BAR; |
| 5059 | if (statusBarHasFocus) { |
| 5060 | // prevent status bar interaction from clearing certain flags |
| 5061 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 5062 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
| 5063 | | View.SYSTEM_UI_FLAG_ALLOW_OVERLAY; |
| 5064 | tmpVisibility = (tmpVisibility & ~flags) | (mLastSystemUiFlags & flags); |
| 5065 | } |
| 5066 | boolean overlayAllowed = (tmpVisibility & View.SYSTEM_UI_FLAG_ALLOW_OVERLAY) != 0; |
| 5067 | if (mStatusHideybar == HIDEYBAR_SHOWING) { |
| 5068 | // status hideybar requested |
| 5069 | boolean hideStatusBarWM = |
| 5070 | (mFocusedWindow.getAttrs().flags |
| 5071 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
| 5072 | boolean hideStatusBarSysui = |
| 5073 | (tmpVisibility & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
| 5074 | |
| 5075 | boolean statusHideyAllowed = |
| 5076 | hideStatusBarWM |
| 5077 | || (hideStatusBarSysui && overlayAllowed) |
| 5078 | || statusBarHasFocus; |
| 5079 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5080 | if (mStatusBar == null || !statusHideyAllowed) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5081 | mStatusHideybar = HIDEYBAR_NONE; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 5082 | if (mStatusBar != null && hideStatusBarSysui) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5083 | // clear the clearable flags instead |
| 5084 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 5085 | if (newVal != mResettingSystemUiFlags) { |
| 5086 | mResettingSystemUiFlags = newVal; |
| 5087 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 5088 | } |
| 5089 | } |
| 5090 | } else { |
| 5091 | // show status hideybar |
| 5092 | tmpVisibility |= View.STATUS_BAR_OVERLAY; |
| 5093 | if ((mLastSystemUiFlags & View.STATUS_BAR_OVERLAY) == 0) { |
John Spurlock | d85618e | 2013-05-28 14:58:50 -0400 | [diff] [blame] | 5094 | tmpVisibility &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5095 | mStatusBar.showLw(true); |
| 5096 | } |
| 5097 | } |
| 5098 | } |
| 5099 | if (mNavigationHideybar == HIDEYBAR_SHOWING) { |
| 5100 | // navigation hideybar requested |
| 5101 | boolean hideNavigationBarSysui = |
| 5102 | (tmpVisibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
| 5103 | boolean navigationHideyAllowed = |
John Spurlock | e3b642e | 2013-05-09 15:51:32 -0400 | [diff] [blame] | 5104 | hideNavigationBarSysui && overlayAllowed && mNavigationBar != null; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5105 | if (!navigationHideyAllowed) { |
| 5106 | mNavigationHideybar = HIDEYBAR_NONE; |
| 5107 | } else { |
| 5108 | // show navigation hideybar |
| 5109 | tmpVisibility |= View.NAVIGATION_BAR_OVERLAY; |
| 5110 | if ((mLastSystemUiFlags & View.NAVIGATION_BAR_OVERLAY) == 0) { |
John Spurlock | d85618e | 2013-05-28 14:58:50 -0400 | [diff] [blame] | 5111 | tmpVisibility &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5112 | mNavigationBar.showLw(true); |
| 5113 | } |
| 5114 | } |
| 5115 | } |
| 5116 | return tmpVisibility; |
| 5117 | } |
| 5118 | |
| 5119 | // TODO temporary helper that allows testing overlay bars on existing apps |
| 5120 | private static final class OverlayTesting { |
John Spurlock | 245fd01 | 2013-05-31 10:31:04 -0400 | [diff] [blame] | 5121 | static String ENABLED_SETTING = "overlay_testing_enabled"; |
| 5122 | static boolean enabled = false; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5123 | private static final HashSet<String> sForced = new HashSet<String>(); |
| 5124 | |
| 5125 | private static String parseActivity(WindowState win) { |
| 5126 | if (win != null && win.getAppToken() != null) { |
| 5127 | String str = win.getAppToken().toString(); |
| 5128 | int end = str.lastIndexOf(' '); |
| 5129 | if (end > 0) { |
| 5130 | int start = str.lastIndexOf(' ', end - 1); |
| 5131 | if (start > -1) { |
| 5132 | return str.substring(start + 1, end); |
| 5133 | } |
| 5134 | } |
| 5135 | } |
| 5136 | return null; |
| 5137 | } |
| 5138 | |
| 5139 | public static int applyForced(WindowState focused, int vis) { |
| 5140 | if (sForced.contains(parseActivity(focused))) { |
| 5141 | vis |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 5142 | View.SYSTEM_UI_FLAG_FULLSCREEN | |
| 5143 | View.SYSTEM_UI_FLAG_ALLOW_OVERLAY; |
| 5144 | } |
| 5145 | return vis; |
| 5146 | } |
| 5147 | |
| 5148 | public static void toggleForceOverlay(WindowState focused, Context context) { |
| 5149 | String activity = parseActivity(focused); |
| 5150 | if (activity != null) { |
| 5151 | String action; |
| 5152 | if (sForced.contains(activity)) { |
| 5153 | sForced.remove(activity); |
| 5154 | action = "Force overlay disabled"; |
| 5155 | } else { |
| 5156 | sForced.add(activity); |
| 5157 | action = "Force overlay enabled"; |
| 5158 | } |
| 5159 | android.widget.Toast.makeText(context, |
| 5160 | action + " for " + activity, android.widget.Toast.LENGTH_SHORT).show(); |
| 5161 | } |
| 5162 | } |
| 5163 | } |
| 5164 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 5165 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 5166 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5167 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 5168 | public boolean hasNavigationBar() { |
| 5169 | return mHasNavigationBar; |
| 5170 | } |
| 5171 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5172 | @Override |
| 5173 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 5174 | mLastInputMethodWindow = ime; |
| 5175 | mLastInputMethodTargetWindow = target; |
| 5176 | } |
| 5177 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5178 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5179 | public void setCurrentUserLw(int newUserId) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5180 | if (mKeyguardDelegate != null) { |
| 5181 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5182 | } |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 5183 | if (mStatusBarService != null) { |
| 5184 | try { |
| 5185 | mStatusBarService.setCurrentUser(newUserId); |
| 5186 | } catch (RemoteException e) { |
| 5187 | // oh well |
| 5188 | } |
| 5189 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5190 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5191 | } |
| 5192 | |
| 5193 | @Override |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 5194 | public void showAssistant() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5195 | mKeyguardDelegate.showAssistant(); |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 5196 | } |
| 5197 | |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 5198 | @Override |
| 5199 | public boolean canMagnifyWindow(int windowType) { |
| 5200 | switch (windowType) { |
| 5201 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 5202 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 5203 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 5204 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 5205 | return false; |
| 5206 | } |
| 5207 | } |
| 5208 | return true; |
| 5209 | } |
| 5210 | |
| 5211 | @Override |
| 5212 | public boolean isTopLevelWindow(int windowType) { |
| 5213 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 5214 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 5215 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 5216 | } |
| 5217 | return true; |
| 5218 | } |
| 5219 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 5220 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 5221 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5222 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5223 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 5224 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 5225 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5226 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
| 5227 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5228 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 5229 | || mForceClearedSystemUiFlags != 0) { |
| 5230 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 5231 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 5232 | pw.print(" mResettingSystemUiFlags=0x"); |
| 5233 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 5234 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 5235 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5236 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 5237 | if (mLastFocusNeedsMenu) { |
| 5238 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 5239 | pw.println(mLastFocusNeedsMenu); |
| 5240 | } |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5241 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 5242 | pw.print(" mDockMode="); pw.print(mDockMode); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5243 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 5244 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 5245 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 5246 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5247 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5248 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5249 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 5250 | pw.print(mCarDockEnablesAccelerometer); |
| 5251 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 5252 | pw.println(mDeskDockEnablesAccelerometer); |
| 5253 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 5254 | pw.print(mLidKeyboardAccessibility); |
| 5255 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5256 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
| 5257 | pw.print(prefix); pw.print("mLongPressOnPowerBehavior="); |
| 5258 | pw.print(mLongPressOnPowerBehavior); |
| 5259 | pw.print(" mHasSoftInput="); pw.println(mHasSoftInput); |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 5260 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 5261 | pw.print(" mScreenOnFully="); pw.print(mScreenOnFully); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5262 | pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 5263 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 5264 | pw.print(","); pw.print(mOverscanScreenTop); |
| 5265 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 5266 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 5267 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 5268 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 5269 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 5270 | pw.print(" top="); pw.print(mOverscanTop); |
| 5271 | pw.print(" right="); pw.print(mOverscanRight); |
| 5272 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 5273 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 5274 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 5275 | pw.print(mRestrictedOverscanScreenLeft); |
| 5276 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 5277 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 5278 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5279 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 5280 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 5281 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 5282 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 5283 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 5284 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 5285 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 5286 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 5287 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 5288 | pw.print(","); pw.print(mStableFullscreenTop); |
| 5289 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 5290 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5291 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 5292 | pw.print(","); pw.print(mStableTop); |
| 5293 | pw.print(")-("); pw.print(mStableRight); |
| 5294 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 5295 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 5296 | pw.print(","); pw.print(mSystemTop); |
| 5297 | pw.print(")-("); pw.print(mSystemRight); |
| 5298 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5299 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 5300 | pw.print(","); pw.print(mCurTop); |
| 5301 | pw.print(")-("); pw.print(mCurRight); |
| 5302 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 5303 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 5304 | pw.print(","); pw.print(mContentTop); |
| 5305 | pw.print(")-("); pw.print(mContentRight); |
| 5306 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
| 5307 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 5308 | pw.print(","); pw.print(mDockTop); |
| 5309 | pw.print(")-("); pw.print(mDockRight); |
| 5310 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 5311 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 5312 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5313 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 5314 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
| 5315 | pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5316 | if (mLastInputMethodWindow != null) { |
| 5317 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 5318 | pw.println(mLastInputMethodWindow); |
| 5319 | } |
| 5320 | if (mLastInputMethodTargetWindow != null) { |
| 5321 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 5322 | pw.println(mLastInputMethodTargetWindow); |
| 5323 | } |
| 5324 | if (mStatusBar != null) { |
| 5325 | pw.print(prefix); pw.print("mStatusBar="); |
| 5326 | pw.println(mStatusBar); |
| 5327 | } |
| 5328 | if (mNavigationBar != null) { |
| 5329 | pw.print(prefix); pw.print("mNavigationBar="); |
| 5330 | pw.println(mNavigationBar); |
| 5331 | } |
| 5332 | if (mKeyguard != null) { |
| 5333 | pw.print(prefix); pw.print("mKeyguard="); |
| 5334 | pw.println(mKeyguard); |
| 5335 | } |
| 5336 | if (mFocusedWindow != null) { |
| 5337 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 5338 | pw.println(mFocusedWindow); |
| 5339 | } |
| 5340 | if (mFocusedApp != null) { |
| 5341 | pw.print(prefix); pw.print("mFocusedApp="); |
| 5342 | pw.println(mFocusedApp); |
| 5343 | } |
| 5344 | if (mWinDismissingKeyguard != null) { |
| 5345 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 5346 | pw.println(mWinDismissingKeyguard); |
| 5347 | } |
| 5348 | if (mTopFullscreenOpaqueWindowState != null) { |
| 5349 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 5350 | pw.println(mTopFullscreenOpaqueWindowState); |
| 5351 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5352 | if (mForcingShowNavBar) { |
| 5353 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 5354 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 5355 | pw.println(mForcingShowNavBarLayer); |
| 5356 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5357 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5358 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5359 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 5360 | pw.print(" mForceStatusBarFromKeyguard="); |
| 5361 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5362 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5363 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5364 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 5365 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 5366 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 5367 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 5368 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 5369 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 5370 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 5371 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 5372 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 5373 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 5374 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5375 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 5376 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 5377 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5378 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5379 | } |