The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2 | * |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | package com.android.internal.policy.impl; |
| 17 | |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 18 | import android.app.ActivityManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 19 | import android.app.ActivityManagerNative; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 20 | import android.app.AppOpsManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 21 | import android.app.IUiModeManager; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 22 | import android.app.ProgressDialog; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 23 | import android.app.SearchManager; |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 24 | import android.app.StatusBarManager; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 25 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 26 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 27 | import android.content.BroadcastReceiver; |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 28 | import android.content.ComponentName; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 29 | import android.content.ContentResolver; |
| 30 | import android.content.Context; |
| 31 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 32 | import android.content.IntentFilter; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 33 | import android.content.ServiceConnection; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 34 | import android.content.pm.ActivityInfo; |
| 35 | import android.content.pm.PackageManager; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 36 | import android.content.pm.ResolveInfo; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 37 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 38 | import android.content.res.Configuration; |
| 39 | import android.content.res.Resources; |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 40 | import android.content.res.TypedArray; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 41 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 42 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 43 | import android.graphics.Rect; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 44 | import android.media.AudioManager; |
Jean-Michel Trivi | fca1e60 | 2013-10-10 18:12:59 -0700 | [diff] [blame] | 45 | import android.media.AudioSystem; |
Michael Jurka | 7a34895 | 2012-02-27 13:07:58 -0800 | [diff] [blame] | 46 | import android.media.IAudioService; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 47 | import android.media.Ringtone; |
| 48 | import android.media.RingtoneManager; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 49 | import android.os.Bundle; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 50 | import android.os.FactoryTest; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 51 | import android.os.Handler; |
| 52 | import android.os.IBinder; |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 53 | import android.os.IRemoteCallback; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 54 | import android.os.Looper; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 55 | import android.os.Message; |
| 56 | import android.os.Messenger; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 57 | import android.os.PowerManager; |
| 58 | import android.os.RemoteException; |
| 59 | import android.os.ServiceManager; |
| 60 | import android.os.SystemClock; |
| 61 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 62 | import android.os.UEventObserver; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 63 | import android.os.UserHandle; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 64 | import android.os.Vibrator; |
| 65 | import android.provider.Settings; |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 66 | import android.service.dreams.DreamService; |
| 67 | import android.service.dreams.IDreamManager; |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 68 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 69 | import android.util.EventLog; |
| 70 | import android.util.Log; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 71 | import android.util.Slog; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 72 | import android.util.SparseArray; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 73 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 74 | import android.view.Gravity; |
| 75 | import android.view.HapticFeedbackConstants; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 76 | import android.view.IApplicationToken; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 77 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 78 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 79 | import android.view.InputDevice; |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 80 | import android.view.InputEvent; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 81 | import android.view.InputEventReceiver; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 82 | import android.view.KeyCharacterMap; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 83 | import android.view.KeyCharacterMap.FallbackAction; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 84 | import android.view.KeyEvent; |
| 85 | import android.view.MotionEvent; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 86 | import android.view.Surface; |
| 87 | import android.view.View; |
| 88 | import android.view.ViewConfiguration; |
| 89 | import android.view.Window; |
| 90 | import android.view.WindowManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 91 | import android.view.WindowManagerGlobal; |
| 92 | import android.view.WindowManagerPolicy; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 93 | import android.view.accessibility.AccessibilityEvent; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 94 | import android.view.accessibility.AccessibilityManager; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 95 | import android.view.animation.Animation; |
| 96 | import android.view.animation.AnimationUtils; |
| 97 | |
| 98 | import com.android.internal.R; |
| 99 | import com.android.internal.policy.PolicyManager; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 100 | import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 101 | import com.android.internal.statusbar.IStatusBarService; |
| 102 | import com.android.internal.telephony.ITelephony; |
| 103 | import com.android.internal.widget.PointerLocationView; |
| 104 | |
| 105 | import java.io.File; |
| 106 | import java.io.FileReader; |
| 107 | import java.io.IOException; |
| 108 | import java.io.PrintWriter; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame^] | 109 | import java.util.HashSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 110 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 111 | import static android.view.WindowManager.LayoutParams.*; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 112 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 113 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
| 114 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 115 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 116 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 117 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 118 | * introduces a new method suffix, Lp, for an internal lock of the |
| 119 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 120 | * 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] | 121 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 122 | */ |
| 123 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 124 | static final String TAG = "WindowManager"; |
| 125 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 126 | static final boolean localLOGV = false; |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 127 | static final boolean DEBUG_LAYOUT = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 128 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 129 | static final boolean DEBUG_STARTING_WINDOW = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 130 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 131 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 132 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 133 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 134 | // No longer recommended for desk docks; still useful in car docks. |
| 135 | static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true; |
| 136 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 137 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 138 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 139 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 140 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 141 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 142 | |
| 143 | // These need to match the documentation/constant in |
| 144 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 145 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 146 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 147 | static final int LONG_PRESS_HOME_ASSIST = 2; |
| 148 | |
| 149 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 150 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 151 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 152 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 153 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 154 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 155 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 156 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 157 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 158 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 159 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 160 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 161 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 162 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 163 | /** |
| 164 | * These are the system UI flags that, when changing, can cause the layout |
| 165 | * of the screen to change. |
| 166 | */ |
| 167 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 168 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 169 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 170 | | View.STATUS_BAR_TRANSLUCENT |
| 171 | | View.NAVIGATION_BAR_TRANSLUCENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 172 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 173 | /** |
| 174 | * Keyguard stuff |
| 175 | */ |
| 176 | private WindowState mKeyguardScrim; |
| 177 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 178 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 179 | * |
| 180 | * These are special keys that are used to launch particular kinds of applications, |
| 181 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 182 | * usage page. We don't support quite that many yet... |
| 183 | */ |
| 184 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 185 | static { |
| 186 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 187 | sApplicationLaunchKeyCategories.append( |
| 188 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 189 | sApplicationLaunchKeyCategories.append( |
| 190 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 191 | sApplicationLaunchKeyCategories.append( |
| 192 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 193 | sApplicationLaunchKeyCategories.append( |
| 194 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 195 | sApplicationLaunchKeyCategories.append( |
| 196 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 197 | sApplicationLaunchKeyCategories.append( |
| 198 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 199 | } |
| 200 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 201 | /** |
| 202 | * Lock protecting internal state. Must not call out into window |
| 203 | * manager with lock held. (This lock will be acquired in places |
| 204 | * where the window manager is calling in with its own lock held.) |
| 205 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 206 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 207 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 208 | Context mContext; |
| 209 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 210 | WindowManagerFuncs mWindowManagerFuncs; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 211 | PowerManager mPowerManager; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 212 | IStatusBarService mStatusBarService; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 213 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 214 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 215 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 216 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 217 | AccessibilityManager mAccessibilityManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 218 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 219 | // Vibrator pattern for haptic feedback of a long press. |
| 220 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 221 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 222 | // Vibrator pattern for haptic feedback of virtual key press. |
| 223 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 224 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 225 | // Vibrator pattern for a short vibration. |
| 226 | long[] mKeyboardTapVibePattern; |
| 227 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 228 | // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. |
| 229 | long[] mClockTickVibePattern; |
| 230 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 231 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 232 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 233 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 234 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 235 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 236 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 237 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 238 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 239 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 240 | boolean mSafeMode; |
| 241 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 242 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 243 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 244 | boolean mHasNavigationBar = false; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 245 | boolean mCanHideNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 246 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
| 247 | boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? |
| 248 | int[] mNavigationBarHeightForRotation = new int[4]; |
| 249 | int[] mNavigationBarWidthForRotation = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 250 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 251 | WindowState mKeyguard = null; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 252 | KeyguardServiceDelegate mKeyguardDelegate; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 253 | GlobalActions mGlobalActions; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 254 | volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread |
| 255 | boolean mPendingPowerKeyUpCanceled; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 256 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 257 | WindowState mLastInputMethodWindow = null; |
| 258 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 259 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 260 | static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0; |
| 261 | static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1; |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 262 | static final int RECENT_APPS_BEHAVIOR_DISMISS = 2; |
| 263 | static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 3; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 264 | |
| 265 | RecentApplicationsDialog mRecentAppsDialog; |
| 266 | int mRecentAppsDialogHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 267 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 268 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 269 | int mLidState = LID_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 270 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 271 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 272 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 273 | boolean mSystemBooted; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 274 | boolean mHdmiPlugged; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 275 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 276 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 277 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 278 | int mCarDockRotation; |
| 279 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 280 | int mUndockedHdmiRotation; |
| 281 | int mDemoHdmiRotation; |
| 282 | boolean mDemoHdmiRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 283 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 284 | // Default display does not rotate, apps that require non-default orientation will have to |
| 285 | // have the orientation emulated. |
| 286 | private boolean mForceDefaultOrientation = false; |
| 287 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 288 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 289 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 290 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 291 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 292 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 293 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 294 | boolean mCarDockEnablesAccelerometer; |
| 295 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 296 | int mLidKeyboardAccessibility; |
| 297 | int mLidNavigationAccessibility; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 298 | boolean mLidControlsSleep; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 299 | int mLongPressOnPowerBehavior = -1; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 300 | boolean mScreenOnEarly = false; |
| 301 | boolean mScreenOnFully = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 302 | boolean mOrientationSensorEnabled = false; |
| 303 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 304 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 305 | boolean mTranslucentDecorEnabled = true; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 306 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 307 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 308 | |
| 309 | // The last window we were told about in focusChanged. |
| 310 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 311 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 312 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 313 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 314 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 315 | // The current size of the screen; really; extends into the overscan area of |
| 316 | // the screen and doesn't account for any system elements like the status bar. |
| 317 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 318 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 319 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 320 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 321 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 322 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 323 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 324 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 325 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 326 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 327 | // if the status bar can't be hidden; in that case it effectively carves out |
| 328 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 329 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 330 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 331 | // During layout, the current screen borders accounting for any currently |
| 332 | // visible system UI elements. |
| 333 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 334 | // For applications requesting stable content insets, these are them. |
| 335 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 336 | // For applications requesting stable content insets but have also set the |
| 337 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 338 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 339 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 340 | // During layout, the current screen borders with all outer decoration |
| 341 | // (status bar, input method dock) accounted for. |
| 342 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 343 | // During layout, the frame in which content should be displayed |
| 344 | // to the user, accounting for all screen decoration except for any |
| 345 | // space they deem as available for other content. This is usually |
| 346 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 347 | // content insets. |
| 348 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 349 | // 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] | 350 | // windows are placed. |
| 351 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 352 | // During layout, the layer at which the doc window is placed. |
| 353 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 354 | // During layout, this is the layer of the status bar. |
| 355 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 356 | int mLastSystemUiFlags; |
| 357 | // Bits that we are in the process of clearing, so we want to prevent |
| 358 | // them from being set by applications until everything has been updated |
| 359 | // to have them clear. |
| 360 | int mResettingSystemUiFlags = 0; |
| 361 | // Bits that we are currently always keeping cleared. |
| 362 | int mForceClearedSystemUiFlags = 0; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 363 | // What we last reported to system UI about whether the compatibility |
| 364 | // menu needs to be displayed. |
| 365 | boolean mLastFocusNeedsMenu = false; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 366 | |
| 367 | FakeWindow mHideNavFakeWindow = null; |
| 368 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 369 | static final Rect mTmpParentFrame = new Rect(); |
| 370 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 371 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 372 | static final Rect mTmpContentFrame = new Rect(); |
| 373 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 374 | static final Rect mTmpDecorFrame = 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; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame^] | 378 | HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>(); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 379 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 380 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 381 | boolean mForceStatusBarFromKeyguard; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 382 | boolean mHideLockScreen; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 383 | boolean mForcingShowNavBar; |
| 384 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 385 | |
| 386 | // States of keyguard dismiss. |
| 387 | private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. |
| 388 | private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. |
| 389 | private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. |
| 390 | int mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
| 391 | |
| 392 | /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only |
| 393 | * be done once per window. */ |
| 394 | private WindowState mWinDismissingKeyguard; |
| 395 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 396 | boolean mShowingLockscreen; |
| 397 | boolean mShowingDream; |
| 398 | boolean mDreamingLockscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 399 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 400 | boolean mHomeConsumed; |
| 401 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 402 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 403 | Intent mCarDockIntent; |
| 404 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 405 | boolean mSearchKeyShortcutPending; |
| 406 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 407 | boolean mAssistKeyLongPressed; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 408 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 409 | // support for activating the lock screen while the screen is on |
| 410 | boolean mAllowLockscreenWhenOn; |
| 411 | int mLockScreenTimeout; |
| 412 | boolean mLockScreenTimerActive; |
| 413 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 414 | // 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] | 415 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 416 | |
| 417 | // Behavior of POWER button while in-call and screen on. |
| 418 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 419 | int mIncallPowerBehavior; |
| 420 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 421 | Display mDisplay; |
| 422 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 423 | int mLandscapeRotation = 0; // default landscape rotation |
| 424 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 425 | int mPortraitRotation = 0; // default portrait rotation |
| 426 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 427 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 428 | int mOverscanLeft = 0; |
| 429 | int mOverscanTop = 0; |
| 430 | int mOverscanRight = 0; |
| 431 | int mOverscanBottom = 0; |
| 432 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 433 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 434 | private int mLongPressOnHomeBehavior; |
| 435 | |
| 436 | // What we do when the user double-taps on home |
| 437 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 438 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 439 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 440 | // Time to volume and power must be pressed within this interval of each other. |
| 441 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 442 | // Increase the chord delay when taking a screenshot from the keyguard |
| 443 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 444 | private boolean mScreenshotChordEnabled; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 445 | private boolean mVolumeDownKeyTriggered; |
| 446 | private long mVolumeDownKeyTime; |
| 447 | private boolean mVolumeDownKeyConsumedByScreenshotChord; |
| 448 | private boolean mVolumeUpKeyTriggered; |
| 449 | private boolean mPowerKeyTriggered; |
| 450 | private long mPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 451 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 452 | /* The number of steps between min and max brightness */ |
| 453 | private static final int BRIGHTNESS_STEPS = 10; |
| 454 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 455 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 456 | ShortcutManager mShortcutManager; |
| 457 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 458 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 459 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 460 | private int mCurrentUserId; |
| 461 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 462 | // Maps global key codes to the components that will handle them. |
| 463 | private GlobalKeyManager mGlobalKeyManager; |
| 464 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 465 | // Fallback actions by key code. |
| 466 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 467 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 468 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 469 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 470 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 471 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 472 | 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] | 473 | |
| 474 | private class PolicyHandler extends Handler { |
| 475 | @Override |
| 476 | public void handleMessage(Message msg) { |
| 477 | switch (msg.what) { |
| 478 | case MSG_ENABLE_POINTER_LOCATION: |
| 479 | enablePointerLocation(); |
| 480 | break; |
| 481 | case MSG_DISABLE_POINTER_LOCATION: |
| 482 | disablePointerLocation(); |
| 483 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 484 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 485 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 486 | break; |
| 487 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 488 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 489 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | } |
| 493 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 494 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 495 | @Override |
| 496 | public void onUEvent(UEventObserver.UEvent event) { |
| 497 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 498 | } |
| 499 | }; |
| 500 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 501 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 502 | SettingsObserver(Handler handler) { |
| 503 | super(handler); |
| 504 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 505 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 506 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 507 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 508 | ContentResolver resolver = mContext.getContentResolver(); |
| 509 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 510 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 511 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 512 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 513 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 514 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 515 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 516 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 517 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 518 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 519 | Settings.System.USER_ROTATION), false, this, |
| 520 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 521 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 522 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 523 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 524 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 525 | Settings.System.POINTER_LOCATION), false, this, |
| 526 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 527 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 528 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 529 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 530 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 531 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 532 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 533 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 534 | Settings.Global.POLICY_CONTROL), false, this, |
| 535 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 536 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 540 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 541 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 542 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 543 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 544 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 545 | class MyOrientationListener extends WindowOrientationListener { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 546 | MyOrientationListener(Context context, Handler handler) { |
| 547 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 548 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 549 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 550 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 551 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 552 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 553 | updateRotation(false); |
| 554 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 555 | } |
| 556 | MyOrientationListener mOrientationListener; |
| 557 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 558 | private final BarController mStatusBarController = new BarController("StatusBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 559 | View.STATUS_BAR_TRANSIENT, |
| 560 | View.STATUS_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 561 | View.STATUS_BAR_TRANSLUCENT, |
| 562 | StatusBarManager.WINDOW_STATUS_BAR, |
| 563 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 564 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 565 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 566 | View.NAVIGATION_BAR_TRANSIENT, |
| 567 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 568 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 569 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
| 570 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 571 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 572 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 573 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 574 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 575 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 576 | IStatusBarService getStatusBarService() { |
| 577 | synchronized (mServiceAquireLock) { |
| 578 | if (mStatusBarService == null) { |
| 579 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 580 | ServiceManager.getService("statusbar")); |
| 581 | } |
| 582 | return mStatusBarService; |
| 583 | } |
| 584 | } |
| 585 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 586 | /* |
| 587 | * We always let the sensor be switched on by default except when |
| 588 | * the user has explicitly disabled sensor based rotation or when the |
| 589 | * screen is switched off. |
| 590 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 591 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 592 | if (mSupportAutoRotation) { |
| 593 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 594 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 595 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 596 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 597 | // If the application has explicitly requested to follow the |
| 598 | // orientation, then we need to turn the sensor on. |
| 599 | return true; |
| 600 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 601 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 602 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 603 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 604 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 605 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 606 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 607 | // orientation management, |
| 608 | return true; |
| 609 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 610 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 611 | // If the setting for using the sensor by default is enabled, then |
| 612 | // we will always leave it on. Note that the user could go to |
| 613 | // a window that forces an orientation that does not use the |
| 614 | // sensor and in theory we could turn it off... however, when next |
| 615 | // turning it on we won't have a good value for the current |
| 616 | // orientation for a little bit, which can cause orientation |
| 617 | // changes to lag, so we'd like to keep it always on. (It will |
| 618 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 619 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 620 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 621 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 622 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 623 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 624 | /* |
| 625 | * Various use cases for invoking this function |
| 626 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 627 | * 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] | 628 | * if not already enabled |
| 629 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 630 | * already enabled |
| 631 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 632 | * screen turning on and current app has nosensor based orientation, do nothing |
| 633 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 634 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 635 | if (!mOrientationListener.canDetectOrientation()) { |
| 636 | // If sensor is turned off or nonexistent for some reason |
| 637 | return; |
| 638 | } |
| 639 | //Could have been invoked due to screen turning on or off or |
| 640 | //change of the currently visible window's orientation |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 641 | if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 642 | ", current orientation="+mCurrentAppOrientation+ |
| 643 | ", SensorEnabled="+mOrientationSensorEnabled); |
| 644 | boolean disable = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 645 | if (mScreenOnEarly) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 646 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 647 | disable = false; |
| 648 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 649 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 650 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 651 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 652 | mOrientationSensorEnabled = true; |
| 653 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 654 | } |
| 655 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 656 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 657 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 658 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 659 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 660 | mOrientationSensorEnabled = false; |
| 661 | } |
| 662 | } |
| 663 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 664 | private void interceptPowerKeyDown(boolean handled) { |
| 665 | mPowerKeyHandled = handled; |
| 666 | if (!handled) { |
| 667 | mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout()); |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | private boolean interceptPowerKeyUp(boolean canceled) { |
| 672 | if (!mPowerKeyHandled) { |
| 673 | mHandler.removeCallbacks(mPowerLongPress); |
| 674 | return !canceled; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 675 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 676 | return false; |
| 677 | } |
| 678 | |
| 679 | private void cancelPendingPowerKeyAction() { |
| 680 | if (!mPowerKeyHandled) { |
| 681 | mHandler.removeCallbacks(mPowerLongPress); |
| 682 | } |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 683 | if (mPowerKeyTriggered) { |
| 684 | mPendingPowerKeyUpCanceled = true; |
| 685 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 689 | if (mScreenshotChordEnabled |
| 690 | && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 691 | final long now = SystemClock.uptimeMillis(); |
| 692 | if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 693 | && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 694 | mVolumeDownKeyConsumedByScreenshotChord = true; |
| 695 | cancelPendingPowerKeyAction(); |
| 696 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 697 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 698 | } |
| 699 | } |
| 700 | } |
| 701 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 702 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 703 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 704 | // Double the time it takes to take a screenshot from the keyguard |
| 705 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
| 706 | ViewConfiguration.getGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 707 | } |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 708 | return ViewConfiguration.getGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 709 | } |
| 710 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 711 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 712 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | private final Runnable mPowerLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 716 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 717 | public void run() { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 718 | // The context isn't read |
| 719 | if (mLongPressOnPowerBehavior < 0) { |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 720 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 721 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 722 | } |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 723 | int resolvedBehavior = mLongPressOnPowerBehavior; |
| 724 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 725 | resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 726 | } |
| 727 | |
| 728 | switch (resolvedBehavior) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 729 | case LONG_PRESS_POWER_NOTHING: |
| 730 | break; |
| 731 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 732 | mPowerKeyHandled = true; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 733 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 734 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 735 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 736 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 737 | showGlobalActionsDialog(); |
| 738 | break; |
| 739 | case LONG_PRESS_POWER_SHUT_OFF: |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 740 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 741 | mPowerKeyHandled = true; |
| 742 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 743 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 744 | mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 745 | break; |
| 746 | } |
| 747 | } |
| 748 | }; |
| 749 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 750 | private final Runnable mScreenshotRunnable = new Runnable() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 751 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 752 | public void run() { |
| 753 | takeScreenshot(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 754 | } |
| 755 | }; |
| 756 | |
| 757 | void showGlobalActionsDialog() { |
| 758 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 759 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 760 | } |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 761 | final boolean keyguardShowing = keyguardIsShowingTq(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 762 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 763 | if (keyguardShowing) { |
| 764 | // since it took two seconds of long press to bring this up, |
| 765 | // 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] | 766 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 767 | } |
| 768 | } |
| 769 | |
| 770 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 771 | return Settings.Global.getInt( |
| 772 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 773 | } |
| 774 | |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 775 | private void handleLongPressOnHome() { |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 776 | if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 777 | mHomeConsumed = true; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 778 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 779 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 780 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { |
| 781 | toggleRecentApps(); |
| 782 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) { |
| 783 | launchAssistAction(); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 784 | } |
| 785 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 786 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 787 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 788 | private void handleDoubleTapOnHome() { |
| 789 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 790 | mHomeConsumed = true; |
| 791 | toggleRecentApps(); |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 796 | @Override |
| 797 | public void run() { |
| 798 | if (mHomeDoubleTapPending) { |
| 799 | mHomeDoubleTapPending = false; |
| 800 | launchHomeFromHotKey(); |
| 801 | } |
| 802 | } |
| 803 | }; |
| 804 | |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 805 | /** |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 806 | * Create (if necessary) and show or dismiss the recent apps dialog according |
| 807 | * according to the requested behavior. |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 808 | */ |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 809 | void showOrHideRecentAppsDialog(final int behavior) { |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 810 | mHandler.post(new Runnable() { |
| 811 | @Override |
| 812 | public void run() { |
| 813 | if (mRecentAppsDialog == null) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 814 | mRecentAppsDialog = new RecentApplicationsDialog(mContext); |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 815 | } |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 816 | if (mRecentAppsDialog.isShowing()) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 817 | switch (behavior) { |
| 818 | case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS: |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 819 | case RECENT_APPS_BEHAVIOR_DISMISS: |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 820 | mRecentAppsDialog.dismiss(); |
| 821 | break; |
| 822 | case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH: |
| 823 | mRecentAppsDialog.dismissAndSwitch(); |
| 824 | break; |
| 825 | case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW: |
| 826 | default: |
| 827 | break; |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 828 | } |
| 829 | } else { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 830 | switch (behavior) { |
| 831 | case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS: |
| 832 | mRecentAppsDialog.show(); |
| 833 | break; |
| 834 | case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW: |
| 835 | try { |
| 836 | mWindowManager.setInTouchMode(false); |
| 837 | } catch (RemoteException e) { |
| 838 | } |
| 839 | mRecentAppsDialog.show(); |
| 840 | break; |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 841 | case RECENT_APPS_BEHAVIOR_DISMISS: |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 842 | case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH: |
| 843 | default: |
| 844 | break; |
| 845 | } |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 846 | } |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 847 | } |
| 848 | }); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 849 | } |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 850 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 851 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 852 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 853 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 854 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 855 | mContext = context; |
| 856 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 857 | mWindowManagerFuncs = windowManagerFuncs; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 858 | mHandler = new PolicyHandler(); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 859 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 860 | try { |
| 861 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 862 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 863 | mSettingsObserver = new SettingsObserver(mHandler); |
| 864 | mSettingsObserver.observe(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 865 | mShortcutManager = new ShortcutManager(context, mHandler); |
| 866 | mShortcutManager.observe(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 867 | mUiMode = context.getResources().getInteger( |
| 868 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 869 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 870 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 871 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 872 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 873 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 874 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 875 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 876 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 877 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 878 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 879 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 880 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 881 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 882 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 883 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 884 | "PhoneWindowManager.mBroadcastWakeLock"); |
| 885 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 886 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 887 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 888 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 889 | com.android.internal.R.integer.config_lidOpenRotation); |
| 890 | mCarDockRotation = readRotation( |
| 891 | com.android.internal.R.integer.config_carDockRotation); |
| 892 | mDeskDockRotation = readRotation( |
| 893 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 894 | mUndockedHdmiRotation = readRotation( |
| 895 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 896 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 897 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 898 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 899 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 900 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 901 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 902 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 903 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 904 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 905 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 906 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 907 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 908 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 909 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 910 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 911 | Context.ACCESSIBILITY_SERVICE); |
| 912 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 913 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 914 | IntentFilter filter = new IntentFilter(); |
| 915 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 916 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 917 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 918 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 919 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 920 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 921 | if (intent != null) { |
| 922 | // Retrieve current sticky dock event broadcast. |
| 923 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 924 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 925 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 926 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 927 | // register for dream-related broadcasts |
| 928 | filter = new IntentFilter(); |
| 929 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 930 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 931 | context.registerReceiver(mDreamReceiver, filter); |
| 932 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 933 | // register for multiuser-relevant broadcasts |
| 934 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 935 | context.registerReceiver(mMultiuserReceiver, filter); |
| 936 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 937 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 938 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 939 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 940 | @Override |
| 941 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 942 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 943 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 944 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 945 | } |
| 946 | @Override |
| 947 | public void onSwipeFromBottom() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 948 | if (mNavigationBar != null && mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 949 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 950 | } |
| 951 | } |
| 952 | @Override |
| 953 | public void onSwipeFromRight() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 954 | if (mNavigationBar != null && !mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 955 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 956 | } |
| 957 | } |
| 958 | @Override |
| 959 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 960 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 961 | } |
| 962 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 963 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 964 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 965 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 966 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 967 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 968 | com.android.internal.R.array.config_longPressVibePattern); |
| 969 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 970 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 971 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 972 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 973 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 974 | com.android.internal.R.array.config_clockTickVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 975 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 976 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 977 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 978 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 979 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 980 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 981 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 982 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 983 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 984 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 985 | // Controls rotation and the like. |
| 986 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 987 | |
| 988 | // Match current screen state. |
| 989 | if (mPowerManager.isScreenOn()) { |
| 990 | screenTurningOn(null); |
| 991 | } else { |
| 992 | screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 993 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 994 | } |
| 995 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 996 | /** |
| 997 | * Read values from config.xml that may be overridden depending on |
| 998 | * the configuration of the device. |
| 999 | * eg. Disable long press on home goes to recents on sw600dp. |
| 1000 | */ |
| 1001 | private void readConfigurationDependentBehaviors() { |
| 1002 | mLongPressOnHomeBehavior = mContext.getResources().getInteger( |
| 1003 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 1004 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
| 1005 | mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) { |
| 1006 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1007 | } |
| 1008 | |
| 1009 | mDoubleTapOnHomeBehavior = mContext.getResources().getInteger( |
| 1010 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1011 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1012 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1013 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1014 | } |
| 1015 | } |
| 1016 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1017 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1018 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 1019 | // This method might be called before the policy has been fully initialized |
| 1020 | // or for other displays we don't care about. |
| 1021 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 1022 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1023 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1024 | mDisplay = display; |
| 1025 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1026 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1027 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1028 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1029 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1030 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1031 | mLandscapeRotation = Surface.ROTATION_0; |
| 1032 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1033 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1034 | mPortraitRotation = Surface.ROTATION_90; |
| 1035 | mUpsideDownRotation = Surface.ROTATION_270; |
| 1036 | } else { |
| 1037 | mPortraitRotation = Surface.ROTATION_270; |
| 1038 | mUpsideDownRotation = Surface.ROTATION_90; |
| 1039 | } |
| 1040 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1041 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1042 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1043 | mPortraitRotation = Surface.ROTATION_0; |
| 1044 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1045 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1046 | mLandscapeRotation = Surface.ROTATION_270; |
| 1047 | mSeascapeRotation = Surface.ROTATION_90; |
| 1048 | } else { |
| 1049 | mLandscapeRotation = Surface.ROTATION_90; |
| 1050 | mSeascapeRotation = Surface.ROTATION_270; |
| 1051 | } |
| 1052 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1053 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1054 | mStatusBarHeight = |
| 1055 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1056 | |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1057 | // Height of the navigation bar when presented horizontally at bottom |
| 1058 | mNavigationBarHeightForRotation[mPortraitRotation] = |
| 1059 | mNavigationBarHeightForRotation[mUpsideDownRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1060 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1061 | mNavigationBarHeightForRotation[mLandscapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1062 | mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize( |
| 1063 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1064 | |
| 1065 | // Width of the navigation bar when presented vertically along one side |
| 1066 | mNavigationBarWidthForRotation[mPortraitRotation] = |
| 1067 | mNavigationBarWidthForRotation[mUpsideDownRotation] = |
| 1068 | mNavigationBarWidthForRotation[mLandscapeRotation] = |
| 1069 | mNavigationBarWidthForRotation[mSeascapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1070 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1071 | |
| 1072 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1073 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1074 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1075 | |
Craig Mautner | d4ec3324 | 2013-07-22 10:37:43 -0700 | [diff] [blame] | 1076 | // Allow the navigation bar to move on small devices (phones). |
| 1077 | mNavigationBarCanMove = shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 1078 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1079 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1080 | // Allow a system property to override this. Used by the emulator. |
| 1081 | // See also hasNavigationBar(). |
| 1082 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 1083 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1084 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1085 | } else if ("0".equals(navBarOverride)) { |
| 1086 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1087 | } |
| 1088 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1089 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1090 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1091 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1092 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1093 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1094 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1095 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1096 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1097 | |
| 1098 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 1099 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 1100 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 1101 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 1102 | // For debug purposes the next line turns this feature off with: |
| 1103 | // $ adb shell setprop config.override_forced_orient true |
| 1104 | // $ adb shell wm size reset |
| 1105 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 1106 | } |
| 1107 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1108 | /** |
| 1109 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 1110 | * navigation bar and touch exploration is not enabled |
| 1111 | */ |
| 1112 | private boolean canHideNavigationBar() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1113 | return mHasNavigationBar |
| 1114 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1117 | @Override |
| 1118 | public boolean isDefaultOrientationForced() { |
| 1119 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1122 | @Override |
| 1123 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1124 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1125 | mOverscanLeft = left; |
| 1126 | mOverscanTop = top; |
| 1127 | mOverscanRight = right; |
| 1128 | mOverscanBottom = bottom; |
| 1129 | } |
| 1130 | } |
| 1131 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1132 | public void updateSettings() { |
| 1133 | ContentResolver resolver = mContext.getContentResolver(); |
| 1134 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1135 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1136 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1137 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1138 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1139 | UserHandle.USER_CURRENT); |
| 1140 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1141 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1142 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1143 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1144 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1145 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1146 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1147 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1148 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1149 | if (mUserRotation != userRotation) { |
| 1150 | mUserRotation = userRotation; |
| 1151 | updateRotation = true; |
| 1152 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1153 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1154 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1155 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1156 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1157 | if (mUserRotationMode != userRotationMode) { |
| 1158 | mUserRotationMode = userRotationMode; |
| 1159 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1160 | updateOrientationListenerLp(); |
| 1161 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1162 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1163 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1164 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1165 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1166 | if (mPointerLocationMode != pointerLocation) { |
| 1167 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1168 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1169 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1170 | } |
| 1171 | } |
| 1172 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1173 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1174 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1175 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1176 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1177 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1178 | if (mHasSoftInput != hasSoftInput) { |
| 1179 | mHasSoftInput = hasSoftInput; |
| 1180 | updateRotation = true; |
| 1181 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1182 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 1183 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1184 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 1185 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1186 | } |
| 1187 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1188 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1189 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | private void enablePointerLocation() { |
| 1193 | if (mPointerLocationView == null) { |
| 1194 | mPointerLocationView = new PointerLocationView(mContext); |
| 1195 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1196 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1197 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1198 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1199 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1200 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1201 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1202 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1203 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1204 | if (ActivityManager.isHighEndGfx()) { |
| 1205 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1206 | lp.privateFlags |= |
| 1207 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 1208 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1209 | lp.format = PixelFormat.TRANSLUCENT; |
| 1210 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1211 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1212 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1213 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1214 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1215 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1216 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1217 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1218 | |
| 1219 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1220 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1221 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
| 1222 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1223 | wm.removeView(mPointerLocationView); |
| 1224 | mPointerLocationView = null; |
| 1225 | } |
| 1226 | } |
| 1227 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1228 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1229 | try { |
| 1230 | int rotation = mContext.getResources().getInteger(resID); |
| 1231 | switch (rotation) { |
| 1232 | case 0: |
| 1233 | return Surface.ROTATION_0; |
| 1234 | case 90: |
| 1235 | return Surface.ROTATION_90; |
| 1236 | case 180: |
| 1237 | return Surface.ROTATION_180; |
| 1238 | case 270: |
| 1239 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1240 | } |
| 1241 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1242 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1243 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1244 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1248 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1249 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1250 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1251 | |
| 1252 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 1253 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1254 | if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW |
| 1255 | || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1256 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1257 | } |
| 1258 | String permission = null; |
| 1259 | switch (type) { |
| 1260 | case TYPE_TOAST: |
| 1261 | // XXX right now the app process has complete control over |
| 1262 | // this... should introduce a token to let the system |
| 1263 | // monitor/control what they are doing. |
| 1264 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 1265 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1266 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1267 | case TYPE_WALLPAPER: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1268 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1269 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1270 | break; |
| 1271 | case TYPE_PHONE: |
| 1272 | case TYPE_PRIORITY_PHONE: |
| 1273 | case TYPE_SYSTEM_ALERT: |
| 1274 | case TYPE_SYSTEM_ERROR: |
| 1275 | case TYPE_SYSTEM_OVERLAY: |
| 1276 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1277 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1278 | break; |
| 1279 | default: |
| 1280 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 1281 | } |
| 1282 | if (permission != null) { |
| 1283 | if (mContext.checkCallingOrSelfPermission(permission) |
| 1284 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1285 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1286 | } |
| 1287 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1288 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1289 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1290 | |
| 1291 | @Override |
| 1292 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 1293 | |
| 1294 | // If this switch statement is modified, modify the comment in the declarations of |
| 1295 | // the type in {@link WindowManager.LayoutParams} as well. |
| 1296 | switch (attrs.type) { |
| 1297 | default: |
| 1298 | // These are the windows that by default are shown only to the user that created |
| 1299 | // them. If this needs to be overridden, set |
| 1300 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 1301 | // {@link WindowManager.LayoutParams}. Note that permission |
| 1302 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 1303 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 1304 | return true; |
| 1305 | } |
| 1306 | break; |
| 1307 | |
| 1308 | // These are the windows that by default are shown to all users. However, to |
| 1309 | // protect against spoofing, check permissions below. |
| 1310 | case TYPE_APPLICATION_STARTING: |
| 1311 | case TYPE_BOOT_PROGRESS: |
| 1312 | case TYPE_DISPLAY_OVERLAY: |
| 1313 | case TYPE_HIDDEN_NAV_CONSUMER: |
| 1314 | case TYPE_KEYGUARD: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1315 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1316 | case TYPE_KEYGUARD_DIALOG: |
| 1317 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1318 | case TYPE_NAVIGATION_BAR: |
| 1319 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1320 | case TYPE_PHONE: |
| 1321 | case TYPE_POINTER: |
| 1322 | case TYPE_PRIORITY_PHONE: |
| 1323 | case TYPE_RECENTS_OVERLAY: |
| 1324 | case TYPE_SEARCH_BAR: |
| 1325 | case TYPE_STATUS_BAR: |
| 1326 | case TYPE_STATUS_BAR_PANEL: |
| 1327 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1328 | case TYPE_SYSTEM_DIALOG: |
| 1329 | case TYPE_UNIVERSE_BACKGROUND: |
| 1330 | case TYPE_VOLUME_OVERLAY: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1331 | case TYPE_PRIVATE_PRESENTATION: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1332 | break; |
| 1333 | } |
| 1334 | |
| 1335 | // Check if third party app has set window to system window type. |
| 1336 | return mContext.checkCallingOrSelfPermission( |
| 1337 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 1338 | != PackageManager.PERMISSION_GRANTED; |
| 1339 | } |
| 1340 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1341 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1342 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 1343 | switch (attrs.type) { |
| 1344 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1345 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1346 | // These types of windows can't receive input events. |
| 1347 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1348 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1349 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1350 | break; |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 1355 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1356 | } |
| 1357 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1358 | private boolean isHidden(int accessibilityMode) { |
| 1359 | switch (accessibilityMode) { |
| 1360 | case 1: |
| 1361 | return mLidState == LID_CLOSED; |
| 1362 | case 2: |
| 1363 | return mLidState == LID_OPEN; |
| 1364 | default: |
| 1365 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1366 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1367 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1368 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1369 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1370 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1371 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 1372 | int navigationPresence) { |
| 1373 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 1374 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1375 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1376 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1377 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1378 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1379 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 1380 | || (keyboardPresence == PRESENCE_INTERNAL |
| 1381 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1382 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1383 | if (!mHasSoftInput) { |
| 1384 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 1385 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1386 | } |
| 1387 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1388 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 1389 | || (navigationPresence == PRESENCE_INTERNAL |
| 1390 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1391 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1392 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1393 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1394 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1395 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1396 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1397 | public int windowTypeToLayerLw(int type) { |
| 1398 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1399 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1400 | } |
| 1401 | switch (type) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1402 | case TYPE_UNIVERSE_BACKGROUND: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1403 | return 1; |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1404 | case TYPE_PRIVATE_PRESENTATION: |
| 1405 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1406 | case TYPE_WALLPAPER: |
| 1407 | // wallpaper is at the bottom, though the window manager may move it. |
| 1408 | return 2; |
| 1409 | case TYPE_PHONE: |
| 1410 | return 3; |
| 1411 | case TYPE_SEARCH_BAR: |
| 1412 | return 4; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1413 | case TYPE_RECENTS_OVERLAY: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1414 | case TYPE_SYSTEM_DIALOG: |
| 1415 | return 5; |
| 1416 | case TYPE_TOAST: |
| 1417 | // toasts and the plugged-in battery thing |
| 1418 | return 6; |
| 1419 | case TYPE_PRIORITY_PHONE: |
| 1420 | // SIM errors and unlock. Not sure if this really should be in a high layer. |
| 1421 | return 7; |
| 1422 | case TYPE_DREAM: |
| 1423 | // used for Dreams (screensavers with TYPE_DREAM windows) |
| 1424 | return 8; |
| 1425 | case TYPE_SYSTEM_ALERT: |
| 1426 | // like the ANR / app crashed dialogs |
| 1427 | return 9; |
| 1428 | case TYPE_INPUT_METHOD: |
| 1429 | // on-screen keyboards and other such input method user interfaces go here. |
| 1430 | return 10; |
| 1431 | case TYPE_INPUT_METHOD_DIALOG: |
| 1432 | // on-screen keyboards and other such input method user interfaces go here. |
| 1433 | return 11; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1434 | case TYPE_KEYGUARD_SCRIM: |
| 1435 | // the safety window that shows behind keyguard while keyguard is starting |
| 1436 | return 12; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1437 | case TYPE_KEYGUARD: |
| 1438 | // the keyguard; nothing on top of these can take focus, since they are |
| 1439 | // responsible for power management when displayed. |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1440 | return 13; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1441 | case TYPE_KEYGUARD_DIALOG: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1442 | return 14; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1443 | case TYPE_STATUS_BAR_SUB_PANEL: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1444 | return 15; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1445 | case TYPE_STATUS_BAR: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1446 | return 16; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1447 | case TYPE_STATUS_BAR_PANEL: |
| 1448 | return 17; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1449 | case TYPE_VOLUME_OVERLAY: |
| 1450 | // the on-screen volume indicator and controller shown when the user |
| 1451 | // changes the device volume |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1452 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1453 | case TYPE_SYSTEM_OVERLAY: |
| 1454 | // the on-screen volume indicator and controller shown when the user |
| 1455 | // changes the device volume |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1456 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1457 | case TYPE_NAVIGATION_BAR: |
| 1458 | // the navigation bar, if available, shows atop most things |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1459 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1460 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1461 | // 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] | 1462 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1463 | case TYPE_SYSTEM_ERROR: |
| 1464 | // system-level error dialogs |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1465 | return 22; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1466 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1467 | // used to highlight the magnified portion of a display |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1468 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1469 | case TYPE_DISPLAY_OVERLAY: |
| 1470 | // used to simulate secondary display devices |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1471 | return 24; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1472 | case TYPE_DRAG: |
| 1473 | // the drag layer: input for drag-and-drop is associated with this window, |
| 1474 | // which sits above all other focusable windows |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1475 | return 25; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1476 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1477 | return 26; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1478 | case TYPE_BOOT_PROGRESS: |
| 1479 | return 27; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1480 | case TYPE_POINTER: |
| 1481 | // the (mouse) pointer layer |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1482 | return 28; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1483 | case TYPE_HIDDEN_NAV_CONSUMER: |
| 1484 | return 29; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1485 | } |
| 1486 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1487 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1491 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1492 | public int subWindowTypeToLayerLw(int type) { |
| 1493 | switch (type) { |
| 1494 | case TYPE_APPLICATION_PANEL: |
| 1495 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 1496 | return APPLICATION_PANEL_SUBLAYER; |
| 1497 | case TYPE_APPLICATION_MEDIA: |
| 1498 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 1499 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 1500 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1501 | case TYPE_APPLICATION_SUB_PANEL: |
| 1502 | return APPLICATION_SUB_PANEL_SUBLAYER; |
| 1503 | } |
| 1504 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 1505 | return 0; |
| 1506 | } |
| 1507 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1508 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1509 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1510 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1511 | } |
| 1512 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1513 | @Override |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1514 | public int getAboveUniverseLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1515 | return windowTypeToLayerLw(TYPE_SYSTEM_ERROR); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1518 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1519 | if (mHasNavigationBar) { |
| 1520 | // For a basic navigation bar, when we are in landscape mode we place |
| 1521 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1522 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
| 1523 | return fullWidth - mNavigationBarWidthForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1524 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1525 | } |
| 1526 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1527 | } |
| 1528 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1529 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1530 | if (mHasNavigationBar) { |
| 1531 | // For a basic navigation bar, when we are in portrait mode we place |
| 1532 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1533 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
| 1534 | return fullHeight - mNavigationBarHeightForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1535 | } |
| 1536 | } |
| 1537 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1540 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
| 1541 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1544 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1545 | // There is a separate status bar at the top of the display. We don't count that as part |
| 1546 | // 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] | 1547 | // we do want to exclude it since applications can't generally use that part |
| 1548 | // of the screen. |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1549 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1550 | } |
| 1551 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1552 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1553 | public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) { |
| 1554 | return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD; |
| 1555 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1556 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1557 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1558 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1559 | switch (attrs.type) { |
| 1560 | case TYPE_STATUS_BAR: |
| 1561 | case TYPE_NAVIGATION_BAR: |
| 1562 | case TYPE_WALLPAPER: |
| 1563 | case TYPE_DREAM: |
| 1564 | case TYPE_UNIVERSE_BACKGROUND: |
| 1565 | case TYPE_KEYGUARD: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1566 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1567 | return false; |
| 1568 | default: |
| 1569 | return true; |
| 1570 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1571 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1572 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1573 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1574 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1575 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 1576 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1577 | int icon, int logo, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1578 | if (!SHOW_STARTING_ANIMATIONS) { |
| 1579 | return null; |
| 1580 | } |
| 1581 | if (packageName == null) { |
| 1582 | return null; |
| 1583 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1584 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1585 | WindowManager wm = null; |
| 1586 | View view = null; |
| 1587 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1588 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1589 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1590 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 1591 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 1592 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1593 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1594 | try { |
| 1595 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1596 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1597 | } catch (PackageManager.NameNotFoundException e) { |
| 1598 | // Ignore |
| 1599 | } |
| 1600 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1601 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1602 | Window win = PolicyManager.makeNewWindow(context); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1603 | final TypedArray ta = win.getWindowStyle(); |
| 1604 | if (ta.getBoolean( |
| 1605 | com.android.internal.R.styleable.Window_windowDisablePreview, false) |
| 1606 | || ta.getBoolean( |
| 1607 | com.android.internal.R.styleable.Window_windowShowWallpaper,false)) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1608 | return null; |
| 1609 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1610 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1611 | Resources r = context.getResources(); |
| 1612 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1613 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1614 | win.setType( |
| 1615 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
| 1616 | // Force the window flags: this is a fake window, so it is not really |
| 1617 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 1618 | // flag because we do know that the next window will take input |
| 1619 | // focus, so we want to get the IME window up on top of us right away. |
| 1620 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1621 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1622 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 1623 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 1624 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1625 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1626 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 1627 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 1628 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1629 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1630 | win.setDefaultIcon(icon); |
| 1631 | win.setDefaultLogo(logo); |
| 1632 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1633 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1634 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1635 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1636 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 1637 | params.token = appToken; |
| 1638 | params.packageName = packageName; |
| 1639 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 1640 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 1641 | params.privateFlags |= |
| 1642 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1643 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1644 | |
| 1645 | if (!compatInfo.supportsScreen()) { |
| 1646 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 1647 | } |
| 1648 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1649 | params.setTitle("Starting " + packageName); |
| 1650 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1651 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 1652 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1653 | |
| 1654 | if (win.isFloating()) { |
| 1655 | // Whoops, there is no way to display an animation/preview |
| 1656 | // of such a thing! After all that work... let's skip it. |
| 1657 | // (Note that we must do this here because it is in |
| 1658 | // getDecorView() where the theme is evaluated... maybe |
| 1659 | // we should peek the floating attribute from the theme |
| 1660 | // earlier.) |
| 1661 | return null; |
| 1662 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1663 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1664 | if (DEBUG_STARTING_WINDOW) Slog.d( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1665 | TAG, "Adding starting window for " + packageName |
| 1666 | + " / " + appToken + ": " |
| 1667 | + (view.getParent() != null ? view : null)); |
| 1668 | |
| 1669 | wm.addView(view, params); |
| 1670 | |
| 1671 | // Only return the view if it was successfully added to the |
| 1672 | // window manager... which we can tell by it having a parent. |
| 1673 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1674 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1675 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 1676 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 1677 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1678 | } catch (RuntimeException e) { |
| 1679 | // don't crash if something else bad happens, for example a |
| 1680 | // failure loading resources because we are loading from an app |
| 1681 | // on external storage that has been unmounted. |
| 1682 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1683 | } finally { |
| 1684 | if (view != null && view.getParent() == null) { |
| 1685 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 1686 | wm.removeViewImmediate(view); |
| 1687 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | return null; |
| 1691 | } |
| 1692 | |
| 1693 | /** {@inheritDoc} */ |
| 1694 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1695 | if (DEBUG_STARTING_WINDOW) { |
| 1696 | RuntimeException e = new RuntimeException("here"); |
| 1697 | e.fillInStackTrace(); |
| 1698 | Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e); |
| 1699 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1700 | |
| 1701 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1702 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1703 | wm.removeView(window); |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | /** |
| 1708 | * Preflight adding a window to the system. |
| 1709 | * |
| 1710 | * Currently enforces that three window types are singletons: |
| 1711 | * <ul> |
| 1712 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1713 | * <li>KEYGUARD_TYPE</li> |
| 1714 | * </ul> |
| 1715 | * |
| 1716 | * @param win The window to be added |
| 1717 | * @param attrs Information about the window to be added |
| 1718 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1719 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 1720 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1721 | */ |
| 1722 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 1723 | switch (attrs.type) { |
| 1724 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 1725 | mContext.enforceCallingOrSelfPermission( |
| 1726 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1727 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1728 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1729 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1730 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1731 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1732 | } |
| 1733 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1734 | mStatusBarController.setWindow(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1735 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1736 | case TYPE_NAVIGATION_BAR: |
| 1737 | mContext.enforceCallingOrSelfPermission( |
| 1738 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1739 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1740 | if (mNavigationBar != null) { |
| 1741 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1742 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1743 | } |
| 1744 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1745 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1746 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1747 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1748 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 1749 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1750 | mContext.enforceCallingOrSelfPermission( |
| 1751 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1752 | "PhoneWindowManager"); |
| 1753 | break; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1754 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 1755 | mContext.enforceCallingOrSelfPermission( |
| 1756 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1757 | "PhoneWindowManager"); |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1758 | break; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1759 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1760 | mContext.enforceCallingOrSelfPermission( |
| 1761 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1762 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1763 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1764 | case TYPE_KEYGUARD: |
| 1765 | if (mKeyguard != null) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1766 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1767 | } |
| 1768 | mKeyguard = win; |
| 1769 | break; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1770 | case TYPE_KEYGUARD_SCRIM: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1771 | if (mKeyguardScrim != null) { |
| 1772 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 1773 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1774 | mKeyguardScrim = win; |
| 1775 | break; |
| 1776 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1777 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1778 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | /** {@inheritDoc} */ |
| 1782 | public void removeWindowLw(WindowState win) { |
| 1783 | if (mStatusBar == win) { |
| 1784 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1785 | mStatusBarController.setWindow(null); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1786 | } else if (mKeyguard == win) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1787 | Log.v(TAG, "Removing keyguard window (Did it crash?)"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1788 | mKeyguard = null; |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 1789 | mKeyguardDelegate.showScrim(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1790 | } else if (mKeyguardScrim == win) { |
| 1791 | Log.v(TAG, "Removing keyguard scrim"); |
| 1792 | mKeyguardScrim = null; |
| 1793 | } if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1794 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1795 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1796 | } |
| 1797 | } |
| 1798 | |
| 1799 | static final boolean PRINT_ANIM = false; |
| 1800 | |
| 1801 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1802 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1803 | public int selectAnimationLw(WindowState win, int transit) { |
| 1804 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 1805 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1806 | if (win == mStatusBar) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1807 | if (transit == TRANSIT_EXIT |
| 1808 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1809 | return R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1810 | } else if (transit == TRANSIT_ENTER |
| 1811 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1812 | return R.anim.dock_top_enter; |
| 1813 | } |
| 1814 | } else if (win == mNavigationBar) { |
| 1815 | // This can be on either the bottom or the right. |
| 1816 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1817 | if (transit == TRANSIT_EXIT |
| 1818 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1819 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1820 | } else if (transit == TRANSIT_ENTER |
| 1821 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1822 | return R.anim.dock_bottom_enter; |
| 1823 | } |
| 1824 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1825 | if (transit == TRANSIT_EXIT |
| 1826 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1827 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1828 | } else if (transit == TRANSIT_ENTER |
| 1829 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1830 | return R.anim.dock_right_enter; |
| 1831 | } |
| 1832 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1836 | if (win.hasAppShownWindows()) { |
| 1837 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 1838 | return com.android.internal.R.anim.app_starting_exit; |
| 1839 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 1840 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1841 | && transit == TRANSIT_ENTER) { |
| 1842 | // Special case: we are animating in a dream, while the keyguard |
| 1843 | // is shown. We don't want an animation on the dream, because |
| 1844 | // we need it shown immediately with the keyguard animating away |
| 1845 | // to reveal it. |
| 1846 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | return 0; |
| 1850 | } |
| 1851 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 1852 | @Override |
| 1853 | public void selectRotationAnimationLw(int anim[]) { |
| 1854 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 1855 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 1856 | + (mTopFullscreenOpaqueWindowState == null ? |
| 1857 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 1858 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 1859 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 1860 | case ROTATION_ANIMATION_CROSSFADE: |
| 1861 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 1862 | anim[1] = R.anim.rotation_animation_enter; |
| 1863 | break; |
| 1864 | case ROTATION_ANIMATION_JUMPCUT: |
| 1865 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 1866 | anim[1] = R.anim.rotation_animation_enter; |
| 1867 | break; |
| 1868 | case ROTATION_ANIMATION_ROTATE: |
| 1869 | default: |
| 1870 | anim[0] = anim[1] = 0; |
| 1871 | break; |
| 1872 | } |
| 1873 | } else { |
| 1874 | anim[0] = anim[1] = 0; |
| 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | @Override |
| 1879 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 1880 | boolean forceDefault) { |
| 1881 | switch (exitAnimId) { |
| 1882 | case R.anim.rotation_animation_xfade_exit: |
| 1883 | case R.anim.rotation_animation_jump_exit: |
| 1884 | // These are the only cases that matter. |
| 1885 | if (forceDefault) { |
| 1886 | return false; |
| 1887 | } |
| 1888 | int anim[] = new int[2]; |
| 1889 | selectRotationAnimationLw(anim); |
| 1890 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 1891 | default: |
| 1892 | return true; |
| 1893 | } |
| 1894 | } |
| 1895 | |
| 1896 | @Override |
Dianne Hackborn | 0c2acff | 2012-04-12 15:17:07 -0700 | [diff] [blame] | 1897 | public Animation createForceHideEnterAnimation(boolean onWallpaper) { |
| 1898 | return AnimationUtils.loadAnimation(mContext, onWallpaper |
| 1899 | ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter |
| 1900 | : com.android.internal.R.anim.lock_screen_behind_enter); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1901 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 1902 | |
| 1903 | private static void awakenDreams() { |
| 1904 | IDreamManager dreamManager = getDreamManager(); |
| 1905 | if (dreamManager != null) { |
| 1906 | try { |
| 1907 | dreamManager.awaken(); |
| 1908 | } catch (RemoteException e) { |
| 1909 | // fine, stay asleep then |
| 1910 | } |
| 1911 | } |
| 1912 | } |
| 1913 | |
| 1914 | static IDreamManager getDreamManager() { |
| 1915 | return IDreamManager.Stub.asInterface( |
| 1916 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 1917 | } |
| 1918 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1919 | static ITelephony getTelephonyService() { |
Mike Lockwood | f5f4ec9 | 2011-11-08 14:05:31 -0800 | [diff] [blame] | 1920 | return ITelephony.Stub.asInterface( |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1921 | ServiceManager.checkService(Context.TELEPHONY_SERVICE)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1922 | } |
| 1923 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1924 | static IAudioService getAudioService() { |
| 1925 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 1926 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 1927 | if (audioService == null) { |
| 1928 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 1929 | } |
| 1930 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | boolean keyguardOn() { |
| 1934 | return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode(); |
| 1935 | } |
| 1936 | |
| 1937 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 1938 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 1939 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 1940 | }; |
| 1941 | |
| 1942 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1943 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1944 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1945 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1946 | final int keyCode = event.getKeyCode(); |
| 1947 | final int repeatCount = event.getRepeatCount(); |
| 1948 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1949 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1950 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 1951 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1952 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 1953 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1954 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 1955 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 1956 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1957 | } |
| 1958 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1959 | // If we think we might have a volume down & power key chord on the way |
| 1960 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 1961 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1962 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1963 | if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) { |
| 1964 | final long now = SystemClock.uptimeMillis(); |
| 1965 | final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
| 1966 | if (now < timeoutTime) { |
| 1967 | return timeoutTime - now; |
| 1968 | } |
| 1969 | } |
| 1970 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 1971 | && mVolumeDownKeyConsumedByScreenshotChord) { |
| 1972 | if (!down) { |
| 1973 | mVolumeDownKeyConsumedByScreenshotChord = false; |
| 1974 | } |
| 1975 | return -1; |
| 1976 | } |
| 1977 | } |
| 1978 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1979 | // First we always handle the home key here, so applications |
| 1980 | // can never break it, although if keyguard is on, we do let |
| 1981 | // it handle it, because that gives us the correct 5 second |
| 1982 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1983 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1984 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1985 | // If we have released the home key, and didn't do anything else |
| 1986 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1987 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1988 | cancelPreloadRecentApps(); |
| 1989 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1990 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1991 | if (mHomeConsumed) { |
| 1992 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1993 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1994 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1995 | |
| 1996 | if (canceled) { |
| 1997 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 1998 | return -1; |
| 1999 | } |
| 2000 | |
| 2001 | // If an incoming call is ringing, HOME is totally disabled. |
| 2002 | // (The user is already on the InCallScreen at this point, |
| 2003 | // and his ONLY options are to answer or reject the call.) |
| 2004 | try { |
| 2005 | ITelephony telephonyService = getTelephonyService(); |
| 2006 | if (telephonyService != null && telephonyService.isRinging()) { |
| 2007 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 2008 | return -1; |
| 2009 | } |
| 2010 | } catch (RemoteException ex) { |
| 2011 | Log.w(TAG, "RemoteException from getPhoneInterface()", ex); |
| 2012 | } |
| 2013 | |
| 2014 | // Delay handling home if a double-tap is possible. |
| 2015 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 2016 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 2017 | mHomeDoubleTapPending = true; |
| 2018 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 2019 | ViewConfiguration.getDoubleTapTimeout()); |
| 2020 | return -1; |
| 2021 | } |
| 2022 | |
| 2023 | // Go home! |
| 2024 | launchHomeFromHotKey(); |
| 2025 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2026 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2027 | |
| 2028 | // If a system window has focus, then it doesn't make sense |
| 2029 | // right now to interact with applications. |
| 2030 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 2031 | if (attrs != null) { |
| 2032 | final int type = attrs.type; |
| 2033 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2034 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2035 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) { |
| 2036 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2037 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2038 | } |
| 2039 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 2040 | for (int i=0; i<typeCount; i++) { |
| 2041 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 2042 | // 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] | 2043 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2044 | } |
| 2045 | } |
| 2046 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2047 | |
| 2048 | // Remember that home is pressed and handle special actions. |
| 2049 | if (repeatCount == 0) { |
| 2050 | mHomePressed = true; |
| 2051 | if (mHomeDoubleTapPending) { |
| 2052 | mHomeDoubleTapPending = false; |
| 2053 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 2054 | handleDoubleTapOnHome(); |
| 2055 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 2056 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2057 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2058 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2059 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 2060 | if (!keyguardOn) { |
| 2061 | handleLongPressOnHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2062 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2063 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2064 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2065 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2066 | // Hijack modified menu keys for debugging features |
| 2067 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 2068 | |
| 2069 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2070 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2071 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2072 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 2073 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2074 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2075 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2076 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2077 | Intent service = new Intent(); |
| 2078 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 2079 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2080 | boolean shown = Settings.Global.getInt( |
| 2081 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2082 | if (!shown) { |
| 2083 | mContext.startService(service); |
| 2084 | } else { |
| 2085 | mContext.stopService(service); |
| 2086 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2087 | Settings.Global.putInt( |
| 2088 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2089 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2090 | } |
| 2091 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2092 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2093 | if (down) { |
| 2094 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2095 | mSearchKeyShortcutPending = true; |
| 2096 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2097 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2098 | } else { |
| 2099 | mSearchKeyShortcutPending = false; |
| 2100 | if (mConsumeSearchKeyUp) { |
| 2101 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2102 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2103 | } |
| 2104 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2105 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2106 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2107 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2108 | if (down && repeatCount == 0) { |
| 2109 | preloadRecentApps(); |
| 2110 | } else if (!down) { |
| 2111 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2112 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2113 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2114 | return -1; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2115 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 2116 | if (down) { |
| 2117 | if (repeatCount == 0) { |
| 2118 | mAssistKeyLongPressed = false; |
| 2119 | } else if (repeatCount == 1) { |
| 2120 | mAssistKeyLongPressed = true; |
| 2121 | if (!keyguardOn) { |
| 2122 | launchAssistLongPressAction(); |
| 2123 | } |
| 2124 | } |
| 2125 | } else { |
| 2126 | if (mAssistKeyLongPressed) { |
| 2127 | mAssistKeyLongPressed = false; |
| 2128 | } else { |
| 2129 | if (!keyguardOn) { |
| 2130 | launchAssistAction(); |
| 2131 | } |
| 2132 | } |
| 2133 | } |
| 2134 | return -1; |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 2135 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 2136 | if (down && repeatCount == 0) { |
| 2137 | mHandler.post(mScreenshotRunnable); |
| 2138 | } |
| 2139 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2140 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 2141 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 2142 | if (down) { |
| 2143 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 2144 | |
| 2145 | // Disable autobrightness if it's on |
| 2146 | int auto = Settings.System.getIntForUser( |
| 2147 | mContext.getContentResolver(), |
| 2148 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2149 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2150 | UserHandle.USER_CURRENT_OR_SELF); |
| 2151 | if (auto != 0) { |
| 2152 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2153 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2154 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2155 | UserHandle.USER_CURRENT_OR_SELF); |
| 2156 | } |
| 2157 | |
| 2158 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 2159 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 2160 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 2161 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 2162 | Settings.System.SCREEN_BRIGHTNESS, |
| 2163 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 2164 | UserHandle.USER_CURRENT_OR_SELF); |
| 2165 | brightness += step; |
| 2166 | // Make sure we don't go beyond the limits. |
| 2167 | brightness = Math.min(max, brightness); |
| 2168 | brightness = Math.max(min, brightness); |
| 2169 | |
| 2170 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2171 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 2172 | UserHandle.USER_CURRENT_OR_SELF); |
| 2173 | Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG); |
| 2174 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF); |
| 2175 | } |
| 2176 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2177 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2178 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2179 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2180 | // Any printing key that is chorded with Search should be consumed |
| 2181 | // even if no shortcut was invoked. This prevents text from being |
| 2182 | // inadvertently inserted when using a keyboard that has built-in macro |
| 2183 | // 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] | 2184 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2185 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 2186 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2187 | mConsumeSearchKeyUp = true; |
| 2188 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2189 | if (down && repeatCount == 0 && !keyguardOn) { |
| 2190 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 2191 | if (shortcutIntent != null) { |
| 2192 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2193 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2194 | mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2195 | } catch (ActivityNotFoundException ex) { |
| 2196 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2197 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2198 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2199 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2200 | } else { |
| 2201 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2202 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2203 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2204 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2205 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2206 | } |
| 2207 | } |
| 2208 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2209 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2210 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2211 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 2212 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2213 | if (kcm.isPrintingKey(keyCode)) { |
| 2214 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 2215 | metaState & ~(KeyEvent.META_META_ON |
| 2216 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 2217 | if (shortcutIntent != null) { |
| 2218 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2219 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2220 | mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2221 | } catch (ActivityNotFoundException ex) { |
| 2222 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2223 | + "the activity to which it is registered was not found: " |
| 2224 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 2225 | } |
| 2226 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2227 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2228 | } |
| 2229 | } |
| 2230 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2231 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2232 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2233 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 2234 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 2235 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2236 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2237 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2238 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2239 | } catch (ActivityNotFoundException ex) { |
| 2240 | Slog.w(TAG, "Dropping application launch key because " |
| 2241 | + "the activity to which it is registered was not found: " |
| 2242 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 2243 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2244 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2245 | } |
| 2246 | } |
| 2247 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2248 | // Display task switcher for ALT-TAB or Meta-TAB. |
| 2249 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2250 | if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2251 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
| 2252 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON) |
| 2253 | || KeyEvent.metaStateHasModifiers( |
| 2254 | shiftlessModifiers, KeyEvent.META_META_ON)) { |
| 2255 | mRecentAppsDialogHeldModifiers = shiftlessModifiers; |
| 2256 | showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW); |
| 2257 | return -1; |
| 2258 | } |
| 2259 | } |
| 2260 | } else if (!down && mRecentAppsDialogHeldModifiers != 0 |
| 2261 | && (metaState & mRecentAppsDialogHeldModifiers) == 0) { |
| 2262 | mRecentAppsDialogHeldModifiers = 0; |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2263 | showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS : |
| 2264 | RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2265 | } |
| 2266 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 2267 | // Handle keyboard language switching. |
| 2268 | if (down && repeatCount == 0 |
| 2269 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2270 | || (keyCode == KeyEvent.KEYCODE_SPACE |
| 2271 | && (metaState & KeyEvent.META_CTRL_MASK) != 0))) { |
| 2272 | int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; |
| 2273 | mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); |
| 2274 | return -1; |
| 2275 | } |
| 2276 | if (mLanguageSwitchKeyPressed && !down |
| 2277 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2278 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 2279 | mLanguageSwitchKeyPressed = false; |
| 2280 | return -1; |
| 2281 | } |
| 2282 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 2283 | if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
| 2284 | return -1; |
| 2285 | } |
| 2286 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2287 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2288 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2289 | } |
| 2290 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2291 | /** {@inheritDoc} */ |
| 2292 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2293 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2294 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2295 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2296 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 2297 | + ", flags=" + event.getFlags() |
| 2298 | + ", keyCode=" + event.getKeyCode() |
| 2299 | + ", scanCode=" + event.getScanCode() |
| 2300 | + ", metaState=" + event.getMetaState() |
| 2301 | + ", repeatCount=" + event.getRepeatCount() |
| 2302 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2303 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2304 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2305 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2306 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 2307 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2308 | final int keyCode = event.getKeyCode(); |
| 2309 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2310 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 2311 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2312 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2313 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2314 | final FallbackAction fallbackAction; |
| 2315 | if (initialDown) { |
| 2316 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 2317 | } else { |
| 2318 | fallbackAction = mFallbackActions.get(keyCode); |
| 2319 | } |
| 2320 | |
| 2321 | if (fallbackAction != null) { |
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 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 2324 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2325 | } |
| 2326 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2327 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 2328 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2329 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2330 | event.getAction(), fallbackAction.keyCode, |
| 2331 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2332 | event.getDeviceId(), event.getScanCode(), |
| 2333 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2334 | |
| 2335 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 2336 | fallbackEvent.recycle(); |
| 2337 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2338 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2339 | |
| 2340 | if (initialDown) { |
| 2341 | mFallbackActions.put(keyCode, fallbackAction); |
| 2342 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2343 | mFallbackActions.remove(keyCode); |
| 2344 | fallbackAction.recycle(); |
| 2345 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2346 | } |
| 2347 | } |
| 2348 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2349 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2350 | if (fallbackEvent == null) { |
| 2351 | Slog.d(TAG, "No fallback."); |
| 2352 | } else { |
| 2353 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 2354 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2355 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2356 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2357 | } |
| 2358 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2359 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
| 2360 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true); |
| 2361 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 2362 | long delayMillis = interceptKeyBeforeDispatching( |
| 2363 | win, fallbackEvent, policyFlags); |
| 2364 | if (delayMillis == 0) { |
| 2365 | return true; |
| 2366 | } |
| 2367 | } |
| 2368 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2369 | } |
| 2370 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2371 | private void launchAssistLongPressAction() { |
| 2372 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 2373 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 2374 | |
| 2375 | // launch the search activity |
| 2376 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 2377 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2378 | try { |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2379 | // TODO: This only stops the factory-installed search manager. |
| 2380 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2381 | SearchManager searchManager = getSearchManager(); |
| 2382 | if (searchManager != null) { |
| 2383 | searchManager.stopSearch(); |
| 2384 | } |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2385 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2386 | } catch (ActivityNotFoundException e) { |
| 2387 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 2388 | } |
| 2389 | } |
| 2390 | |
| 2391 | private void launchAssistAction() { |
| 2392 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 2393 | Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2394 | .getAssistIntent(mContext, true, UserHandle.USER_CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2395 | if (intent != null) { |
| 2396 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2397 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 2398 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 2399 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2400 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2401 | } catch (ActivityNotFoundException e) { |
| 2402 | Slog.w(TAG, "No activity to handle assist action.", e); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2403 | } |
| 2404 | } |
| 2405 | } |
| 2406 | |
| 2407 | private SearchManager getSearchManager() { |
| 2408 | if (mSearchManager == null) { |
| 2409 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 2410 | } |
| 2411 | return mSearchManager; |
| 2412 | } |
| 2413 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2414 | private void preloadRecentApps() { |
| 2415 | mPreloadedRecentApps = true; |
| 2416 | try { |
| 2417 | IStatusBarService statusbar = getStatusBarService(); |
| 2418 | if (statusbar != null) { |
| 2419 | statusbar.preloadRecentApps(); |
| 2420 | } |
| 2421 | } catch (RemoteException e) { |
| 2422 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
| 2423 | // re-acquire status bar service next time it is needed. |
| 2424 | mStatusBarService = null; |
| 2425 | } |
| 2426 | } |
| 2427 | |
| 2428 | private void cancelPreloadRecentApps() { |
| 2429 | if (mPreloadedRecentApps) { |
| 2430 | mPreloadedRecentApps = false; |
| 2431 | try { |
| 2432 | IStatusBarService statusbar = getStatusBarService(); |
| 2433 | if (statusbar != null) { |
| 2434 | statusbar.cancelPreloadRecentApps(); |
| 2435 | } |
| 2436 | } catch (RemoteException e) { |
| 2437 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 2438 | // re-acquire status bar service next time it is needed. |
| 2439 | mStatusBarService = null; |
| 2440 | } |
| 2441 | } |
| 2442 | } |
| 2443 | |
| 2444 | private void toggleRecentApps() { |
| 2445 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 2446 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS); |
| 2447 | try { |
| 2448 | IStatusBarService statusbar = getStatusBarService(); |
| 2449 | if (statusbar != null) { |
| 2450 | statusbar.toggleRecentApps(); |
| 2451 | } |
| 2452 | } catch (RemoteException e) { |
| 2453 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 2454 | // re-acquire status bar service next time it is needed. |
| 2455 | mStatusBarService = null; |
| 2456 | } |
| 2457 | } |
| 2458 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2459 | /** |
| 2460 | * A home key -> launch home action was detected. Take the appropriate action |
| 2461 | * given the situation with the keyguard. |
| 2462 | */ |
| 2463 | void launchHomeFromHotKey() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2464 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotHidden()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2465 | // don't launch home if keyguard showing |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2466 | } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2467 | // when in keyguard restricted mode, must first verify unlock |
| 2468 | // before launching home |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2469 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2470 | public void onKeyguardExitResult(boolean success) { |
| 2471 | if (success) { |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2472 | try { |
| 2473 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2474 | } catch (RemoteException e) { |
| 2475 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 2476 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2477 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2478 | } |
| 2479 | } |
| 2480 | }); |
| 2481 | } else { |
| 2482 | // no keyguard stuff to worry about, just launch home! |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2483 | try { |
| 2484 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2485 | } catch (RemoteException e) { |
| 2486 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 2487 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2488 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2489 | } |
| 2490 | } |
| 2491 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2492 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 2493 | @Override |
| 2494 | public void run() { |
| 2495 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2496 | // Clear flags. |
| 2497 | mForceClearedSystemUiFlags &= |
| 2498 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 2499 | } |
| 2500 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2501 | } |
| 2502 | }; |
| 2503 | |
| 2504 | /** |
| 2505 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 2506 | * to determine when the nav bar should be shown and prevent applications from |
| 2507 | * receiving those touches. |
| 2508 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2509 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 2510 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 2511 | super(inputChannel, looper); |
| 2512 | } |
| 2513 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2514 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2515 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2516 | boolean handled = false; |
| 2517 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 2518 | if (event instanceof MotionEvent |
| 2519 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 2520 | final MotionEvent motionEvent = (MotionEvent)event; |
| 2521 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2522 | // When the user taps down, we re-show the nav bar. |
| 2523 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2524 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2525 | // Any user activity always causes us to show the |
| 2526 | // navigation controls, if they had been hidden. |
| 2527 | // We also clear the low profile and only content |
| 2528 | // flags so that tapping on the screen will atomically |
| 2529 | // restore all currently hidden screen decorations. |
| 2530 | int newVal = mResettingSystemUiFlags | |
| 2531 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 2532 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 2533 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2534 | if (mResettingSystemUiFlags != newVal) { |
| 2535 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2536 | changed = true; |
| 2537 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2538 | // We don't allow the system's nav bar to be hidden |
| 2539 | // again for 1 second, to prevent applications from |
| 2540 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2541 | newVal = mForceClearedSystemUiFlags | |
| 2542 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2543 | if (mForceClearedSystemUiFlags != newVal) { |
| 2544 | mForceClearedSystemUiFlags = newVal; |
| 2545 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2546 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2547 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2548 | } |
| 2549 | if (changed) { |
| 2550 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 2551 | } |
| 2552 | } |
| 2553 | } |
| 2554 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2555 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2556 | } |
| 2557 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2558 | } |
| 2559 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 2560 | new InputEventReceiver.Factory() { |
| 2561 | @Override |
| 2562 | public InputEventReceiver createInputEventReceiver( |
| 2563 | InputChannel inputChannel, Looper looper) { |
| 2564 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 2565 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2566 | }; |
| 2567 | |
| 2568 | @Override |
| 2569 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 2570 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 2571 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2572 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2573 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 2574 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2575 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2576 | // Clear any bits in the new visibility that are currently being |
| 2577 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2578 | return visibility & ~mResettingSystemUiFlags |
| 2579 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2580 | } |
| 2581 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2582 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2583 | public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 2584 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 2585 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 2586 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2587 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2588 | 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] | 2589 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2590 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 2591 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2592 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2593 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 2594 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 2595 | } else { |
| 2596 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 2597 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 2598 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2599 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 2600 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 2601 | contentInset.set(mStableFullscreenLeft, mStableFullscreenTop, |
| 2602 | availRight - mStableFullscreenRight, |
| 2603 | availBottom - mStableFullscreenBottom); |
| 2604 | } else { |
| 2605 | contentInset.set(mStableLeft, mStableTop, |
| 2606 | availRight - mStableRight, availBottom - mStableBottom); |
| 2607 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2608 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2609 | contentInset.setEmpty(); |
| 2610 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2611 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
| 2612 | contentInset.set(mCurLeft, mCurTop, |
| 2613 | availRight - mCurRight, availBottom - mCurBottom); |
| 2614 | } else { |
| 2615 | contentInset.set(mCurLeft, mCurTop, |
| 2616 | availRight - mCurRight, availBottom - mCurBottom); |
| 2617 | } |
| 2618 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2619 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2620 | contentInset.setEmpty(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2621 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2622 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2623 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2624 | @Override |
| 2625 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
| 2626 | int displayRotation) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2627 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 2628 | if (isDefaultDisplay) { |
| 2629 | switch (displayRotation) { |
| 2630 | case Surface.ROTATION_90: |
| 2631 | overscanLeft = mOverscanTop; |
| 2632 | overscanTop = mOverscanRight; |
| 2633 | overscanRight = mOverscanBottom; |
| 2634 | overscanBottom = mOverscanLeft; |
| 2635 | break; |
| 2636 | case Surface.ROTATION_180: |
| 2637 | overscanLeft = mOverscanRight; |
| 2638 | overscanTop = mOverscanBottom; |
| 2639 | overscanRight = mOverscanLeft; |
| 2640 | overscanBottom = mOverscanTop; |
| 2641 | break; |
| 2642 | case Surface.ROTATION_270: |
| 2643 | overscanLeft = mOverscanBottom; |
| 2644 | overscanTop = mOverscanLeft; |
| 2645 | overscanRight = mOverscanTop; |
| 2646 | overscanBottom = mOverscanRight; |
| 2647 | break; |
| 2648 | default: |
| 2649 | overscanLeft = mOverscanLeft; |
| 2650 | overscanTop = mOverscanTop; |
| 2651 | overscanRight = mOverscanRight; |
| 2652 | overscanBottom = mOverscanBottom; |
| 2653 | break; |
| 2654 | } |
| 2655 | } else { |
| 2656 | overscanLeft = 0; |
| 2657 | overscanTop = 0; |
| 2658 | overscanRight = 0; |
| 2659 | overscanBottom = 0; |
| 2660 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2661 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 2662 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 2663 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 2664 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2665 | mSystemLeft = 0; |
| 2666 | mSystemTop = 0; |
| 2667 | mSystemRight = displayWidth; |
| 2668 | mSystemBottom = displayHeight; |
| 2669 | mUnrestrictedScreenLeft = overscanLeft; |
| 2670 | mUnrestrictedScreenTop = overscanTop; |
| 2671 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 2672 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 2673 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 2674 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2675 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 2676 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2677 | mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2678 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2679 | mDockTop = mContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2680 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2681 | mDockRight = mContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2682 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2683 | mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2684 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2685 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2686 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2687 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2688 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 2689 | final Rect pf = mTmpParentFrame; |
| 2690 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2691 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2692 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2693 | final Rect dcf = mTmpDecorFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2694 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 2695 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 2696 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 2697 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2698 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2699 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2700 | if (isDefaultDisplay) { |
| 2701 | // For purposes of putting out fake window up to steal focus, we will |
| 2702 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2703 | final int sysui = mLastSystemUiFlags; |
| 2704 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 2705 | boolean navTranslucent = (sysui & View.NAVIGATION_BAR_TRANSLUCENT) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 2706 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 2707 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 2708 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 2709 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 2710 | navTranslucent &= areTranslucentBarsAllowed(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2711 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2712 | // When the navigation bar isn't visible, we put up a fake |
| 2713 | // input window to catch all touch events. This way we can |
| 2714 | // detect when the user presses anywhere to bring back the nav |
| 2715 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 2716 | if (navVisible || navAllowedHidden) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2717 | if (mHideNavFakeWindow != null) { |
| 2718 | mHideNavFakeWindow.dismiss(); |
| 2719 | mHideNavFakeWindow = null; |
| 2720 | } |
| 2721 | } else if (mHideNavFakeWindow == null) { |
| 2722 | mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow( |
| 2723 | mHandler.getLooper(), mHideNavInputEventReceiverFactory, |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2724 | "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2725 | 0, false, false, true); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2726 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2727 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2728 | // For purposes of positioning and showing the nav bar, if we have |
| 2729 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 2730 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 2731 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2732 | |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2733 | boolean updateSysUiVisibility = false; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2734 | if (mNavigationBar != null) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2735 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2736 | // Force the navigation bar to its appropriate place and |
| 2737 | // size. We need to do this directly, instead of relying on |
| 2738 | // it to bubble up from the nav bar, because this needs to |
| 2739 | // change atomically with screen rotations. |
| 2740 | mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight); |
| 2741 | if (mNavigationBarOnBottom) { |
| 2742 | // 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] | 2743 | int top = displayHeight - overscanBottom |
| 2744 | - mNavigationBarHeightForRotation[displayRotation]; |
| 2745 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2746 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 2747 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2748 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2749 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2750 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2751 | mDockBottom = mTmpNavigationFrame.top; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2752 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 2753 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2754 | } else { |
| 2755 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2756 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2757 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 2758 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 2759 | && !mNavigationBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 2760 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2761 | // If the opaque nav bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2762 | // and not in the process of animating on or off, then |
| 2763 | // we can tell the app that it is covered by it. |
| 2764 | mSystemBottom = mTmpNavigationFrame.top; |
| 2765 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2766 | } else { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2767 | // Landscape screen; nav bar goes to the right. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2768 | int left = displayWidth - overscanRight |
| 2769 | - mNavigationBarWidthForRotation[displayRotation]; |
| 2770 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2771 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 2772 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2773 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2774 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2775 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2776 | mDockRight = mTmpNavigationFrame.left; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2777 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 2778 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2779 | } else { |
| 2780 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2781 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2782 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 2783 | if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw() |
| 2784 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2785 | // If the nav bar is currently requested to be visible, |
| 2786 | // and not in the process of animating on or off, then |
| 2787 | // we can tell the app that it is covered by it. |
| 2788 | mSystemRight = mTmpNavigationFrame.left; |
| 2789 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2790 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2791 | // Make sure the content and current rectangles are updated to |
| 2792 | // account for the restrictions from the navigation bar. |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2793 | mContentTop = mCurTop = mDockTop; |
| 2794 | mContentBottom = mCurBottom = mDockBottom; |
| 2795 | mContentLeft = mCurLeft = mDockLeft; |
| 2796 | mContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2797 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 2798 | // And compute the final frame. |
| 2799 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2800 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2801 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2802 | if (mNavigationBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2803 | updateSysUiVisibility = true; |
| 2804 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2805 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2806 | 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] | 2807 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
| 2808 | |
| 2809 | // decide where the status bar goes ahead of time |
| 2810 | if (mStatusBar != null) { |
| 2811 | // apply any navigation bar insets |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2812 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 2813 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 2814 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 2815 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 2816 | + mUnrestrictedScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2817 | vf.left = mStableLeft; |
| 2818 | vf.top = mStableTop; |
| 2819 | vf.right = mStableRight; |
| 2820 | vf.bottom = mStableBottom; |
| 2821 | |
| 2822 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 2823 | |
| 2824 | // Let the status bar determine its size. |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2825 | mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2826 | |
| 2827 | // For layout, the status bar is always at the top with our fixed height. |
| 2828 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 2829 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2830 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 2831 | boolean statusBarTranslucent = (sysui & View.STATUS_BAR_TRANSLUCENT) != 0; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 2832 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 2833 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2834 | // If the status bar is hidden, we don't want to cause |
| 2835 | // windows behind it to scroll. |
John Spurlock | eda1f69 | 2013-09-16 11:38:44 -0400 | [diff] [blame] | 2836 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2837 | // Status bar may go away, so the screen area it occupies |
| 2838 | // is available to apps but just covering them when the |
| 2839 | // status bar is visible. |
| 2840 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 2841 | |
| 2842 | mContentTop = mCurTop = mDockTop; |
| 2843 | mContentBottom = mCurBottom = mDockBottom; |
| 2844 | mContentLeft = mCurLeft = mDockLeft; |
| 2845 | mContentRight = mCurRight = mDockRight; |
| 2846 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2847 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2848 | String.format( |
| 2849 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 2850 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 2851 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 2852 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 2853 | } |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2854 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 2855 | && !statusBarTransient && !statusBarTranslucent |
| 2856 | && !mStatusBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2857 | // If the opaque status bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2858 | // and not in the process of animating on or off, then |
| 2859 | // we can tell the app that it is covered by it. |
| 2860 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 2861 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2862 | if (mStatusBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2863 | updateSysUiVisibility = true; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 2864 | } |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2865 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2866 | if (updateSysUiVisibility) { |
| 2867 | updateSystemUiVisibilityLw(); |
| 2868 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2869 | } |
| 2870 | } |
| 2871 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 2872 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2873 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2874 | public int getSystemDecorLayerLw() { |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 2875 | if (mStatusBar != null) return mStatusBar.getSurfaceLayer(); |
| 2876 | if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer(); |
| 2877 | return 0; |
| 2878 | } |
| 2879 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2880 | @Override |
| 2881 | public void getContentRectLw(Rect r) { |
| 2882 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 2883 | } |
| 2884 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2885 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 2886 | 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] | 2887 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 2888 | // Here's a special case: if this attached window is a panel that is |
| 2889 | // above the dock window, and the window it is attached to is below |
| 2890 | // the dock window, then the frames we computed for the window it is |
| 2891 | // attached to can not be used because the dock is effectively part |
| 2892 | // of the underlying window and the attached window is floating on top |
| 2893 | // of the whole thing. So, we ignore the attached window and explicitly |
| 2894 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2895 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 2896 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 2897 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 2898 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2899 | } else { |
| 2900 | // The effective display frame of the attached window depends on |
| 2901 | // whether it is taking care of insetting its content. If not, |
| 2902 | // we need to use the parent's content frame so that the entire |
| 2903 | // window is positioned within that content. Otherwise we can use |
| 2904 | // the display frame and let the attached window take care of |
| 2905 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 2906 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2907 | cf.set(attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2908 | } else { |
| 2909 | // If the window is resizing, then we want to base the content |
| 2910 | // frame on our attached content frame to resize... however, |
| 2911 | // things can be tricky if the attached window is NOT in resize |
| 2912 | // mode, in which case its content frame will be larger. |
| 2913 | // Ungh. So to deal with that, make sure the content frame |
| 2914 | // we end up using is not covering the IM dock. |
| 2915 | cf.set(attached.getContentFrameLw()); |
| 2916 | if (attached.getSurfaceLayer() < mDockLayer) { |
| 2917 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 2918 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 2919 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 2920 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 2921 | } |
| 2922 | } |
| 2923 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2924 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2925 | vf.set(attached.getVisibleFrameLw()); |
| 2926 | } |
| 2927 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 2928 | // window should be positioned relative to its parent or the entire |
| 2929 | // screen. |
| 2930 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 2931 | ? attached.getFrameLw() : df); |
| 2932 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2933 | |
| 2934 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 2935 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 2936 | // If app is requesting a stable layout, don't let the |
| 2937 | // content insets go below the stable values. |
| 2938 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 2939 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 2940 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 2941 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 2942 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 2943 | } else { |
| 2944 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 2945 | if (r.top < mStableTop) r.top = mStableTop; |
| 2946 | if (r.right > mStableRight) r.right = mStableRight; |
| 2947 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 2948 | } |
| 2949 | } |
| 2950 | } |
| 2951 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2952 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2953 | @Override |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 2954 | public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs, |
| 2955 | WindowState attached) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2956 | // we've already done the status bar |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2957 | if (win == mStatusBar || win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2958 | return; |
| 2959 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2960 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 2961 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 2962 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 2963 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2964 | 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] | 2965 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 2966 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2967 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 2968 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2969 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 2970 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2971 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2972 | final Rect pf = mTmpParentFrame; |
| 2973 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2974 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2975 | final Rect cf = mTmpContentFrame; |
| 2976 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2977 | final Rect dcf = mTmpDecorFrame; |
| 2978 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2979 | |
| 2980 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 2981 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2982 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 2983 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 2984 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2985 | if (!isDefaultDisplay) { |
| 2986 | if (attached != null) { |
| 2987 | // If this window is attached to another, our display |
| 2988 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2989 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2990 | } else { |
| 2991 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2992 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 2993 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 2994 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2995 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2996 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2997 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2998 | } |
| 2999 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3000 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3001 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 3002 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3003 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 3004 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3005 | // ...with content insets above the nav bar |
| 3006 | cf.bottom = vf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3007 | // IM dock windows always go to the bottom of the screen. |
| 3008 | attrs.gravity = Gravity.BOTTOM; |
| 3009 | mDockLayer = win.getSurfaceLayer(); |
| 3010 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3011 | |
| 3012 | // Default policy decor for the default display |
| 3013 | dcf.left = mSystemLeft; |
| 3014 | dcf.top = mSystemTop; |
| 3015 | dcf.right = mSystemRight; |
| 3016 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3017 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 3018 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 3019 | final boolean isAppWindow = |
| 3020 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 3021 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 3022 | final boolean topAtRest = |
| 3023 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 3024 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3025 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 3026 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
| 3027 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3028 | // Ensure policy decor includes status bar |
| 3029 | dcf.top = mStableTop; |
| 3030 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3031 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
John Spurlock | 8e0ca28 | 2013-10-03 11:46:06 -0400 | [diff] [blame] | 3032 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3033 | // Ensure policy decor includes navigation bar |
| 3034 | dcf.bottom = mStableBottom; |
| 3035 | dcf.right = mStableRight; |
| 3036 | } |
| 3037 | } |
| 3038 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3039 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 3040 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3041 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3042 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3043 | // This is the case for a normal activity window: we want it |
| 3044 | // to cover all of the screen space, and it can take care of |
| 3045 | // moving its contents to account for screen decorations that |
| 3046 | // intrude into that space. |
| 3047 | if (attached != null) { |
| 3048 | // If this window is attached to another, our display |
| 3049 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3050 | 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] | 3051 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3052 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3053 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3054 | // Status bar panels are the only windows who can go on top of |
| 3055 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3056 | // permission, so they have the same privileges as the status |
| 3057 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3058 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3059 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3060 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3061 | pf.left = df.left = of.left = hasNavBar |
| 3062 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3063 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3064 | pf.right = df.right = of.right = hasNavBar |
| 3065 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 3066 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3067 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 3068 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 3069 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3070 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3071 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3072 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 3073 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3074 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3075 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3076 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3077 | // Asking to layout into the overscan region, so give it that pure |
| 3078 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3079 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 3080 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 3081 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3082 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 3083 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3084 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3085 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 3086 | && (attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD || ( |
| 3087 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3088 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3089 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3090 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3091 | // only do this for application windows to ensure no window that |
| 3092 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3093 | pf.left = df.left = mOverscanScreenLeft; |
| 3094 | pf.top = df.top = mOverscanScreenTop; |
| 3095 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3096 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3097 | // We need to tell the app about where the frame inside the overscan |
| 3098 | // is, so it can inset its content by that amount -- it didn't ask |
| 3099 | // to actually extend itself into the overscan region. |
| 3100 | of.left = mUnrestrictedScreenLeft; |
| 3101 | of.top = mUnrestrictedScreenTop; |
| 3102 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3103 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3104 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3105 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 3106 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 3107 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 3108 | + mRestrictedOverscanScreenWidth; |
| 3109 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 3110 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3111 | // We need to tell the app about where the frame inside the overscan |
| 3112 | // is, so it can inset its content by that amount -- it didn't ask |
| 3113 | // to actually extend itself into the overscan region. |
| 3114 | of.left = mUnrestrictedScreenLeft; |
| 3115 | of.top = mUnrestrictedScreenTop; |
| 3116 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3117 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3118 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3119 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3120 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3121 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 3122 | cf.left = mDockLeft; |
| 3123 | cf.top = mDockTop; |
| 3124 | cf.right = mDockRight; |
| 3125 | cf.bottom = mDockBottom; |
| 3126 | } else { |
| 3127 | cf.left = mContentLeft; |
| 3128 | cf.top = mContentTop; |
| 3129 | cf.right = mContentRight; |
| 3130 | cf.bottom = mContentBottom; |
| 3131 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3132 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3133 | // Full screen windows are always given a layout that is as if the |
| 3134 | // status bar and other transient decors are gone. This is to avoid |
| 3135 | // bad states when moving from a window that is not hding the |
| 3136 | // status bar to one that is. |
| 3137 | cf.left = mRestrictedScreenLeft; |
| 3138 | cf.top = mRestrictedScreenTop; |
| 3139 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3140 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3141 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3142 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3143 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3144 | vf.left = mCurLeft; |
| 3145 | vf.top = mCurTop; |
| 3146 | vf.right = mCurRight; |
| 3147 | vf.bottom = mCurBottom; |
| 3148 | } else { |
| 3149 | vf.set(cf); |
| 3150 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3151 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3152 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 3153 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 3154 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3155 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3156 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3157 | // A window that has requested to fill the entire screen just |
| 3158 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3159 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3160 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3161 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 3162 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3163 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3164 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3165 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3166 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3167 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3168 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3169 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3170 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3171 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 3172 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 3173 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 3174 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3175 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3176 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3177 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3178 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 3179 | + mUnrestrictedScreenWidth; |
| 3180 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 3181 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3182 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3183 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 3184 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3185 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
| 3186 | || attrs.type == TYPE_BOOT_PROGRESS) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 3187 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 3188 | // Fullscreen secure system overlays get what they ask for. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3189 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3190 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3191 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3192 | + mOverscanScreenWidth; |
| 3193 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3194 | + mOverscanScreenHeight; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 3195 | } else if (attrs.type == TYPE_BOOT_PROGRESS |
| 3196 | || attrs.type == TYPE_UNIVERSE_BACKGROUND) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3197 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3198 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3199 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3200 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3201 | + mOverscanScreenWidth; |
| 3202 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3203 | + mOverscanScreenHeight; |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3204 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 3205 | // The wallpaper also has Real Ultimate Power. |
| 3206 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3207 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3208 | pf.right = df.right = of.right = cf.right |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3209 | = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3210 | pf.bottom = df.bottom = of.bottom = cf.bottom |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3211 | = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3212 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3213 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3214 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3215 | // Asking to layout into the overscan region, so give it that pure |
| 3216 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3217 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3218 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3219 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3220 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3221 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3222 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3223 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3224 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3225 | && (attrs.type == TYPE_TOAST |
| 3226 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3227 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3228 | // Asking for layout as if the nav bar is hidden, lets the |
| 3229 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3230 | // only do this for application windows (or toasts) to ensure no window that |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3231 | // can be above the nav bar can do this. |
| 3232 | // XXX This assumes that an app asking for this will also |
| 3233 | // ask for layout in only content. We can't currently figure out |
| 3234 | // 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] | 3235 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3236 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3237 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 3238 | + mUnrestrictedScreenWidth; |
| 3239 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 3240 | + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3241 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3242 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3243 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3244 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3245 | + mRestrictedScreenWidth; |
| 3246 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3247 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3248 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3249 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3250 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3251 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3252 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3253 | vf.left = mCurLeft; |
| 3254 | vf.top = mCurTop; |
| 3255 | vf.right = mCurRight; |
| 3256 | vf.bottom = mCurBottom; |
| 3257 | } else { |
| 3258 | vf.set(cf); |
| 3259 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3260 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3261 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3262 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3263 | // A child window should be placed inside of the same visible |
| 3264 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3265 | 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] | 3266 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3267 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3268 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3269 | // Otherwise, a normal window must be placed inside the content |
| 3270 | // of all screen decorations. |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3271 | if (attrs.type == TYPE_STATUS_BAR_PANEL) { |
| 3272 | // Status bar panels are the only windows who can go on top of |
| 3273 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3274 | // permission, so they have the same privileges as the status |
| 3275 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3276 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3277 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3278 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3279 | + mRestrictedScreenWidth; |
| 3280 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3281 | + mRestrictedScreenHeight; |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 3282 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT |
| 3283 | || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 3284 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3285 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 3286 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 3287 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 3288 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3289 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3290 | pf.left = mContentLeft; |
| 3291 | pf.top = mContentTop; |
| 3292 | pf.right = mContentRight; |
| 3293 | pf.bottom = mContentBottom; |
| 3294 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3295 | df.left = of.left = cf.left = mDockLeft; |
| 3296 | df.top = of.top = cf.top = mDockTop; |
| 3297 | df.right = of.right = cf.right = mDockRight; |
| 3298 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3299 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3300 | df.left = of.left = cf.left = mContentLeft; |
| 3301 | df.top = of.top = cf.top = mContentTop; |
| 3302 | df.right = of.right = cf.right = mContentRight; |
| 3303 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3304 | } |
| 3305 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3306 | vf.left = mCurLeft; |
| 3307 | vf.top = mCurTop; |
| 3308 | vf.right = mCurRight; |
| 3309 | vf.bottom = mCurBottom; |
| 3310 | } else { |
| 3311 | vf.set(cf); |
| 3312 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3313 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3314 | } |
| 3315 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3316 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 3317 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
| 3318 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3319 | df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 3320 | df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom |
| 3321 | = vf.right = vf.bottom = 10000; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3322 | } |
| 3323 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3324 | 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] | 3325 | + ": sim=#" + Integer.toHexString(sim) |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3326 | + " attach=" + attached + " type=" + attrs.type |
| 3327 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3328 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3329 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3330 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
| 3331 | + " dcf=" + dcf.toShortString()); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3332 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3333 | win.computeFrameLw(pf, df, of, cf, vf, dcf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3334 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3335 | // Dock windows carve out the bottom of the screen, so normal windows |
| 3336 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 3337 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
| 3338 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3339 | setLastInputMethodWindowLw(null, null); |
| 3340 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3341 | } |
| 3342 | } |
| 3343 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3344 | private void offsetInputMethodWindowLw(WindowState win) { |
| 3345 | int top = win.getContentFrameLw().top; |
| 3346 | top += win.getGivenContentInsetsLw().top; |
| 3347 | if (mContentBottom > top) { |
| 3348 | mContentBottom = top; |
| 3349 | } |
| 3350 | top = win.getVisibleFrameLw().top; |
| 3351 | top += win.getGivenVisibleInsetsLw().top; |
| 3352 | if (mCurBottom > top) { |
| 3353 | mCurBottom = top; |
| 3354 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3355 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3356 | + mDockBottom + " mContentBottom=" |
| 3357 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 3358 | } |
| 3359 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3360 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 3361 | @Override |
| 3362 | public void finishLayoutLw() { |
| 3363 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3364 | } |
| 3365 | |
| 3366 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3367 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3368 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3369 | mTopFullscreenOpaqueWindowState = null; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame^] | 3370 | mAppsToBeHidden.clear(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3371 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3372 | mForceStatusBarFromKeyguard = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3373 | mForcingShowNavBar = false; |
| 3374 | mForcingShowNavBarLayer = -1; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3375 | |
| 3376 | mHideLockScreen = false; |
| 3377 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3378 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3379 | mShowingLockscreen = false; |
| 3380 | mShowingDream = false; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3381 | } |
| 3382 | |
| 3383 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3384 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3385 | public void applyPostLayoutPolicyLw(WindowState win, |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3386 | WindowManager.LayoutParams attrs) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3387 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 3388 | + win.isVisibleOrBehindKeyguardLw()); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3389 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 3390 | if (mTopFullscreenOpaqueWindowState == null |
| 3391 | && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) { |
| 3392 | mForcingShowNavBar = true; |
| 3393 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3394 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3395 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 3396 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3397 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3398 | if (attrs.type == TYPE_KEYGUARD) { |
| 3399 | mForceStatusBarFromKeyguard = true; |
| 3400 | } else { |
| 3401 | mForceStatusBar = true; |
| 3402 | } |
| 3403 | } |
| 3404 | if (attrs.type == TYPE_KEYGUARD) { |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3405 | mShowingLockscreen = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3406 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3407 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3408 | && attrs.type <= LAST_APPLICATION_WINDOW; |
| 3409 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 3410 | // If the lockscreen was showing when the dream started then wait |
| 3411 | // for the dream to draw before hiding the lockscreen. |
| 3412 | if (!mDreamingLockscreen |
| 3413 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 3414 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3415 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3416 | } |
| 3417 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3418 | |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 3419 | final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3420 | if (appWindow) { |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame^] | 3421 | if (showWhenLocked) { |
| 3422 | mAppsToBeHidden.remove(win.getAppToken()); |
| 3423 | } else { |
| 3424 | mAppsToBeHidden.add(win.getAppToken()); |
| 3425 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3426 | if (attrs.x == 0 && attrs.y == 0 |
| 3427 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 3428 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { |
| 3429 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 3430 | mTopFullscreenOpaqueWindowState = win; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame^] | 3431 | if (mAppsToBeHidden.isEmpty()) { |
Craig Mautner | da09ae3 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3432 | if (showWhenLocked) { |
| 3433 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 3434 | "Setting mHideLockScreen to true by win " + win); |
| 3435 | mHideLockScreen = true; |
| 3436 | mForceStatusBarFromKeyguard = false; |
| 3437 | } |
| 3438 | if ((fl & FLAG_DISMISS_KEYGUARD) != 0 |
| 3439 | && mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
| 3440 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 3441 | "Setting mDismissKeyguard true by win " + win); |
| 3442 | mDismissKeyguard = mWinDismissingKeyguard == win ? |
| 3443 | DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
| 3444 | mWinDismissingKeyguard = win; |
| 3445 | mForceStatusBarFromKeyguard = mShowingLockscreen && isKeyguardSecure(); |
| 3446 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3447 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 3448 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3449 | mAllowLockscreenWhenOn = true; |
| 3450 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3451 | } |
| 3452 | } |
| 3453 | } |
| 3454 | } |
| 3455 | |
| 3456 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3457 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3458 | public int finishPostLayoutPolicyLw() { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3459 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3460 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3461 | |
| 3462 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 3463 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 3464 | : null; |
| 3465 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 3466 | // If we are not currently showing a dream then remember the current |
| 3467 | // lockscreen state. We will use this to determine whether the dream |
| 3468 | // started while the lockscreen was showing and remember this state |
| 3469 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3470 | if (!mShowingDream) { |
| 3471 | mDreamingLockscreen = mShowingLockscreen; |
| 3472 | } |
| 3473 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3474 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3475 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3476 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 3477 | + " top=" + mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3478 | if (mForceStatusBar || mForceStatusBarFromKeyguard) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3479 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3480 | if (mStatusBarController.setBarShowingLw(true)) { |
| 3481 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3482 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 3483 | // Maintain fullscreen layout until incoming animation is complete. |
| 3484 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 3485 | // Transient status bar on the lockscreen is not allowed |
| 3486 | if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) { |
| 3487 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 3488 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 3489 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3490 | } else if (mTopFullscreenOpaqueWindowState != null) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3491 | final int fl = PolicyControl.getWindowFlags(null, lp); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3492 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3493 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3494 | + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3495 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3496 | + " lp.flags=0x" + Integer.toHexString(fl)); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3497 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3498 | topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3499 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3500 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
| 3501 | // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window |
| 3502 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 3503 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3504 | if (mStatusBarController.isTransientShowing()) { |
| 3505 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3506 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3507 | } |
| 3508 | } else if (topIsFullscreen) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3509 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3510 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3511 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3512 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 3513 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 3514 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3515 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3516 | if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3517 | if (mStatusBarController.setBarShowingLw(true)) { |
| 3518 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3519 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3520 | } |
| 3521 | } |
| 3522 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3523 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 3524 | if (mTopIsFullscreen != topIsFullscreen) { |
| 3525 | if (!topIsFullscreen) { |
| 3526 | // Force another layout when status bar becomes fully shown. |
| 3527 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3528 | } |
| 3529 | mTopIsFullscreen = topIsFullscreen; |
| 3530 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3531 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3532 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 3533 | // displayed when the screen is locked. |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 3534 | if (mKeyguard != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3535 | if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3536 | + mHideLockScreen); |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3537 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3538 | if (mKeyguard.hideLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3539 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3540 | | FINISH_LAYOUT_REDO_CONFIG |
| 3541 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3542 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3543 | if (mKeyguardDelegate.isShowing()) { |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 3544 | mHandler.post(new Runnable() { |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3545 | @Override |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 3546 | public void run() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3547 | mKeyguardDelegate.keyguardDone(false, false); |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 3548 | } |
| 3549 | }); |
| 3550 | } |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 3551 | } else if (mHideLockScreen) { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3552 | if (mKeyguard.hideLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3553 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3554 | | FINISH_LAYOUT_REDO_CONFIG |
| 3555 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3556 | } |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 3557 | if (!mShowingDream) { |
| 3558 | mKeyguardDelegate.setHidden(true); |
| 3559 | } |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3560 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
| 3561 | // This is the case of keyguard isSecure() and not mHideLockScreen. |
| 3562 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 3563 | // Only launch the next keyguard unlock window once per window. |
| 3564 | if (mKeyguard.showLw(true)) { |
| 3565 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3566 | | FINISH_LAYOUT_REDO_CONFIG |
| 3567 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3568 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3569 | mKeyguardDelegate.setHidden(false); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3570 | mHandler.post(new Runnable() { |
| 3571 | @Override |
| 3572 | public void run() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3573 | mKeyguardDelegate.dismiss(); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3574 | } |
| 3575 | }); |
| 3576 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 3577 | } else { |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3578 | mWinDismissingKeyguard = null; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3579 | if (mKeyguard.showLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3580 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3581 | | FINISH_LAYOUT_REDO_CONFIG |
| 3582 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3583 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3584 | mKeyguardDelegate.setHidden(false); |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 3585 | } |
| 3586 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3587 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3588 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3589 | // If the navigation bar has been hidden or shown, we need to do another |
| 3590 | // layout pass to update that window. |
| 3591 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3592 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3593 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 3594 | // update since mAllowLockscreenWhenOn might have changed |
| 3595 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3596 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3597 | } |
| 3598 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3599 | public boolean allowAppAnimationsLw() { |
Craig Mautner | 5800443 | 2013-10-14 12:58:42 -0700 | [diff] [blame] | 3600 | if (mKeyguard != null && mKeyguard.isVisibleLw() && !mKeyguard.isAnimatingLw() |
| 3601 | || mShowingDream) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 3602 | // If keyguard or dreams is currently visible, no reason to animate behind it. |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3603 | return false; |
| 3604 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3605 | return true; |
| 3606 | } |
| 3607 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3608 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3609 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3610 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3611 | // If the navigation bar has been hidden or shown, we need to do another |
| 3612 | // layout pass to update that window. |
| 3613 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 3614 | } |
| 3615 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3616 | } |
| 3617 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 3618 | /** {@inheritDoc} */ |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3619 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 3620 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3621 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 3622 | if (newLidState == mLidState) { |
| 3623 | return; |
| 3624 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 3625 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3626 | mLidState = newLidState; |
| 3627 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 3628 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3629 | |
| 3630 | if (lidOpen) { |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 3631 | mPowerManager.wakeUp(SystemClock.uptimeMillis()); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3632 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3633 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3634 | } |
| 3635 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3636 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3637 | void setHdmiPlugged(boolean plugged) { |
| 3638 | if (mHdmiPlugged != plugged) { |
| 3639 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3640 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3641 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 3642 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3643 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 3644 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3645 | } |
| 3646 | } |
| 3647 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 3648 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 3649 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 3650 | // watch for HDMI plug messages if the hdmi switch exists |
| 3651 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 3652 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 3653 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 3654 | final String filename = "/sys/class/switch/hdmi/state"; |
| 3655 | FileReader reader = null; |
| 3656 | try { |
| 3657 | reader = new FileReader(filename); |
| 3658 | char[] buf = new char[15]; |
| 3659 | int n = reader.read(buf); |
| 3660 | if (n > 1) { |
| 3661 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 3662 | } |
| 3663 | } catch (IOException ex) { |
| 3664 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 3665 | } catch (NumberFormatException ex) { |
| 3666 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 3667 | } finally { |
| 3668 | if (reader != null) { |
| 3669 | try { |
| 3670 | reader.close(); |
| 3671 | } catch (IOException ex) { |
| 3672 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 3673 | } |
| 3674 | } |
| 3675 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 3676 | // This dance forces the code in setHdmiPlugged to run. |
| 3677 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 3678 | mHdmiPlugged = !plugged; |
| 3679 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 3680 | } |
| 3681 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3682 | /** |
Jean-Michel Trivi | fca1e60 | 2013-10-10 18:12:59 -0700 | [diff] [blame] | 3683 | * @return Whether music is being played right now "locally" (e.g. on the device's speakers |
| 3684 | * or wired headphones) or "remotely" (e.g. on a device using the Cast protocol and |
| 3685 | * controlled by this device, or through remote submix). |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3686 | */ |
| 3687 | boolean isMusicActive() { |
Eric Laurent | 413cb9d | 2009-07-17 11:52:43 -0700 | [diff] [blame] | 3688 | final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); |
| 3689 | if (am == null) { |
| 3690 | Log.w(TAG, "isMusicActive: couldn't get AudioManager reference"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3691 | return false; |
| 3692 | } |
Jean-Michel Trivi | fca1e60 | 2013-10-10 18:12:59 -0700 | [diff] [blame] | 3693 | return am.isLocalOrRemoteMusicActive(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3694 | } |
| 3695 | |
| 3696 | /** |
| 3697 | * Tell the audio service to adjust the volume appropriate to the event. |
| 3698 | * @param keycode |
| 3699 | */ |
Mike Lockwood | a53e381 | 2009-09-25 10:51:39 -0400 | [diff] [blame] | 3700 | void handleVolumeKey(int stream, int keycode) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3701 | IAudioService audioService = getAudioService(); |
| 3702 | if (audioService == null) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3703 | return; |
| 3704 | } |
| 3705 | try { |
Jean-Michel Trivi | fca1e60 | 2013-10-10 18:12:59 -0700 | [diff] [blame] | 3706 | // when audio is playing locally, we shouldn't have to hold a wake lock |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3707 | // during the call, but we do it as a precaution for the rare possibility |
Jean-Michel Trivi | fca1e60 | 2013-10-10 18:12:59 -0700 | [diff] [blame] | 3708 | // that the music stops right before we call this. |
| 3709 | // Otherwise we might also be in a remote playback case. |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 3710 | // TODO: Actually handle MUTE. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3711 | mBroadcastWakeLock.acquire(); |
Jean-Michel Trivi | fca1e60 | 2013-10-10 18:12:59 -0700 | [diff] [blame] | 3712 | if (stream == AudioSystem.STREAM_MUSIC) { |
| 3713 | audioService.adjustLocalOrRemoteStreamVolume(stream, |
| 3714 | keycode == KeyEvent.KEYCODE_VOLUME_UP |
| 3715 | ? AudioManager.ADJUST_RAISE |
| 3716 | : AudioManager.ADJUST_LOWER, |
| 3717 | mContext.getOpPackageName()); |
| 3718 | } else { |
| 3719 | audioService.adjustStreamVolume(stream, |
| 3720 | keycode == KeyEvent.KEYCODE_VOLUME_UP |
| 3721 | ? AudioManager.ADJUST_RAISE |
| 3722 | : AudioManager.ADJUST_LOWER, |
| 3723 | 0, |
| 3724 | mContext.getOpPackageName()); |
| 3725 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3726 | } catch (RemoteException e) { |
Jean-Michel Trivi | fca1e60 | 2013-10-10 18:12:59 -0700 | [diff] [blame] | 3727 | Log.w(TAG, "IAudioService.adjust*StreamVolume() threw RemoteException " + e); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3728 | } finally { |
| 3729 | mBroadcastWakeLock.release(); |
| 3730 | } |
| 3731 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3732 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 3733 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 3734 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 3735 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3736 | final Runnable mScreenshotTimeout = new Runnable() { |
| 3737 | @Override public void run() { |
| 3738 | synchronized (mScreenshotLock) { |
| 3739 | if (mScreenshotConnection != null) { |
| 3740 | mContext.unbindService(mScreenshotConnection); |
| 3741 | mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 3742 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3743 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3744 | } |
| 3745 | }; |
| 3746 | |
| 3747 | // Assume this is called from the Handler thread. |
| 3748 | private void takeScreenshot() { |
| 3749 | synchronized (mScreenshotLock) { |
| 3750 | if (mScreenshotConnection != null) { |
| 3751 | return; |
| 3752 | } |
| 3753 | ComponentName cn = new ComponentName("com.android.systemui", |
| 3754 | "com.android.systemui.screenshot.TakeScreenshotService"); |
| 3755 | Intent intent = new Intent(); |
| 3756 | intent.setComponent(cn); |
| 3757 | ServiceConnection conn = new ServiceConnection() { |
| 3758 | @Override |
| 3759 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 3760 | synchronized (mScreenshotLock) { |
| 3761 | if (mScreenshotConnection != this) { |
| 3762 | return; |
| 3763 | } |
| 3764 | Messenger messenger = new Messenger(service); |
| 3765 | Message msg = Message.obtain(null, 1); |
| 3766 | final ServiceConnection myConn = this; |
| 3767 | Handler h = new Handler(mHandler.getLooper()) { |
| 3768 | @Override |
| 3769 | public void handleMessage(Message msg) { |
| 3770 | synchronized (mScreenshotLock) { |
| 3771 | if (mScreenshotConnection == myConn) { |
| 3772 | mContext.unbindService(mScreenshotConnection); |
| 3773 | mScreenshotConnection = null; |
| 3774 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 3775 | } |
| 3776 | } |
| 3777 | } |
| 3778 | }; |
| 3779 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 3780 | msg.arg1 = msg.arg2 = 0; |
| 3781 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 3782 | msg.arg1 = 1; |
| 3783 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 3784 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3785 | try { |
| 3786 | messenger.send(msg); |
| 3787 | } catch (RemoteException e) { |
| 3788 | } |
| 3789 | } |
| 3790 | } |
| 3791 | @Override |
| 3792 | public void onServiceDisconnected(ComponentName name) {} |
| 3793 | }; |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 3794 | if (mContext.bindServiceAsUser( |
| 3795 | intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3796 | mScreenshotConnection = conn; |
| 3797 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 3798 | } |
| 3799 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3800 | } |
| 3801 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3802 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3803 | @Override |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3804 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3805 | if (!mSystemBooted) { |
| 3806 | // If we have not yet booted, don't let key events do anything. |
| 3807 | return 0; |
| 3808 | } |
| 3809 | |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3810 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 3811 | final boolean canceled = event.isCanceled(); |
| 3812 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 3813 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 3814 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 3815 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 3816 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 3817 | // the same as if it were open and in front. |
| 3818 | // This will prevent any keys other than the power button from waking the screen |
| 3819 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3820 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 3821 | (isScreenOn ? |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3822 | mKeyguardDelegate.isShowingAndNotHidden() : |
| 3823 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3824 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 3825 | if (keyCode == KeyEvent.KEYCODE_POWER |
| 3826 | || keyCode == KeyEvent.KEYCODE_SLEEP |
| 3827 | || keyCode == KeyEvent.KEYCODE_WAKEUP) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3828 | policyFlags |= WindowManagerPolicy.FLAG_WAKE; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 3829 | } |
| 3830 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3831 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3832 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3833 | + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 3834 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3835 | } |
| 3836 | |
Jeff Brown | 98392ef | 2011-09-12 18:24:59 -0700 | [diff] [blame] | 3837 | if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 3838 | && event.getRepeatCount() == 0) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3839 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 3840 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3841 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3842 | // Basic policy based on screen state and keyguard. |
| 3843 | // FIXME: This policy isn't quite correct. We shouldn't care whether the screen |
| 3844 | // is on or off, really. We should care about whether the device is in an |
| 3845 | // interactive state or is in suspend pretending to be "off". |
| 3846 | // The primary screen might be turned off due to proximity sensor or |
| 3847 | // because we are presenting media on an auxiliary screen or remotely controlling |
| 3848 | // the device some other way (which is why we have an exemption here for injected |
| 3849 | // events). |
| 3850 | int result; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 3851 | boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE |
| 3852 | | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0; |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 3853 | if (isScreenOn || (isInjected && !isWakeKey)) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3854 | // When the screen is on or if the key is injected pass the key to the application. |
| 3855 | result = ACTION_PASS_TO_USER; |
| 3856 | } else { |
| 3857 | // When the screen is off and the key is not injected, determine whether |
| 3858 | // to wake the device but don't pass the key to the application. |
| 3859 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 3860 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 3861 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3862 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3863 | } |
| 3864 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 3865 | // If the key would be handled globally, just return the result, don't worry about special |
| 3866 | // key processing. |
| 3867 | if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
| 3868 | return result; |
| 3869 | } |
| 3870 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3871 | // Handle special keys. |
| 3872 | switch (keyCode) { |
| 3873 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 3874 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 3875 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3876 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 3877 | if (down) { |
| 3878 | if (isScreenOn && !mVolumeDownKeyTriggered |
| 3879 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3880 | mVolumeDownKeyTriggered = true; |
| 3881 | mVolumeDownKeyTime = event.getDownTime(); |
| 3882 | mVolumeDownKeyConsumedByScreenshotChord = false; |
| 3883 | cancelPendingPowerKeyAction(); |
| 3884 | interceptScreenshotChord(); |
| 3885 | } |
| 3886 | } else { |
| 3887 | mVolumeDownKeyTriggered = false; |
| 3888 | cancelPendingScreenshotChordAction(); |
| 3889 | } |
| 3890 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 3891 | if (down) { |
| 3892 | if (isScreenOn && !mVolumeUpKeyTriggered |
| 3893 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3894 | mVolumeUpKeyTriggered = true; |
| 3895 | cancelPendingPowerKeyAction(); |
| 3896 | cancelPendingScreenshotChordAction(); |
| 3897 | } |
| 3898 | } else { |
| 3899 | mVolumeUpKeyTriggered = false; |
| 3900 | cancelPendingScreenshotChordAction(); |
| 3901 | } |
| 3902 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3903 | if (down) { |
| 3904 | ITelephony telephonyService = getTelephonyService(); |
| 3905 | if (telephonyService != null) { |
| 3906 | try { |
| 3907 | if (telephonyService.isRinging()) { |
| 3908 | // If an incoming call is ringing, either VOLUME key means |
| 3909 | // "silence ringer". We handle these keys here, rather than |
| 3910 | // in the InCallScreen, to make sure we'll respond to them |
| 3911 | // even if the InCallScreen hasn't come to the foreground yet. |
| 3912 | // Look for the DOWN event here, to agree with the "fallback" |
| 3913 | // behavior in the InCallScreen. |
| 3914 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 3915 | + " VOLUME key-down while ringing: Silence ringer!"); |
| 3916 | |
| 3917 | // Silence the ringer. (It's safe to call this |
| 3918 | // even if the ringer has already been silenced.) |
| 3919 | telephonyService.silenceRinger(); |
| 3920 | |
| 3921 | // And *don't* pass this key thru to the current activity |
| 3922 | // (which is probably the InCallScreen.) |
| 3923 | result &= ~ACTION_PASS_TO_USER; |
| 3924 | break; |
| 3925 | } |
| 3926 | if (telephonyService.isOffhook() |
| 3927 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 3928 | // If we are in call but we decided not to pass the key to |
| 3929 | // the application, handle the volume change here. |
| 3930 | handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode); |
| 3931 | break; |
| 3932 | } |
| 3933 | } catch (RemoteException ex) { |
| 3934 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 3935 | } |
| 3936 | } |
| 3937 | |
| 3938 | if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) { |
| 3939 | // If music is playing but we decided not to pass the key to the |
| 3940 | // application, handle the volume change here. |
| 3941 | handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode); |
| 3942 | break; |
| 3943 | } |
| 3944 | } |
| 3945 | break; |
| 3946 | } |
| 3947 | |
| 3948 | case KeyEvent.KEYCODE_ENDCALL: { |
| 3949 | result &= ~ACTION_PASS_TO_USER; |
| 3950 | if (down) { |
| 3951 | ITelephony telephonyService = getTelephonyService(); |
| 3952 | boolean hungUp = false; |
| 3953 | if (telephonyService != null) { |
| 3954 | try { |
| 3955 | hungUp = telephonyService.endCall(); |
| 3956 | } catch (RemoteException ex) { |
| 3957 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 3958 | } |
| 3959 | } |
| 3960 | interceptPowerKeyDown(!isScreenOn || hungUp); |
| 3961 | } else { |
| 3962 | if (interceptPowerKeyUp(canceled)) { |
| 3963 | if ((mEndcallBehavior |
| 3964 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 3965 | if (goHome()) { |
| 3966 | break; |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 3967 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3968 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3969 | if ((mEndcallBehavior |
| 3970 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 3971 | mPowerManager.goToSleep(event.getEventTime()); |
| 3972 | isWakeKey = false; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3973 | } |
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 | } |
| 3976 | break; |
| 3977 | } |
| 3978 | |
| 3979 | case KeyEvent.KEYCODE_POWER: { |
| 3980 | result &= ~ACTION_PASS_TO_USER; |
| 3981 | if (down) { |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 3982 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(isScreenOn, |
| 3983 | event.getDownTime(), isImmersiveMode(mLastSystemUiFlags)); |
| 3984 | if (panic) { |
| 3985 | mHandler.post(mRequestTransientNav); |
| 3986 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3987 | if (isScreenOn && !mPowerKeyTriggered |
| 3988 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3989 | mPowerKeyTriggered = true; |
| 3990 | mPowerKeyTime = event.getDownTime(); |
| 3991 | interceptScreenshotChord(); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3992 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3993 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3994 | ITelephony telephonyService = getTelephonyService(); |
| 3995 | boolean hungUp = false; |
| 3996 | if (telephonyService != null) { |
| 3997 | try { |
| 3998 | if (telephonyService.isRinging()) { |
| 3999 | // Pressing Power while there's a ringing incoming |
| 4000 | // call should silence the ringer. |
| 4001 | telephonyService.silenceRinger(); |
| 4002 | } else if ((mIncallPowerBehavior |
| 4003 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
shower | 3ac2f66 | 2014-01-03 15:33:50 +0800 | [diff] [blame] | 4004 | && telephonyService.isOffhook() && isScreenOn) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4005 | // Otherwise, if "Power button ends call" is enabled, |
| 4006 | // the Power button will hang up any current active call. |
| 4007 | hungUp = telephonyService.endCall(); |
| 4008 | } |
| 4009 | } catch (RemoteException ex) { |
| 4010 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 4011 | } |
| 4012 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4013 | interceptPowerKeyDown(!isScreenOn || hungUp |
| 4014 | || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4015 | } else { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4016 | mPowerKeyTriggered = false; |
| 4017 | cancelPendingScreenshotChordAction(); |
| 4018 | if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) { |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4019 | mPowerManager.goToSleep(event.getEventTime()); |
| 4020 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4021 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4022 | mPendingPowerKeyUpCanceled = false; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4023 | } |
| 4024 | break; |
| 4025 | } |
| 4026 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4027 | case KeyEvent.KEYCODE_SLEEP: { |
| 4028 | result &= ~ACTION_PASS_TO_USER; |
| 4029 | mPowerManager.goToSleep(event.getEventTime()); |
| 4030 | isWakeKey = false; |
| 4031 | break; |
| 4032 | } |
| 4033 | |
| 4034 | case KeyEvent.KEYCODE_WAKEUP: { |
| 4035 | result &= ~ACTION_PASS_TO_USER; |
| 4036 | break; |
| 4037 | } |
| 4038 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4039 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4040 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4041 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 4042 | if (down) { |
| 4043 | ITelephony telephonyService = getTelephonyService(); |
| 4044 | if (telephonyService != null) { |
| 4045 | try { |
| 4046 | if (!telephonyService.isIdle()) { |
| 4047 | // Suppress PLAY/PAUSE toggle when phone is ringing or in-call |
| 4048 | // to avoid music playback. |
| 4049 | break; |
| 4050 | } |
| 4051 | } catch (RemoteException ex) { |
| 4052 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4053 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4054 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4055 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4056 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4057 | case KeyEvent.KEYCODE_MUTE: |
| 4058 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4059 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4060 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4061 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4062 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4063 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 4064 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4065 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 4066 | // Only do this if we would otherwise not pass it to the user. In that |
| 4067 | // case, the PhoneWindow class will do the same thing, except it will |
| 4068 | // 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] | 4069 | // Note that we need to make a copy of the key event here because the |
| 4070 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4071 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4072 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 4073 | new KeyEvent(event)); |
| 4074 | msg.setAsynchronous(true); |
| 4075 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4076 | } |
| 4077 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4078 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4079 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4080 | case KeyEvent.KEYCODE_CALL: { |
| 4081 | if (down) { |
| 4082 | ITelephony telephonyService = getTelephonyService(); |
| 4083 | if (telephonyService != null) { |
| 4084 | try { |
| 4085 | if (telephonyService.isRinging()) { |
| 4086 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4087 | + " CALL key-down while ringing: Answer the call!"); |
| 4088 | telephonyService.answerRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4089 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4090 | // And *don't* pass this key thru to the current activity |
| 4091 | // (which is presumably the InCallScreen.) |
| 4092 | result &= ~ACTION_PASS_TO_USER; |
| 4093 | } |
| 4094 | } catch (RemoteException ex) { |
| 4095 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4096 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4097 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4098 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4099 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4100 | } |
| 4101 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4102 | |
| 4103 | if (isWakeKey) { |
| 4104 | mPowerManager.wakeUp(event.getEventTime()); |
| 4105 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4106 | return result; |
| 4107 | } |
| 4108 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4109 | /** |
| 4110 | * When the screen is off we ignore some keys that might otherwise typically |
| 4111 | * be considered wake keys. We filter them out here. |
| 4112 | * |
| 4113 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 4114 | * is always considered a wake key. |
| 4115 | */ |
| 4116 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 4117 | switch (keyCode) { |
| 4118 | // ignore volume keys unless docked |
| 4119 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4120 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 4121 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 4122 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 4123 | |
| 4124 | // ignore media and camera keys |
| 4125 | case KeyEvent.KEYCODE_MUTE: |
| 4126 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4127 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4128 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4129 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 4130 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4131 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4132 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4133 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4134 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 4135 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4136 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4137 | case KeyEvent.KEYCODE_CAMERA: |
| 4138 | return false; |
| 4139 | } |
| 4140 | return true; |
| 4141 | } |
| 4142 | |
| 4143 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4144 | /** {@inheritDoc} */ |
| 4145 | @Override |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4146 | public int interceptMotionBeforeQueueingWhenScreenOff(long whenNanos, int policyFlags) { |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4147 | int result = 0; |
| 4148 | |
| 4149 | final boolean isWakeMotion = (policyFlags |
| 4150 | & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0; |
| 4151 | if (isWakeMotion) { |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4152 | mPowerManager.wakeUp(whenNanos / 1000000); |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4153 | } |
| 4154 | return result; |
| 4155 | } |
| 4156 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4157 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 4158 | if (DEBUG_INPUT) { |
| 4159 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4160 | } |
| 4161 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4162 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 4163 | if (DEBUG_INPUT) { |
| 4164 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 4165 | } |
| 4166 | |
| 4167 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 4168 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 4169 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 4170 | } |
| 4171 | |
| 4172 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 4173 | |
| 4174 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 4175 | && event.getRepeatCount() == 0) { |
| 4176 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 4177 | |
| 4178 | Message msg = mHandler.obtainMessage( |
| 4179 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 4180 | msg.setAsynchronous(true); |
| 4181 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 4182 | } else { |
| 4183 | mBroadcastWakeLock.release(); |
| 4184 | } |
| 4185 | } |
| 4186 | |
| 4187 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 4188 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 4189 | |
| 4190 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 4191 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 4192 | if (DEBUG_INPUT) { |
| 4193 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 4194 | } |
| 4195 | |
| 4196 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 4197 | mBroadcastWakeLock.release(); |
| 4198 | } |
| 4199 | |
| 4200 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 4201 | if (ActivityManagerNative.isSystemReady()) { |
| 4202 | IAudioService audioService = getAudioService(); |
| 4203 | if (audioService != null) { |
| 4204 | try { |
| 4205 | audioService.dispatchMediaKeyEventUnderWakelock(event); |
| 4206 | } catch (RemoteException e) { |
| 4207 | Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e); |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 4208 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4209 | } |
| 4210 | } |
| 4211 | } |
| 4212 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4213 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 4214 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4215 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 4216 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 4217 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 4218 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4219 | } else { |
| 4220 | try { |
| 4221 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 4222 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 4223 | mUiMode = uiModeService.getCurrentModeType(); |
| 4224 | } catch (RemoteException e) { |
| 4225 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 4226 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4227 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 4228 | synchronized (mLock) { |
| 4229 | updateOrientationListenerLp(); |
| 4230 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4231 | } |
| 4232 | }; |
| 4233 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4234 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 4235 | @Override |
| 4236 | public void onReceive(Context context, Intent intent) { |
| 4237 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4238 | if (mKeyguardDelegate != null) { |
| 4239 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4240 | } |
| 4241 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4242 | if (mKeyguardDelegate != null) { |
| 4243 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4244 | } |
| 4245 | } |
| 4246 | } |
| 4247 | }; |
| 4248 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4249 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 4250 | @Override |
| 4251 | public void onReceive(Context context, Intent intent) { |
| 4252 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 4253 | // tickle the settings observer: this first ensures that we're |
| 4254 | // observing the relevant settings for the newly-active user, |
| 4255 | // and then updates our own bookkeeping based on the now- |
| 4256 | // current user. |
| 4257 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 4258 | |
| 4259 | // force a re-application of focused window sysui visibility. |
| 4260 | // the window may never have been shown for this user |
| 4261 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4262 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 4263 | mLastSystemUiFlags = 0; |
| 4264 | updateSystemUiVisibilityLw(); |
| 4265 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4266 | } |
| 4267 | } |
| 4268 | }; |
| 4269 | |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 4270 | private final Runnable mRequestTransientNav = new Runnable() { |
| 4271 | @Override |
| 4272 | public void run() { |
| 4273 | requestTransientBars(mNavigationBar); |
| 4274 | } |
| 4275 | }; |
| 4276 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 4277 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4278 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4279 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
| 4280 | boolean nb = mNavigationBarController.checkShowTransientBarLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4281 | if (sb || nb) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 4282 | WindowState barTarget = sb ? mStatusBar : mNavigationBar; |
| 4283 | if (sb ^ nb && barTarget != swipeTarget) { |
| 4284 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4285 | return; |
| 4286 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4287 | if (sb) mStatusBarController.showTransient(); |
| 4288 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 4289 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4290 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4291 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4292 | } |
| 4293 | } |
| 4294 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4295 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4296 | public void screenTurnedOff(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 4297 | EventLog.writeEvent(70000, 0); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4298 | synchronized (mLock) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4299 | mScreenOnEarly = false; |
| 4300 | mScreenOnFully = false; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4301 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4302 | if (mKeyguardDelegate != null) { |
| 4303 | mKeyguardDelegate.onScreenTurnedOff(why); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4304 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4305 | synchronized (mLock) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4306 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4307 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4308 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4309 | } |
| 4310 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4311 | @Override |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 4312 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 4313 | EventLog.writeEvent(70000, 1); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 4314 | if (false) { |
| 4315 | RuntimeException here = new RuntimeException("here"); |
| 4316 | here.fillInStackTrace(); |
| 4317 | Slog.i(TAG, "Screen turning on...", here); |
| 4318 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4319 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4320 | synchronized (mLock) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4321 | mScreenOnEarly = true; |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4322 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4323 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4324 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4325 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4326 | waitForKeyguard(screenOnListener); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4327 | } |
| 4328 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4329 | private void waitForKeyguard(final ScreenOnListener screenOnListener) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4330 | if (mKeyguardDelegate != null) { |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4331 | if (screenOnListener != null) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4332 | mKeyguardDelegate.onScreenTurnedOn(new KeyguardServiceDelegate.ShowListener() { |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4333 | @Override |
| 4334 | public void onShown(IBinder windowToken) { |
| 4335 | waitForKeyguardWindowDrawn(windowToken, screenOnListener); |
| 4336 | } |
| 4337 | }); |
| 4338 | return; |
| 4339 | } else { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4340 | mKeyguardDelegate.onScreenTurnedOn(null); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4341 | } |
| 4342 | } else { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4343 | Slog.i(TAG, "No keyguard interface!"); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4344 | } |
| 4345 | finishScreenTurningOn(screenOnListener); |
| 4346 | } |
| 4347 | |
| 4348 | private void waitForKeyguardWindowDrawn(IBinder windowToken, |
| 4349 | final ScreenOnListener screenOnListener) { |
Craig Mautner | 6f29590 | 2013-10-11 21:43:06 -0700 | [diff] [blame] | 4350 | if (windowToken != null && !mHideLockScreen) { |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4351 | try { |
| 4352 | if (mWindowManager.waitForWindowDrawn( |
| 4353 | windowToken, new IRemoteCallback.Stub() { |
| 4354 | @Override |
| 4355 | public void sendResult(Bundle data) { |
| 4356 | Slog.i(TAG, "Lock screen displayed!"); |
| 4357 | finishScreenTurningOn(screenOnListener); |
| 4358 | } |
| 4359 | })) { |
| 4360 | return; |
| 4361 | } |
Craig Mautner | 4e8a19c | 2013-10-08 17:26:08 -0700 | [diff] [blame] | 4362 | Slog.i(TAG, "No lock screen! waitForWindowDrawn false"); |
| 4363 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4364 | } catch (RemoteException ex) { |
| 4365 | // Can't happen in system process. |
| 4366 | } |
| 4367 | } |
| 4368 | |
Craig Mautner | 4e8a19c | 2013-10-08 17:26:08 -0700 | [diff] [blame] | 4369 | Slog.i(TAG, "No lock screen! windowToken=" + windowToken); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4370 | finishScreenTurningOn(screenOnListener); |
| 4371 | } |
| 4372 | |
| 4373 | private void finishScreenTurningOn(ScreenOnListener screenOnListener) { |
| 4374 | synchronized (mLock) { |
| 4375 | mScreenOnFully = true; |
| 4376 | } |
| 4377 | |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 4378 | try { |
| 4379 | mWindowManager.setEventDispatching(true); |
| 4380 | } catch (RemoteException unhandled) { |
| 4381 | } |
| 4382 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4383 | if (screenOnListener != null) { |
| 4384 | screenOnListener.onScreenOn(); |
| 4385 | } |
| 4386 | } |
| 4387 | |
| 4388 | @Override |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4389 | public boolean isScreenOnEarly() { |
| 4390 | return mScreenOnEarly; |
| 4391 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4392 | |
| 4393 | @Override |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4394 | public boolean isScreenOnFully() { |
| 4395 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4396 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4397 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4398 | /** {@inheritDoc} */ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4399 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4400 | if (mKeyguardDelegate != null) { |
| 4401 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4402 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4403 | } |
| 4404 | |
| 4405 | /** {@inheritDoc} */ |
| 4406 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4407 | if (mKeyguardDelegate != null) { |
| 4408 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4409 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4410 | } |
| 4411 | |
Mike Lockwood | f791330 | 2009-11-28 22:27:10 -0500 | [diff] [blame] | 4412 | private boolean keyguardIsShowingTq() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4413 | if (mKeyguardDelegate == null) return false; |
| 4414 | return mKeyguardDelegate.isShowingAndNotHidden(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4415 | } |
| 4416 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4417 | |
| 4418 | /** {@inheritDoc} */ |
| 4419 | public boolean isKeyguardLocked() { |
| 4420 | return keyguardOn(); |
| 4421 | } |
| 4422 | |
| 4423 | /** {@inheritDoc} */ |
| 4424 | public boolean isKeyguardSecure() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4425 | if (mKeyguardDelegate == null) return false; |
| 4426 | return mKeyguardDelegate.isSecure(); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4427 | } |
| 4428 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4429 | /** {@inheritDoc} */ |
| 4430 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4431 | if (mKeyguardDelegate == null) return false; |
| 4432 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4433 | } |
| 4434 | |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4435 | public void dismissKeyguardLw() { |
Jim Miller | 195b551 | 2013-02-28 03:35:57 -0800 | [diff] [blame] | 4436 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4437 | mHandler.post(new Runnable() { |
| 4438 | public void run() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4439 | if (mKeyguardDelegate.isDismissable()) { |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4440 | // Can we just finish the keyguard straight away? |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4441 | mKeyguardDelegate.keyguardDone(false, true); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4442 | } else { |
| 4443 | // ask the keyguard to prompt the user to authenticate if necessary |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4444 | mKeyguardDelegate.dismiss(); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4445 | } |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4446 | } |
| 4447 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4448 | } |
| 4449 | } |
| 4450 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4451 | void sendCloseSystemWindows() { |
| 4452 | sendCloseSystemWindows(mContext, null); |
| 4453 | } |
| 4454 | |
| 4455 | void sendCloseSystemWindows(String reason) { |
| 4456 | sendCloseSystemWindows(mContext, reason); |
| 4457 | } |
| 4458 | |
| 4459 | static void sendCloseSystemWindows(Context context, String reason) { |
| 4460 | if (ActivityManagerNative.isSystemReady()) { |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 4461 | try { |
| 4462 | ActivityManagerNative.getDefault().closeSystemDialogs(reason); |
| 4463 | } catch (RemoteException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4464 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4465 | } |
| 4466 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 4467 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4468 | @Override |
| 4469 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4470 | if (false) { |
| 4471 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 4472 | + orientation + ", last=" + lastRotation |
| 4473 | + "); user=" + mUserRotation + " " |
| 4474 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 4475 | ? "USER_ROTATION_LOCKED" : "") |
| 4476 | ); |
| 4477 | } |
| 4478 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 4479 | if (mForceDefaultOrientation) { |
| 4480 | return Surface.ROTATION_0; |
| 4481 | } |
| 4482 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4483 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4484 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 4485 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 4486 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4487 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4488 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4489 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 4490 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4491 | // Ignore sensor when lid switch is open and rotation is forced. |
| 4492 | preferredRotation = mLidOpenRotation; |
| 4493 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4494 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4495 | // Ignore sensor when in car dock unless explicitly enabled. |
| 4496 | // This case can override the behavior of NOSENSOR, and can also |
| 4497 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4498 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4499 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 4500 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 4501 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 4502 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4503 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4504 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 4505 | // This case can override the behavior of NOSENSOR, and can also |
| 4506 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4507 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4508 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 4509 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 4510 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 4511 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 4512 | preferredRotation = mDemoHdmiRotation; |
| 4513 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 4514 | && mUndockedHdmiRotation >= 0) { |
| 4515 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 4516 | // been specified in the configuration (only for legacy devices without |
| 4517 | // full multi-display support). |
| 4518 | // Note that the dock orientation overrides the HDMI orientation. |
| 4519 | preferredRotation = mUndockedHdmiRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4520 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 4521 | // Application just wants to remain locked in the last rotation. |
| 4522 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 4523 | } else if (!mSupportAutoRotation) { |
| 4524 | // If we don't support auto-rotation then bail out here and ignore |
| 4525 | // the sensor and any rotation lock settings. |
| 4526 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 4527 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4528 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4529 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 4530 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 4531 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 4532 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4533 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 4534 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 4535 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 4536 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 4537 | // Otherwise, use sensor only if requested by the application or enabled |
| 4538 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 4539 | if (mAllowAllRotations < 0) { |
| 4540 | // Can't read this during init() because the context doesn't |
| 4541 | // have display metrics at that time so we cannot determine |
| 4542 | // tablet vs. phone then. |
| 4543 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 4544 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 4545 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4546 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 4547 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4548 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 4549 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4550 | preferredRotation = sensorRotation; |
| 4551 | } else { |
| 4552 | preferredRotation = lastRotation; |
| 4553 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 4554 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 4555 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 4556 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 4557 | // The idea is that the user rotation expresses a weak preference for the direction |
| 4558 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 4559 | // 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] | 4560 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4561 | } else { |
| 4562 | // No overriding preference. |
| 4563 | // We will do exactly what the application asked us to do. |
| 4564 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4565 | } |
| 4566 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4567 | switch (orientation) { |
| 4568 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4569 | // Return portrait unless overridden. |
| 4570 | if (isAnyPortrait(preferredRotation)) { |
| 4571 | return preferredRotation; |
| 4572 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4573 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4574 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4575 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4576 | // Return landscape unless overridden. |
| 4577 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4578 | return preferredRotation; |
| 4579 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4580 | return mLandscapeRotation; |
| 4581 | |
| 4582 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4583 | // Return reverse portrait unless overridden. |
| 4584 | if (isAnyPortrait(preferredRotation)) { |
| 4585 | return preferredRotation; |
| 4586 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4587 | return mUpsideDownRotation; |
| 4588 | |
| 4589 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4590 | // Return seascape unless overridden. |
| 4591 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4592 | return preferredRotation; |
| 4593 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4594 | return mSeascapeRotation; |
| 4595 | |
| 4596 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4597 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4598 | // Return either landscape rotation. |
| 4599 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4600 | return preferredRotation; |
| 4601 | } |
| 4602 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 4603 | return lastRotation; |
| 4604 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4605 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4606 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4607 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4608 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4609 | // Return either portrait rotation. |
| 4610 | if (isAnyPortrait(preferredRotation)) { |
| 4611 | return preferredRotation; |
| 4612 | } |
| 4613 | if (isAnyPortrait(lastRotation)) { |
| 4614 | return lastRotation; |
| 4615 | } |
| 4616 | return mPortraitRotation; |
| 4617 | |
| 4618 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 4619 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 4620 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4621 | if (preferredRotation >= 0) { |
| 4622 | return preferredRotation; |
| 4623 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 4624 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 4625 | } |
| 4626 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 4627 | } |
| 4628 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4629 | @Override |
| 4630 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 4631 | switch (orientation) { |
| 4632 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 4633 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 4634 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 4635 | return isAnyPortrait(rotation); |
| 4636 | |
| 4637 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 4638 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 4639 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 4640 | return isLandscapeOrSeascape(rotation); |
| 4641 | |
| 4642 | default: |
| 4643 | return true; |
| 4644 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 4645 | } |
| 4646 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4647 | @Override |
| 4648 | public void setRotationLw(int rotation) { |
| 4649 | mOrientationListener.setCurrentRotation(rotation); |
| 4650 | } |
| 4651 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4652 | private boolean isLandscapeOrSeascape(int rotation) { |
| 4653 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4654 | } |
| 4655 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4656 | private boolean isAnyPortrait(int rotation) { |
| 4657 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4658 | } |
| 4659 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 4660 | public int getUserRotationMode() { |
| 4661 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 4662 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 4663 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 4664 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 4665 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4666 | |
| 4667 | // User rotation: to be used when all else fails in assigning an orientation to the device |
| 4668 | public void setUserRotationMode(int mode, int rot) { |
| 4669 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4670 | |
| 4671 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4672 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4673 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4674 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4675 | rot, |
| 4676 | UserHandle.USER_CURRENT); |
| 4677 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4678 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4679 | 0, |
| 4680 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4681 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4682 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4683 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4684 | 1, |
| 4685 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4686 | } |
| 4687 | } |
| 4688 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 4689 | public void setSafeMode(boolean safeMode) { |
| 4690 | mSafeMode = safeMode; |
| 4691 | performHapticFeedbackLw(null, safeMode |
| 4692 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 4693 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4694 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4695 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 4696 | static long[] getLongIntArray(Resources r, int resid) { |
| 4697 | int[] ar = r.getIntArray(resid); |
| 4698 | if (ar == null) { |
| 4699 | return null; |
| 4700 | } |
| 4701 | long[] out = new long[ar.length]; |
| 4702 | for (int i=0; i<ar.length; i++) { |
| 4703 | out[i] = ar[i]; |
| 4704 | } |
| 4705 | return out; |
| 4706 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4707 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4708 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4709 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4710 | public void systemReady() { |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 4711 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null); |
| 4712 | mKeyguardDelegate.onSystemReady(); |
| 4713 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 4714 | synchronized (mLock) { |
| 4715 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 4716 | mSystemReady = true; |
| 4717 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4718 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 4719 | public void run() { |
| 4720 | updateSettings(); |
| 4721 | } |
| 4722 | }); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4723 | } |
| 4724 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4725 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 4726 | /** {@inheritDoc} */ |
| 4727 | public void systemBooted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 4728 | if (mKeyguardDelegate != null) { |
| 4729 | mKeyguardDelegate.onBootCompleted(); |
| 4730 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 4731 | synchronized (mLock) { |
| 4732 | mSystemBooted = true; |
| 4733 | } |
| 4734 | } |
| 4735 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4736 | ProgressDialog mBootMsgDialog = null; |
| 4737 | |
| 4738 | /** {@inheritDoc} */ |
| 4739 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 4740 | mHandler.post(new Runnable() { |
| 4741 | @Override public void run() { |
| 4742 | if (mBootMsgDialog == null) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 4743 | mBootMsgDialog = new ProgressDialog(mContext) { |
| 4744 | // This dialog will consume all events coming in to |
| 4745 | // it, to avoid it trying to do things too early in boot. |
| 4746 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 4747 | return true; |
| 4748 | } |
| 4749 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 4750 | return true; |
| 4751 | } |
| 4752 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 4753 | return true; |
| 4754 | } |
| 4755 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 4756 | return true; |
| 4757 | } |
| 4758 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 4759 | return true; |
| 4760 | } |
| 4761 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 4762 | AccessibilityEvent event) { |
| 4763 | return true; |
| 4764 | } |
| 4765 | }; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4766 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 4767 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 4768 | mBootMsgDialog.setIndeterminate(true); |
| 4769 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4770 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4771 | mBootMsgDialog.getWindow().addFlags( |
| 4772 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 4773 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 4774 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 4775 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 4776 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 4777 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4778 | mBootMsgDialog.setCancelable(false); |
| 4779 | mBootMsgDialog.show(); |
| 4780 | } |
| 4781 | mBootMsgDialog.setMessage(msg); |
| 4782 | } |
| 4783 | }); |
| 4784 | } |
| 4785 | |
| 4786 | /** {@inheritDoc} */ |
| 4787 | public void hideBootMessages() { |
| 4788 | mHandler.post(new Runnable() { |
| 4789 | @Override public void run() { |
| 4790 | if (mBootMsgDialog != null) { |
| 4791 | mBootMsgDialog.dismiss(); |
| 4792 | mBootMsgDialog = null; |
| 4793 | } |
| 4794 | } |
| 4795 | }); |
| 4796 | } |
| 4797 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4798 | /** {@inheritDoc} */ |
| 4799 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4800 | // *************************************** |
| 4801 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 4802 | // *************************************** |
| 4803 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 4804 | // WITH ITS LOCKS HELD. |
| 4805 | // |
| 4806 | // This code must be VERY careful about the locks |
| 4807 | // it acquires. |
| 4808 | // In fact, the current code acquires way too many, |
| 4809 | // and probably has lurking deadlocks. |
| 4810 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4811 | synchronized (mScreenLockTimeout) { |
| 4812 | if (mLockScreenTimerActive) { |
| 4813 | // reset the timer |
| 4814 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 4815 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 4816 | } |
| 4817 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 4818 | } |
| 4819 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4820 | class ScreenLockTimeout implements Runnable { |
| 4821 | Bundle options; |
| 4822 | |
| 4823 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4824 | public void run() { |
| 4825 | synchronized (this) { |
| 4826 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4827 | if (mKeyguardDelegate != null) { |
| 4828 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4829 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4830 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4831 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4832 | } |
| 4833 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4834 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4835 | public void setLockOptions(Bundle options) { |
| 4836 | this.options = options; |
| 4837 | } |
| 4838 | } |
| 4839 | |
| 4840 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 4841 | |
| 4842 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 4843 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 4844 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4845 | if (options != null) { |
| 4846 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 4847 | // until the runnable actually executes. |
| 4848 | mScreenLockTimeout.setLockOptions(options); |
| 4849 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 4850 | mHandler.post(mScreenLockTimeout); |
| 4851 | } |
| 4852 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4853 | private void updateLockScreenTimeout() { |
| 4854 | synchronized (mScreenLockTimeout) { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4855 | boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly && |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4856 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4857 | if (mLockScreenTimerActive != enable) { |
| 4858 | if (enable) { |
| 4859 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
| 4860 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 4861 | } else { |
| 4862 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 4863 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 4864 | } |
| 4865 | mLockScreenTimerActive = enable; |
| 4866 | } |
| 4867 | } |
| 4868 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4869 | |
| 4870 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4871 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4872 | public void enableScreenAfterBoot() { |
| 4873 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4874 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4875 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4876 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 4877 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4878 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4879 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
| 4880 | mPowerManager.goToSleep(SystemClock.uptimeMillis()); |
| 4881 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4882 | } |
| 4883 | |
| 4884 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4885 | try { |
| 4886 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4887 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 4888 | } catch (RemoteException e) { |
| 4889 | // Ignore |
| 4890 | } |
| 4891 | } |
| 4892 | |
| 4893 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 4894 | try { |
| 4895 | //set orientation on WindowManager |
| 4896 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4897 | } catch (RemoteException e) { |
| 4898 | // Ignore |
| 4899 | } |
| 4900 | } |
| 4901 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4902 | /** |
| 4903 | * Return an Intent to launch the currently active dock app as home. Returns |
| 4904 | * null if the standard home should be launched, which is the case if any of the following is |
| 4905 | * true: |
| 4906 | * <ul> |
| 4907 | * <li>The device is not in either car mode or desk mode |
| 4908 | * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false |
| 4909 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 4910 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 4911 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 4912 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4913 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4914 | */ |
| 4915 | Intent createHomeDockIntent() { |
| 4916 | Intent intent = null; |
| 4917 | |
| 4918 | // What home does is based on the mode, not the dock state. That |
| 4919 | // is, when in car mode you should be taken to car home regardless |
| 4920 | // of whether we are actually in a car dock. |
| 4921 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
| 4922 | if (ENABLE_CAR_DOCK_HOME_CAPTURE) { |
| 4923 | intent = mCarDockIntent; |
| 4924 | } |
| 4925 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 4926 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 4927 | intent = mDeskDockIntent; |
| 4928 | } |
| 4929 | } |
| 4930 | |
| 4931 | if (intent == null) { |
| 4932 | return null; |
| 4933 | } |
| 4934 | |
| 4935 | ActivityInfo ai = null; |
| 4936 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 4937 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 4938 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 4939 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4940 | if (info != null) { |
| 4941 | ai = info.activityInfo; |
| 4942 | } |
| 4943 | if (ai != null |
| 4944 | && ai.metaData != null |
| 4945 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 4946 | intent = new Intent(intent); |
| 4947 | intent.setClassName(ai.packageName, ai.name); |
| 4948 | return intent; |
| 4949 | } |
| 4950 | |
| 4951 | return null; |
| 4952 | } |
| 4953 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4954 | void startDockOrHome() { |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 4955 | awakenDreams(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4956 | |
| 4957 | Intent dock = createHomeDockIntent(); |
| 4958 | if (dock != null) { |
| 4959 | try { |
| 4960 | mContext.startActivityAsUser(dock, UserHandle.CURRENT); |
| 4961 | return; |
| 4962 | } catch (ActivityNotFoundException e) { |
| 4963 | } |
| 4964 | } |
| 4965 | |
Dianne Hackborn | d888399 | 2012-09-07 15:58:52 -0700 | [diff] [blame] | 4966 | mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4967 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4968 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4969 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4970 | * goes to the home screen |
| 4971 | * @return whether it did anything |
| 4972 | */ |
| 4973 | boolean goHome() { |
| 4974 | if (false) { |
| 4975 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 4976 | try { |
| 4977 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 4978 | } catch (RemoteException e) { |
| 4979 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 4980 | sendCloseSystemWindows(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4981 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4982 | } else { |
| 4983 | // This code brings home to the front or, if it is already |
| 4984 | // at the front, puts the device to sleep. |
| 4985 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 4986 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 4987 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 4988 | Log.d(TAG, "UTS-TEST-MODE"); |
| 4989 | } else { |
| 4990 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 4991 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4992 | Intent dock = createHomeDockIntent(); |
| 4993 | if (dock != null) { |
| 4994 | int result = ActivityManagerNative.getDefault() |
| 4995 | .startActivityAsUser(null, null, dock, |
| 4996 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 4997 | null, null, 0, |
| 4998 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
| 4999 | null, null, null, UserHandle.USER_CURRENT); |
| 5000 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 5001 | return false; |
| 5002 | } |
| 5003 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5004 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5005 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5006 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5007 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5008 | null, null, 0, |
| 5009 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Dianne Hackborn | 5e03e2c | 2012-09-06 14:21:19 -0700 | [diff] [blame] | 5010 | null, null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5011 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5012 | return false; |
| 5013 | } |
| 5014 | } catch (RemoteException ex) { |
| 5015 | // bummer, the activity manager, which is in this process, is dead |
| 5016 | } |
| 5017 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5018 | return true; |
| 5019 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5020 | |
| 5021 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5022 | public void setCurrentOrientationLw(int newOrientation) { |
| 5023 | synchronized (mLock) { |
| 5024 | if (newOrientation != mCurrentAppOrientation) { |
| 5025 | mCurrentAppOrientation = newOrientation; |
| 5026 | updateOrientationListenerLp(); |
| 5027 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5028 | } |
| 5029 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5030 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 5031 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 5032 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 5033 | return; |
| 5034 | } |
| 5035 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 5036 | Context.AUDIO_SERVICE); |
| 5037 | if (audioManager.isSilentMode()) { |
| 5038 | return; |
| 5039 | } |
| 5040 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 5041 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 5042 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 5043 | ringTone.play(); |
| 5044 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5045 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 5046 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 5047 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 5048 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 5049 | } |
| 5050 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5051 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5052 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 5053 | if (!mVibrator.hasVibrator()) { |
| 5054 | return false; |
| 5055 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5056 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 5057 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5058 | if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotHidden())) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5059 | return false; |
| 5060 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5061 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5062 | switch (effectId) { |
| 5063 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5064 | pattern = mLongPressVibePattern; |
| 5065 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5066 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5067 | pattern = mVirtualKeyVibePattern; |
| 5068 | break; |
| 5069 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 5070 | pattern = mKeyboardTapVibePattern; |
| 5071 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 5072 | case HapticFeedbackConstants.CLOCK_TICK: |
| 5073 | pattern = mClockTickVibePattern; |
| 5074 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5075 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5076 | pattern = mSafeModeDisabledVibePattern; |
| 5077 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5078 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5079 | pattern = mSafeModeEnabledVibePattern; |
| 5080 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5081 | default: |
| 5082 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5083 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5084 | int owningUid; |
| 5085 | String owningPackage; |
| 5086 | if (win != null) { |
| 5087 | owningUid = win.getOwningUid(); |
| 5088 | owningPackage = win.getOwningPackage(); |
| 5089 | } else { |
| 5090 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 5091 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5092 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5093 | if (pattern.length == 1) { |
| 5094 | // One-shot vibration |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 5095 | mVibrator.vibrate(owningUid, owningPackage, pattern[0], AudioManager.STREAM_SYSTEM); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5096 | } else { |
| 5097 | // Pattern vibration |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 5098 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1, AudioManager.STREAM_SYSTEM); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5099 | } |
| 5100 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5101 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5102 | |
| 5103 | @Override |
| 5104 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 5105 | } |
| 5106 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5107 | @Override |
| 5108 | public void keepScreenOnStoppedLw() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5109 | if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotHidden()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 5110 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5111 | } |
| 5112 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 5113 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5114 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5115 | // If there is no window focused, there will be nobody to handle the events |
| 5116 | // anyway, so just hang on in whatever state we're in until things settle down. |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5117 | WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState; |
| 5118 | if (win == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5119 | return 0; |
| 5120 | } |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5121 | if (win.getAttrs().type == TYPE_KEYGUARD && mHideLockScreen == true) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5122 | // We are updating at a point where the keyguard has gotten |
| 5123 | // focus, but we were last in a state where the top window is |
| 5124 | // hiding it. This is probably because the keyguard as been |
| 5125 | // shown while the top window was displayed, so we want to ignore |
| 5126 | // it here because this is just a very transient change and it |
| 5127 | // will quickly lose focus once it correctly gets hidden. |
| 5128 | return 0; |
| 5129 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5130 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 5131 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5132 | & ~mResettingSystemUiFlags |
| 5133 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5134 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5135 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5136 | } |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5137 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5138 | final int diff = visibility ^ mLastSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5139 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 5140 | if (diff == 0 && mLastFocusNeedsMenu == needsMenu |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5141 | && mFocusedApp == win.getAppToken()) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5142 | return 0; |
| 5143 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5144 | mLastSystemUiFlags = visibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 5145 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5146 | mFocusedApp = win.getAppToken(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5147 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5148 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5149 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 5150 | try { |
| 5151 | IStatusBarService statusbar = getStatusBarService(); |
| 5152 | if (statusbar != null) { |
| 5153 | statusbar.setSystemUiVisibility(visibility, 0xffffffff); |
| 5154 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5155 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 5156 | } catch (RemoteException e) { |
| 5157 | // re-acquire status bar service next time it is needed. |
| 5158 | mStatusBarService = null; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5159 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5160 | } |
| 5161 | }); |
| 5162 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5163 | } |
| 5164 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5165 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5166 | // apply translucent bar vis flags |
| 5167 | WindowState transWin = mKeyguard != null && mKeyguard.isVisibleLw() && !mHideLockScreen |
| 5168 | ? mKeyguard |
| 5169 | : mTopFullscreenOpaqueWindowState; |
| 5170 | vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 5171 | vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 5172 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5173 | // prevent status bar interaction from clearing certain flags |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5174 | boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5175 | if (statusBarHasFocus) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5176 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 5177 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 5178 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5179 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5180 | | View.STATUS_BAR_TRANSLUCENT |
| 5181 | | View.NAVIGATION_BAR_TRANSLUCENT; |
| 5182 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5183 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5184 | |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 5185 | if (!areTranslucentBarsAllowed()) { |
| 5186 | vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5187 | } |
| 5188 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5189 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5190 | boolean immersiveSticky = |
| 5191 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5192 | boolean hideStatusBarWM = |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5193 | mTopFullscreenOpaqueWindowState != null && |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5194 | (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5195 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
| 5196 | boolean hideStatusBarSysui = |
| 5197 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5198 | boolean hideNavBarSysui = |
| 5199 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5200 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5201 | boolean transientStatusBarAllowed = |
| 5202 | mStatusBar != null && ( |
| 5203 | hideStatusBarWM |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5204 | || (hideStatusBarSysui && immersiveSticky) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5205 | || statusBarHasFocus); |
| 5206 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5207 | boolean transientNavBarAllowed = |
| 5208 | mNavigationBar != null && |
| 5209 | hideNavBarSysui && immersiveSticky; |
| 5210 | |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 5211 | boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5212 | && !transientStatusBarAllowed && hideStatusBarSysui; |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 5213 | boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5214 | && !transientNavBarAllowed; |
| 5215 | if (denyTransientStatus || denyTransientNav) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5216 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5217 | clearClearableFlagsLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5218 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5219 | |
| 5220 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 5221 | |
| 5222 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5223 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 5224 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 5225 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5226 | final String pkg = win.getOwningPackage(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5227 | mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 5228 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5229 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5230 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 5231 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5232 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5233 | } |
| 5234 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5235 | private void clearClearableFlagsLw() { |
| 5236 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 5237 | if (newVal != mResettingSystemUiFlags) { |
| 5238 | mResettingSystemUiFlags = newVal; |
| 5239 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 5240 | } |
| 5241 | } |
| 5242 | |
| 5243 | private boolean isImmersiveMode(int vis) { |
| 5244 | final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 5245 | return mNavigationBar != null |
| 5246 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 5247 | && (vis & flags) != 0 |
| 5248 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 5249 | } |
| 5250 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5251 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 5252 | * @return whether the navigation or status bar can be made translucent |
| 5253 | * |
| 5254 | * This should return true unless touch exploration is not enabled or |
| 5255 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5256 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 5257 | private boolean areTranslucentBarsAllowed() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 5258 | return mTranslucentDecorEnabled |
| 5259 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5260 | } |
| 5261 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 5262 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 5263 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5264 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 5265 | public boolean hasNavigationBar() { |
| 5266 | return mHasNavigationBar; |
| 5267 | } |
| 5268 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5269 | @Override |
| 5270 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 5271 | mLastInputMethodWindow = ime; |
| 5272 | mLastInputMethodTargetWindow = target; |
| 5273 | } |
| 5274 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5275 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 5276 | public int getInputMethodWindowVisibleHeightLw() { |
| 5277 | return mDockBottom - mCurBottom; |
| 5278 | } |
| 5279 | |
| 5280 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5281 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 5282 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5283 | if (mKeyguardDelegate != null) { |
| 5284 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5285 | } |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 5286 | if (mStatusBarService != null) { |
| 5287 | try { |
| 5288 | mStatusBarService.setCurrentUser(newUserId); |
| 5289 | } catch (RemoteException e) { |
| 5290 | // oh well |
| 5291 | } |
| 5292 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5293 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5294 | } |
| 5295 | |
| 5296 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 5297 | public boolean canMagnifyWindow(int windowType) { |
| 5298 | switch (windowType) { |
| 5299 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 5300 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 5301 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 5302 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 5303 | return false; |
| 5304 | } |
| 5305 | } |
| 5306 | return true; |
| 5307 | } |
| 5308 | |
| 5309 | @Override |
| 5310 | public boolean isTopLevelWindow(int windowType) { |
| 5311 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 5312 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 5313 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 5314 | } |
| 5315 | return true; |
| 5316 | } |
| 5317 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 5318 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 5319 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5320 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5321 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 5322 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 5323 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5324 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
| 5325 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5326 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 5327 | || mForceClearedSystemUiFlags != 0) { |
| 5328 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 5329 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 5330 | pw.print(" mResettingSystemUiFlags=0x"); |
| 5331 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 5332 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 5333 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5334 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 5335 | if (mLastFocusNeedsMenu) { |
| 5336 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 5337 | pw.println(mLastFocusNeedsMenu); |
| 5338 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 5339 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5340 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 5341 | pw.print(" mDockMode="); pw.print(mDockMode); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5342 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 5343 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 5344 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 5345 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5346 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5347 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5348 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 5349 | pw.print(mCarDockEnablesAccelerometer); |
| 5350 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 5351 | pw.println(mDeskDockEnablesAccelerometer); |
| 5352 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 5353 | pw.print(mLidKeyboardAccessibility); |
| 5354 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5355 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
| 5356 | pw.print(prefix); pw.print("mLongPressOnPowerBehavior="); |
| 5357 | pw.print(mLongPressOnPowerBehavior); |
| 5358 | pw.print(" mHasSoftInput="); pw.println(mHasSoftInput); |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 5359 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 5360 | pw.print(" mScreenOnFully="); pw.print(mScreenOnFully); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5361 | pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 5362 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 5363 | pw.print(","); pw.print(mOverscanScreenTop); |
| 5364 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 5365 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 5366 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 5367 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 5368 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 5369 | pw.print(" top="); pw.print(mOverscanTop); |
| 5370 | pw.print(" right="); pw.print(mOverscanRight); |
| 5371 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 5372 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 5373 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 5374 | pw.print(mRestrictedOverscanScreenLeft); |
| 5375 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 5376 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 5377 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5378 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 5379 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 5380 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 5381 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 5382 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 5383 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 5384 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 5385 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 5386 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 5387 | pw.print(","); pw.print(mStableFullscreenTop); |
| 5388 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 5389 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5390 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 5391 | pw.print(","); pw.print(mStableTop); |
| 5392 | pw.print(")-("); pw.print(mStableRight); |
| 5393 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 5394 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 5395 | pw.print(","); pw.print(mSystemTop); |
| 5396 | pw.print(")-("); pw.print(mSystemRight); |
| 5397 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5398 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 5399 | pw.print(","); pw.print(mCurTop); |
| 5400 | pw.print(")-("); pw.print(mCurRight); |
| 5401 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 5402 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 5403 | pw.print(","); pw.print(mContentTop); |
| 5404 | pw.print(")-("); pw.print(mContentRight); |
| 5405 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
| 5406 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 5407 | pw.print(","); pw.print(mDockTop); |
| 5408 | pw.print(")-("); pw.print(mDockRight); |
| 5409 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 5410 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 5411 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5412 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 5413 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
| 5414 | pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5415 | if (mLastInputMethodWindow != null) { |
| 5416 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 5417 | pw.println(mLastInputMethodWindow); |
| 5418 | } |
| 5419 | if (mLastInputMethodTargetWindow != null) { |
| 5420 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 5421 | pw.println(mLastInputMethodTargetWindow); |
| 5422 | } |
| 5423 | if (mStatusBar != null) { |
| 5424 | pw.print(prefix); pw.print("mStatusBar="); |
| 5425 | pw.println(mStatusBar); |
| 5426 | } |
| 5427 | if (mNavigationBar != null) { |
| 5428 | pw.print(prefix); pw.print("mNavigationBar="); |
| 5429 | pw.println(mNavigationBar); |
| 5430 | } |
| 5431 | if (mKeyguard != null) { |
| 5432 | pw.print(prefix); pw.print("mKeyguard="); |
| 5433 | pw.println(mKeyguard); |
| 5434 | } |
| 5435 | if (mFocusedWindow != null) { |
| 5436 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 5437 | pw.println(mFocusedWindow); |
| 5438 | } |
| 5439 | if (mFocusedApp != null) { |
| 5440 | pw.print(prefix); pw.print("mFocusedApp="); |
| 5441 | pw.println(mFocusedApp); |
| 5442 | } |
| 5443 | if (mWinDismissingKeyguard != null) { |
| 5444 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 5445 | pw.println(mWinDismissingKeyguard); |
| 5446 | } |
| 5447 | if (mTopFullscreenOpaqueWindowState != null) { |
| 5448 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 5449 | pw.println(mTopFullscreenOpaqueWindowState); |
| 5450 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5451 | if (mForcingShowNavBar) { |
| 5452 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 5453 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 5454 | pw.println(mForcingShowNavBarLayer); |
| 5455 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5456 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5457 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5458 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 5459 | pw.print(" mForceStatusBarFromKeyguard="); |
| 5460 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5461 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5462 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5463 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 5464 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 5465 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 5466 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 5467 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 5468 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 5469 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 5470 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 5471 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 5472 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 5473 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5474 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 5475 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 5476 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5477 | mStatusBarController.dump(pw, prefix); |
| 5478 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5479 | PolicyControl.dump(prefix, pw); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5480 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5481 | } |