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; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 99 | import com.android.internal.policy.IKeyguardService; |
| 100 | import com.android.internal.policy.IKeyguardServiceConstants; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 101 | import com.android.internal.policy.PolicyManager; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 102 | import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 103 | import com.android.internal.statusbar.IStatusBarService; |
| 104 | import com.android.internal.telephony.ITelephony; |
| 105 | import com.android.internal.widget.PointerLocationView; |
| 106 | |
| 107 | import java.io.File; |
| 108 | import java.io.FileReader; |
| 109 | import java.io.IOException; |
| 110 | import java.io.PrintWriter; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 111 | import java.util.HashSet; |
Craig Mautner | ae44659 | 2012-12-06 19:05:05 -0800 | [diff] [blame] | 112 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 113 | import static android.view.WindowManager.LayoutParams.*; |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 114 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT; |
| 115 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN; |
| 116 | import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 117 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 118 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 119 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 120 | * introduces a new method suffix, Lp, for an internal lock of the |
| 121 | * PhoneWindowManager. This is used to protect some internal state, and |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 122 | * 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] | 123 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 124 | */ |
| 125 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 126 | static final String TAG = "WindowManager"; |
| 127 | static final boolean DEBUG = false; |
Joe Onorato | 43a1765 | 2011-04-06 19:22:23 -0700 | [diff] [blame] | 128 | static final boolean localLOGV = false; |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 129 | static final boolean DEBUG_LAYOUT = false; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 130 | static final boolean DEBUG_INPUT = false; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 131 | static final boolean DEBUG_STARTING_WINDOW = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 132 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 133 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 134 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 135 | // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key. |
| 136 | // No longer recommended for desk docks; still useful in car docks. |
| 137 | static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true; |
| 138 | static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false; |
| 139 | |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 140 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 141 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 142 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 143 | static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3; |
Michael Jurka | 3b1fc47 | 2011-06-13 10:54:40 -0700 | [diff] [blame] | 144 | |
| 145 | // These need to match the documentation/constant in |
| 146 | // core/res/res/values/config.xml |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 147 | static final int LONG_PRESS_HOME_NOTHING = 0; |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 148 | static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 149 | static final int LONG_PRESS_HOME_ASSIST = 2; |
| 150 | |
| 151 | static final int DOUBLE_TAP_HOME_NOTHING = 0; |
| 152 | static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 153 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 154 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 155 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 156 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 157 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 158 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 159 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 160 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 161 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 162 | static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 163 | static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist"; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 164 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 165 | /** |
| 166 | * These are the system UI flags that, when changing, can cause the layout |
| 167 | * of the screen to change. |
| 168 | */ |
| 169 | static final int SYSTEM_UI_CHANGING_LAYOUT = |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 170 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | 7f4820a | 2013-10-08 12:54:35 -0400 | [diff] [blame] | 171 | | View.SYSTEM_UI_FLAG_FULLSCREEN |
| 172 | | View.STATUS_BAR_TRANSLUCENT |
| 173 | | View.NAVIGATION_BAR_TRANSLUCENT; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 174 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 175 | /** |
| 176 | * Keyguard stuff |
| 177 | */ |
| 178 | private WindowState mKeyguardScrim; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 179 | private boolean mKeyguardHidden; |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 180 | private boolean mKeyguardDrawn; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 181 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 182 | /* Table of Application Launch keys. Maps from key codes to intent categories. |
| 183 | * |
| 184 | * These are special keys that are used to launch particular kinds of applications, |
| 185 | * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C) |
| 186 | * usage page. We don't support quite that many yet... |
| 187 | */ |
| 188 | static SparseArray<String> sApplicationLaunchKeyCategories; |
| 189 | static { |
| 190 | sApplicationLaunchKeyCategories = new SparseArray<String>(); |
| 191 | sApplicationLaunchKeyCategories.append( |
| 192 | KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER); |
| 193 | sApplicationLaunchKeyCategories.append( |
| 194 | KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL); |
| 195 | sApplicationLaunchKeyCategories.append( |
| 196 | KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS); |
| 197 | sApplicationLaunchKeyCategories.append( |
| 198 | KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR); |
| 199 | sApplicationLaunchKeyCategories.append( |
| 200 | KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC); |
| 201 | sApplicationLaunchKeyCategories.append( |
| 202 | KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR); |
| 203 | } |
| 204 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 205 | /** |
| 206 | * Lock protecting internal state. Must not call out into window |
| 207 | * manager with lock held. (This lock will be acquired in places |
| 208 | * where the window manager is calling in with its own lock held.) |
| 209 | */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 210 | private final Object mLock = new Object(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 211 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 212 | Context mContext; |
| 213 | IWindowManager mWindowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 214 | WindowManagerFuncs mWindowManagerFuncs; |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 215 | PowerManager mPowerManager; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 216 | IStatusBarService mStatusBarService; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 217 | boolean mPreloadedRecentApps; |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 218 | final Object mServiceAquireLock = new Object(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 219 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 220 | SearchManager mSearchManager; |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 221 | AccessibilityManager mAccessibilityManager; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 222 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 223 | // Vibrator pattern for haptic feedback of a long press. |
| 224 | long[] mLongPressVibePattern; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 225 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 226 | // Vibrator pattern for haptic feedback of virtual key press. |
| 227 | long[] mVirtualKeyVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 228 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 229 | // Vibrator pattern for a short vibration. |
| 230 | long[] mKeyboardTapVibePattern; |
| 231 | |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 232 | // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock. |
| 233 | long[] mClockTickVibePattern; |
| 234 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 235 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 236 | long[] mSafeModeDisabledVibePattern; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 237 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 238 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 239 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 240 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 241 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 242 | boolean mEnableShiftMenuBugReports = false; |
Mike Lockwood | d747dc8 | 2011-09-13 16:28:22 -0400 | [diff] [blame] | 243 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 244 | boolean mSafeMode; |
| 245 | WindowState mStatusBar = null; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 246 | int mStatusBarHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 247 | WindowState mNavigationBar = null; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 248 | boolean mHasNavigationBar = false; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 249 | boolean mCanHideNavigationBar = false; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 250 | boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side? |
| 251 | boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*? |
| 252 | int[] mNavigationBarHeightForRotation = new int[4]; |
| 253 | int[] mNavigationBarWidthForRotation = new int[4]; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 254 | |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 255 | KeyguardServiceDelegate mKeyguardDelegate; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 256 | GlobalActions mGlobalActions; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 257 | volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread |
| 258 | boolean mPendingPowerKeyUpCanceled; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 259 | Handler mHandler; |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 260 | WindowState mLastInputMethodWindow = null; |
| 261 | WindowState mLastInputMethodTargetWindow = null; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 262 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 263 | static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0; |
| 264 | static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1; |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 265 | static final int RECENT_APPS_BEHAVIOR_DISMISS = 2; |
| 266 | static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 3; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 267 | |
| 268 | RecentApplicationsDialog mRecentAppsDialog; |
| 269 | int mRecentAppsDialogHeldModifiers; |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 270 | boolean mLanguageSwitchKeyPressed; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 271 | |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 272 | int mLidState = LID_ABSENT; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 273 | boolean mHaveBuiltInKeyboard; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 274 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 275 | boolean mSystemReady; |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 276 | boolean mSystemBooted; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 277 | boolean mHdmiPlugged; |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 278 | int mUiMode; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 279 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 280 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 281 | int mCarDockRotation; |
| 282 | int mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 283 | int mUndockedHdmiRotation; |
| 284 | int mDemoHdmiRotation; |
| 285 | boolean mDemoHdmiRotationLock; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 286 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 287 | // Default display does not rotate, apps that require non-default orientation will have to |
| 288 | // have the orientation emulated. |
| 289 | private boolean mForceDefaultOrientation = false; |
| 290 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 291 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 292 | int mUserRotation = Surface.ROTATION_0; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 293 | boolean mAccelerometerDefault; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 294 | |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 295 | boolean mSupportAutoRotation; |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 296 | int mAllowAllRotations = -1; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 297 | boolean mCarDockEnablesAccelerometer; |
| 298 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 299 | int mLidKeyboardAccessibility; |
| 300 | int mLidNavigationAccessibility; |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 301 | boolean mLidControlsSleep; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 302 | int mLongPressOnPowerBehavior = -1; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 303 | boolean mScreenOnEarly = false; |
| 304 | boolean mScreenOnFully = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 305 | boolean mOrientationSensorEnabled = false; |
| 306 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 307 | boolean mHasSoftInput = false; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 308 | boolean mTranslucentDecorEnabled = true; |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 309 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 310 | int mPointerLocationMode = 0; // guarded by mLock |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 311 | |
| 312 | // The last window we were told about in focusChanged. |
| 313 | WindowState mFocusedWindow; |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 314 | IApplicationToken mFocusedApp; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 315 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 316 | PointerLocationView mPointerLocationView; |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 317 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 318 | // The current size of the screen; really; extends into the overscan area of |
| 319 | // the screen and doesn't account for any system elements like the status bar. |
| 320 | int mOverscanScreenLeft, mOverscanScreenTop; |
| 321 | int mOverscanScreenWidth, mOverscanScreenHeight; |
| 322 | // The current visible size of the screen; really; (ir)regardless of whether the status |
| 323 | // bar can be hidden but not extending into the overscan area. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 324 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 325 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 326 | // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate. |
| 327 | int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop; |
| 328 | int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 329 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 330 | // if the status bar can't be hidden; in that case it effectively carves out |
| 331 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 332 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 333 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 334 | // During layout, the current screen borders accounting for any currently |
| 335 | // visible system UI elements. |
| 336 | int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 337 | // For applications requesting stable content insets, these are them. |
| 338 | int mStableLeft, mStableTop, mStableRight, mStableBottom; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 339 | // For applications requesting stable content insets but have also set the |
| 340 | // fullscreen window flag, these are the stable dimensions without the status bar. |
| 341 | int mStableFullscreenLeft, mStableFullscreenTop; |
| 342 | int mStableFullscreenRight, mStableFullscreenBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 343 | // During layout, the current screen borders with all outer decoration |
| 344 | // (status bar, input method dock) accounted for. |
| 345 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 346 | // During layout, the frame in which content should be displayed |
| 347 | // to the user, accounting for all screen decoration except for any |
| 348 | // space they deem as available for other content. This is usually |
| 349 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 350 | // content insets. |
| 351 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 352 | // 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] | 353 | // windows are placed. |
| 354 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 355 | // During layout, the layer at which the doc window is placed. |
| 356 | int mDockLayer; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 357 | // During layout, this is the layer of the status bar. |
| 358 | int mStatusBarLayer; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 359 | int mLastSystemUiFlags; |
| 360 | // Bits that we are in the process of clearing, so we want to prevent |
| 361 | // them from being set by applications until everything has been updated |
| 362 | // to have them clear. |
| 363 | int mResettingSystemUiFlags = 0; |
| 364 | // Bits that we are currently always keeping cleared. |
| 365 | int mForceClearedSystemUiFlags = 0; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 366 | // What we last reported to system UI about whether the compatibility |
| 367 | // menu needs to be displayed. |
| 368 | boolean mLastFocusNeedsMenu = false; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 369 | |
| 370 | FakeWindow mHideNavFakeWindow = null; |
| 371 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 372 | static final Rect mTmpParentFrame = new Rect(); |
| 373 | static final Rect mTmpDisplayFrame = new Rect(); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 374 | static final Rect mTmpOverscanFrame = new Rect(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 375 | static final Rect mTmpContentFrame = new Rect(); |
| 376 | static final Rect mTmpVisibleFrame = new Rect(); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 377 | static final Rect mTmpDecorFrame = new Rect(); |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 378 | static final Rect mTmpNavigationFrame = new Rect(); |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 379 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 380 | WindowState mTopFullscreenOpaqueWindowState; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 381 | HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>(); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 382 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 383 | boolean mForceStatusBar; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 384 | boolean mForceStatusBarFromKeyguard; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 385 | boolean mHideLockScreen; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 386 | boolean mForcingShowNavBar; |
| 387 | int mForcingShowNavBarLayer; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 388 | |
| 389 | // States of keyguard dismiss. |
| 390 | private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed. |
| 391 | private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed. |
| 392 | private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed. |
| 393 | int mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
| 394 | |
| 395 | /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only |
| 396 | * be done once per window. */ |
| 397 | private WindowState mWinDismissingKeyguard; |
| 398 | |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 399 | boolean mShowingLockscreen; |
| 400 | boolean mShowingDream; |
| 401 | boolean mDreamingLockscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 402 | boolean mHomePressed; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 403 | boolean mHomeConsumed; |
| 404 | boolean mHomeDoubleTapPending; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 405 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 406 | Intent mCarDockIntent; |
| 407 | Intent mDeskDockIntent; |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 408 | boolean mSearchKeyShortcutPending; |
| 409 | boolean mConsumeSearchKeyUp; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 410 | boolean mAssistKeyLongPressed; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 411 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 412 | // support for activating the lock screen while the screen is on |
| 413 | boolean mAllowLockscreenWhenOn; |
| 414 | int mLockScreenTimeout; |
| 415 | boolean mLockScreenTimerActive; |
| 416 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 417 | // 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] | 418 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 419 | |
| 420 | // Behavior of POWER button while in-call and screen on. |
| 421 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 422 | int mIncallPowerBehavior; |
| 423 | |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 424 | Display mDisplay; |
| 425 | |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 426 | int mLandscapeRotation = 0; // default landscape rotation |
| 427 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 428 | int mPortraitRotation = 0; // default portrait rotation |
| 429 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 430 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 431 | int mOverscanLeft = 0; |
| 432 | int mOverscanTop = 0; |
| 433 | int mOverscanRight = 0; |
| 434 | int mOverscanBottom = 0; |
| 435 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 436 | // What we do when the user long presses on home |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 437 | private int mLongPressOnHomeBehavior; |
| 438 | |
| 439 | // What we do when the user double-taps on home |
| 440 | private int mDoubleTapOnHomeBehavior; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 441 | |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 442 | // Screenshot trigger states |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 443 | // Time to volume and power must be pressed within this interval of each other. |
| 444 | private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150; |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 445 | // Increase the chord delay when taking a screenshot from the keyguard |
| 446 | private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f; |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 447 | private boolean mScreenshotChordEnabled; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 448 | private boolean mVolumeDownKeyTriggered; |
| 449 | private long mVolumeDownKeyTime; |
| 450 | private boolean mVolumeDownKeyConsumedByScreenshotChord; |
| 451 | private boolean mVolumeUpKeyTriggered; |
| 452 | private boolean mPowerKeyTriggered; |
| 453 | private long mPowerKeyTime; |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 454 | |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 455 | /* The number of steps between min and max brightness */ |
| 456 | private static final int BRIGHTNESS_STEPS = 10; |
| 457 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 458 | SettingsObserver mSettingsObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 459 | ShortcutManager mShortcutManager; |
| 460 | PowerManager.WakeLock mBroadcastWakeLock; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 461 | boolean mHavePendingMediaKeyRepeatWithWakeLock; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 462 | |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 463 | private int mCurrentUserId; |
| 464 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 465 | // Maps global key codes to the components that will handle them. |
| 466 | private GlobalKeyManager mGlobalKeyManager; |
| 467 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 468 | // Fallback actions by key code. |
| 469 | private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions = |
| 470 | new SparseArray<KeyCharacterMap.FallbackAction>(); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 471 | |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 472 | private static final int MSG_ENABLE_POINTER_LOCATION = 1; |
| 473 | private static final int MSG_DISABLE_POINTER_LOCATION = 2; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 474 | private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3; |
| 475 | 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] | 476 | |
| 477 | private class PolicyHandler extends Handler { |
| 478 | @Override |
| 479 | public void handleMessage(Message msg) { |
| 480 | switch (msg.what) { |
| 481 | case MSG_ENABLE_POINTER_LOCATION: |
| 482 | enablePointerLocation(); |
| 483 | break; |
| 484 | case MSG_DISABLE_POINTER_LOCATION: |
| 485 | disablePointerLocation(); |
| 486 | break; |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 487 | case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK: |
| 488 | dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj); |
| 489 | break; |
| 490 | case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK: |
| 491 | dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj); |
| 492 | break; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | } |
| 496 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 497 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 498 | @Override |
| 499 | public void onUEvent(UEventObserver.UEvent event) { |
| 500 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 501 | } |
| 502 | }; |
| 503 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 504 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 505 | SettingsObserver(Handler handler) { |
| 506 | super(handler); |
| 507 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 508 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 509 | void observe() { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 510 | // Observe all users' changes |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 511 | ContentResolver resolver = mContext.getContentResolver(); |
| 512 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 513 | Settings.System.END_BUTTON_BEHAVIOR), false, this, |
| 514 | UserHandle.USER_ALL); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 515 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 516 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this, |
| 517 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 518 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 519 | Settings.System.ACCELEROMETER_ROTATION), false, this, |
| 520 | UserHandle.USER_ALL); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 521 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 522 | Settings.System.USER_ROTATION), false, this, |
| 523 | UserHandle.USER_ALL); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 524 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 525 | Settings.System.SCREEN_OFF_TIMEOUT), false, this, |
| 526 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 527 | resolver.registerContentObserver(Settings.System.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 528 | Settings.System.POINTER_LOCATION), false, this, |
| 529 | UserHandle.USER_ALL); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 530 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 531 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this, |
| 532 | UserHandle.USER_ALL); |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 533 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 534 | Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 535 | UserHandle.USER_ALL); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 536 | resolver.registerContentObserver(Settings.Global.getUriFor( |
| 537 | Settings.Global.POLICY_CONTROL), false, this, |
| 538 | UserHandle.USER_ALL); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 539 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 543 | updateSettings(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 544 | updateRotation(false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 545 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 546 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 547 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 548 | class MyOrientationListener extends WindowOrientationListener { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 549 | MyOrientationListener(Context context, Handler handler) { |
| 550 | super(context, handler); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 551 | } |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 552 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 553 | @Override |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 554 | public void onProposedRotationChanged(int rotation) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 555 | if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 556 | updateRotation(false); |
| 557 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 558 | } |
| 559 | MyOrientationListener mOrientationListener; |
| 560 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 561 | private final BarController mStatusBarController = new BarController("StatusBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 562 | View.STATUS_BAR_TRANSIENT, |
| 563 | View.STATUS_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 564 | View.STATUS_BAR_TRANSLUCENT, |
| 565 | StatusBarManager.WINDOW_STATUS_BAR, |
| 566 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 567 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 568 | private final BarController mNavigationBarController = new BarController("NavigationBar", |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 569 | View.NAVIGATION_BAR_TRANSIENT, |
| 570 | View.NAVIGATION_BAR_UNHIDE, |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 571 | View.NAVIGATION_BAR_TRANSLUCENT, |
| 572 | StatusBarManager.WINDOW_NAVIGATION_BAR, |
| 573 | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 574 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 575 | private ImmersiveModeConfirmation mImmersiveModeConfirmation; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 576 | |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 577 | private SystemGesturesPointerEventListener mSystemGestures; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 578 | |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 579 | IStatusBarService getStatusBarService() { |
| 580 | synchronized (mServiceAquireLock) { |
| 581 | if (mStatusBarService == null) { |
| 582 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 583 | ServiceManager.getService("statusbar")); |
| 584 | } |
| 585 | return mStatusBarService; |
| 586 | } |
| 587 | } |
| 588 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 589 | /* |
| 590 | * We always let the sensor be switched on by default except when |
| 591 | * the user has explicitly disabled sensor based rotation or when the |
| 592 | * screen is switched off. |
| 593 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 594 | boolean needSensorRunningLp() { |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 595 | if (mSupportAutoRotation) { |
| 596 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 597 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 598 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 599 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
| 600 | // If the application has explicitly requested to follow the |
| 601 | // orientation, then we need to turn the sensor on. |
| 602 | return true; |
| 603 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 604 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 605 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 606 | (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 607 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 608 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 609 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 610 | // orientation management, |
| 611 | return true; |
| 612 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 613 | if (mUserRotationMode == USER_ROTATION_LOCKED) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 614 | // If the setting for using the sensor by default is enabled, then |
| 615 | // we will always leave it on. Note that the user could go to |
| 616 | // a window that forces an orientation that does not use the |
| 617 | // sensor and in theory we could turn it off... however, when next |
| 618 | // turning it on we won't have a good value for the current |
| 619 | // orientation for a little bit, which can cause orientation |
| 620 | // changes to lag, so we'd like to keep it always on. (It will |
| 621 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 622 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 623 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 624 | return mSupportAutoRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 625 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 626 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 627 | /* |
| 628 | * Various use cases for invoking this function |
| 629 | * screen turning off, should always disable listeners if already enabled |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 630 | * 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] | 631 | * if not already enabled |
| 632 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 633 | * already enabled |
| 634 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 635 | * screen turning on and current app has nosensor based orientation, do nothing |
| 636 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 637 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 638 | if (!mOrientationListener.canDetectOrientation()) { |
| 639 | // If sensor is turned off or nonexistent for some reason |
| 640 | return; |
| 641 | } |
| 642 | //Could have been invoked due to screen turning on or off or |
| 643 | //change of the currently visible window's orientation |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 644 | if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 645 | ", current orientation="+mCurrentAppOrientation+ |
| 646 | ", SensorEnabled="+mOrientationSensorEnabled); |
| 647 | boolean disable = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 648 | if (mScreenOnEarly) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 649 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 650 | disable = false; |
| 651 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 652 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 653 | mOrientationListener.enable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 654 | if(localLOGV) Slog.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 655 | mOrientationSensorEnabled = true; |
| 656 | } |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 657 | } |
| 658 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 659 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 660 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 661 | mOrientationListener.disable(); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 662 | if(localLOGV) Slog.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 663 | mOrientationSensorEnabled = false; |
| 664 | } |
| 665 | } |
| 666 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 667 | private void interceptPowerKeyDown(boolean handled) { |
| 668 | mPowerKeyHandled = handled; |
| 669 | if (!handled) { |
| 670 | mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout()); |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | private boolean interceptPowerKeyUp(boolean canceled) { |
| 675 | if (!mPowerKeyHandled) { |
| 676 | mHandler.removeCallbacks(mPowerLongPress); |
| 677 | return !canceled; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 678 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 679 | return false; |
| 680 | } |
| 681 | |
| 682 | private void cancelPendingPowerKeyAction() { |
| 683 | if (!mPowerKeyHandled) { |
| 684 | mHandler.removeCallbacks(mPowerLongPress); |
| 685 | } |
Jeff Brown | ff20471 | 2011-10-25 21:27:54 -0700 | [diff] [blame] | 686 | if (mPowerKeyTriggered) { |
| 687 | mPendingPowerKeyUpCanceled = true; |
| 688 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | private void interceptScreenshotChord() { |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 692 | if (mScreenshotChordEnabled |
| 693 | && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 694 | final long now = SystemClock.uptimeMillis(); |
| 695 | if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS |
| 696 | && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { |
| 697 | mVolumeDownKeyConsumedByScreenshotChord = true; |
| 698 | cancelPendingPowerKeyAction(); |
| 699 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 700 | mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay()); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 701 | } |
| 702 | } |
| 703 | } |
| 704 | |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 705 | private long getScreenshotChordLongPressDelay() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 706 | if (mKeyguardDelegate.isShowing()) { |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 707 | // Double the time it takes to take a screenshot from the keyguard |
| 708 | return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER * |
| 709 | ViewConfiguration.getGlobalActionKeyTimeout()); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 710 | } |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 711 | return ViewConfiguration.getGlobalActionKeyTimeout(); |
Winson Chung | 1cea2f3 | 2012-10-08 20:42:01 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 714 | private void cancelPendingScreenshotChordAction() { |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 715 | mHandler.removeCallbacks(mScreenshotRunnable); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | private final Runnable mPowerLongPress = new Runnable() { |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 719 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 720 | public void run() { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 721 | // The context isn't read |
| 722 | if (mLongPressOnPowerBehavior < 0) { |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 723 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 724 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 725 | } |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 726 | int resolvedBehavior = mLongPressOnPowerBehavior; |
| 727 | if (FactoryTest.isLongPressOnPowerOffEnabled()) { |
| 728 | resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM; |
| 729 | } |
| 730 | |
| 731 | switch (resolvedBehavior) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 732 | case LONG_PRESS_POWER_NOTHING: |
| 733 | break; |
| 734 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 735 | mPowerKeyHandled = true; |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 736 | if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) { |
| 737 | performAuditoryFeedbackForAccessibilityIfNeed(); |
| 738 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 739 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 740 | showGlobalActionsDialog(); |
| 741 | break; |
| 742 | case LONG_PRESS_POWER_SHUT_OFF: |
Jeff Brown | 9a538ee | 2012-08-20 14:56:57 -0700 | [diff] [blame] | 743 | case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM: |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 744 | mPowerKeyHandled = true; |
| 745 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 746 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
Jeff Brown | 850c5b7 | 2012-10-01 15:17:22 -0700 | [diff] [blame] | 747 | mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 748 | break; |
| 749 | } |
| 750 | } |
| 751 | }; |
| 752 | |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 753 | private final Runnable mScreenshotRunnable = new Runnable() { |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 754 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 755 | public void run() { |
| 756 | takeScreenshot(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 757 | } |
| 758 | }; |
| 759 | |
| 760 | void showGlobalActionsDialog() { |
| 761 | if (mGlobalActions == null) { |
Jeff Brown | 7304c34 | 2012-05-11 18:42:42 -0700 | [diff] [blame] | 762 | mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 763 | } |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 764 | final boolean keyguardShowing = keyguardIsShowingTq(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 765 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 766 | if (keyguardShowing) { |
| 767 | // since it took two seconds of long press to bring this up, |
| 768 | // 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] | 769 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 770 | } |
| 771 | } |
| 772 | |
| 773 | boolean isDeviceProvisioned() { |
Jeff Brown | bf6f6f9 | 2012-09-25 15:03:20 -0700 | [diff] [blame] | 774 | return Settings.Global.getInt( |
| 775 | mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 776 | } |
| 777 | |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 778 | private void handleLongPressOnHome() { |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 779 | if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 780 | mHomeConsumed = true; |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 781 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 782 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 783 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) { |
| 784 | toggleRecentApps(); |
| 785 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) { |
| 786 | launchAssistAction(); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 787 | } |
| 788 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 789 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 790 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 791 | private void handleDoubleTapOnHome() { |
| 792 | if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 793 | mHomeConsumed = true; |
| 794 | toggleRecentApps(); |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() { |
| 799 | @Override |
| 800 | public void run() { |
| 801 | if (mHomeDoubleTapPending) { |
| 802 | mHomeDoubleTapPending = false; |
| 803 | launchHomeFromHotKey(); |
| 804 | } |
| 805 | } |
| 806 | }; |
| 807 | |
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 | * Create (if necessary) and show or dismiss the recent apps dialog according |
| 810 | * according to the requested behavior. |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 811 | */ |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 812 | void showOrHideRecentAppsDialog(final int behavior) { |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 813 | mHandler.post(new Runnable() { |
| 814 | @Override |
| 815 | public void run() { |
| 816 | if (mRecentAppsDialog == null) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 817 | mRecentAppsDialog = new RecentApplicationsDialog(mContext); |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 818 | } |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 819 | if (mRecentAppsDialog.isShowing()) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 820 | switch (behavior) { |
| 821 | case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS: |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 822 | case RECENT_APPS_BEHAVIOR_DISMISS: |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 823 | mRecentAppsDialog.dismiss(); |
| 824 | break; |
| 825 | case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH: |
| 826 | mRecentAppsDialog.dismissAndSwitch(); |
| 827 | break; |
| 828 | case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW: |
| 829 | default: |
| 830 | break; |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 831 | } |
| 832 | } else { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 833 | switch (behavior) { |
| 834 | case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS: |
| 835 | mRecentAppsDialog.show(); |
| 836 | break; |
| 837 | case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW: |
| 838 | try { |
| 839 | mWindowManager.setInTouchMode(false); |
| 840 | } catch (RemoteException e) { |
| 841 | } |
| 842 | mRecentAppsDialog.show(); |
| 843 | break; |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 844 | case RECENT_APPS_BEHAVIOR_DISMISS: |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 845 | case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH: |
| 846 | default: |
| 847 | break; |
| 848 | } |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 849 | } |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 850 | } |
| 851 | }); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 852 | } |
Jeff Brown | da3d5a9 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 853 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 854 | /** {@inheritDoc} */ |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 855 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 856 | public void init(Context context, IWindowManager windowManager, |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 857 | WindowManagerFuncs windowManagerFuncs) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 858 | mContext = context; |
| 859 | mWindowManager = windowManager; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 860 | mWindowManagerFuncs = windowManagerFuncs; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 861 | mHandler = new PolicyHandler(); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 862 | mOrientationListener = new MyOrientationListener(mContext, mHandler); |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 863 | try { |
| 864 | mOrientationListener.setCurrentRotation(windowManager.getRotation()); |
| 865 | } catch (RemoteException ex) { } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 866 | mSettingsObserver = new SettingsObserver(mHandler); |
| 867 | mSettingsObserver.observe(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 868 | mShortcutManager = new ShortcutManager(context, mHandler); |
| 869 | mShortcutManager.observe(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 870 | mUiMode = context.getResources().getInteger( |
| 871 | com.android.internal.R.integer.config_defaultUiModeType); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 872 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 873 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 874 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 875 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 876 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 877 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 878 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 879 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 880 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 881 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 882 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 883 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 884 | |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 885 | mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 886 | mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 887 | "PhoneWindowManager.mBroadcastWakeLock"); |
| 888 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 889 | mSupportAutoRotation = mContext.getResources().getBoolean( |
| 890 | com.android.internal.R.bool.config_supportAutoRotation); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 891 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 892 | com.android.internal.R.integer.config_lidOpenRotation); |
| 893 | mCarDockRotation = readRotation( |
| 894 | com.android.internal.R.integer.config_carDockRotation); |
| 895 | mDeskDockRotation = readRotation( |
| 896 | com.android.internal.R.integer.config_deskDockRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 897 | mUndockedHdmiRotation = readRotation( |
| 898 | com.android.internal.R.integer.config_undockedHdmiRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 899 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 900 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 901 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 902 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 903 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 904 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 905 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 906 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 907 | mLidControlsSleep = mContext.getResources().getBoolean( |
| 908 | com.android.internal.R.bool.config_lidControlsSleep); |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 909 | mTranslucentDecorEnabled = mContext.getResources().getBoolean( |
| 910 | com.android.internal.R.bool.config_enableTranslucentDecor); |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 911 | readConfigurationDependentBehaviors(); |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 912 | |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 913 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 914 | Context.ACCESSIBILITY_SERVICE); |
| 915 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 916 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 917 | IntentFilter filter = new IntentFilter(); |
| 918 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 919 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 920 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 921 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 922 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 923 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 924 | if (intent != null) { |
| 925 | // Retrieve current sticky dock event broadcast. |
| 926 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 927 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 928 | } |
Daniel Sandler | 7e37df5 | 2011-11-16 22:08:23 -0800 | [diff] [blame] | 929 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 930 | // register for dream-related broadcasts |
| 931 | filter = new IntentFilter(); |
| 932 | filter.addAction(Intent.ACTION_DREAMING_STARTED); |
| 933 | filter.addAction(Intent.ACTION_DREAMING_STOPPED); |
| 934 | context.registerReceiver(mDreamReceiver, filter); |
| 935 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 936 | // register for multiuser-relevant broadcasts |
| 937 | filter = new IntentFilter(Intent.ACTION_USER_SWITCHED); |
| 938 | context.registerReceiver(mMultiuserReceiver, filter); |
| 939 | |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 940 | // monitor for system gestures |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 941 | mSystemGestures = new SystemGesturesPointerEventListener(context, |
| 942 | new SystemGesturesPointerEventListener.Callbacks() { |
John Spurlock | 57306e6 | 2013-04-22 09:48:49 -0400 | [diff] [blame] | 943 | @Override |
| 944 | public void onSwipeFromTop() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 945 | if (mStatusBar != null) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 946 | requestTransientBars(mStatusBar); |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 947 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 948 | } |
| 949 | @Override |
| 950 | public void onSwipeFromBottom() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 951 | if (mNavigationBar != null && mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 952 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | @Override |
| 956 | public void onSwipeFromRight() { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 957 | if (mNavigationBar != null && !mNavigationBarOnBottom) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 958 | requestTransientBars(mNavigationBar); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 959 | } |
| 960 | } |
| 961 | @Override |
| 962 | public void onDebug() { |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 963 | // no-op |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 964 | } |
| 965 | }); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 966 | mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext); |
Craig Mautner | 037aa8d | 2013-06-07 10:35:44 -0700 | [diff] [blame] | 967 | mWindowManagerFuncs.registerPointerEventListener(mSystemGestures); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 968 | |
Jeff Brown | c234613 | 2012-04-13 01:55:38 -0700 | [diff] [blame] | 969 | mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 970 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 971 | com.android.internal.R.array.config_longPressVibePattern); |
| 972 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 973 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 974 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 975 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 976 | mClockTickVibePattern = getLongIntArray(mContext.getResources(), |
| 977 | com.android.internal.R.array.config_clockTickVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 978 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 979 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 980 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 981 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 982 | |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 983 | mScreenshotChordEnabled = mContext.getResources().getBoolean( |
| 984 | com.android.internal.R.bool.config_enableScreenshotChord); |
| 985 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 986 | mGlobalKeyManager = new GlobalKeyManager(mContext); |
| 987 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 988 | // Controls rotation and the like. |
| 989 | initializeHdmiState(); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 990 | |
| 991 | // Match current screen state. |
Jeff Brown | 26c6a50 | 2014-04-11 02:15:54 -0700 | [diff] [blame] | 992 | if (mPowerManager.isInteractive()) { |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 993 | screenTurningOn(null); |
| 994 | } else { |
| 995 | screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER); |
| 996 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 997 | } |
| 998 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 999 | /** |
| 1000 | * Read values from config.xml that may be overridden depending on |
| 1001 | * the configuration of the device. |
| 1002 | * eg. Disable long press on home goes to recents on sw600dp. |
| 1003 | */ |
| 1004 | private void readConfigurationDependentBehaviors() { |
| 1005 | mLongPressOnHomeBehavior = mContext.getResources().getInteger( |
| 1006 | com.android.internal.R.integer.config_longPressOnHomeBehavior); |
| 1007 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
| 1008 | mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) { |
| 1009 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1010 | } |
| 1011 | |
| 1012 | mDoubleTapOnHomeBehavior = mContext.getResources().getInteger( |
| 1013 | com.android.internal.R.integer.config_doubleTapOnHomeBehavior); |
| 1014 | if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING || |
| 1015 | mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 1016 | mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 1017 | } |
| 1018 | } |
| 1019 | |
Craig Mautner | 0bf6ec9 | 2012-12-18 08:33:27 -0800 | [diff] [blame] | 1020 | @Override |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1021 | public void setInitialDisplaySize(Display display, int width, int height, int density) { |
Jeff Brown | ef981a4 | 2013-08-07 14:13:37 -0700 | [diff] [blame] | 1022 | // This method might be called before the policy has been fully initialized |
| 1023 | // or for other displays we don't care about. |
| 1024 | if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) { |
| 1025 | return; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1026 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1027 | mDisplay = display; |
| 1028 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1029 | final Resources res = mContext.getResources(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1030 | int shortSize, longSize; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1031 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1032 | shortSize = height; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1033 | longSize = width; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1034 | mLandscapeRotation = Surface.ROTATION_0; |
| 1035 | mSeascapeRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1036 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1037 | mPortraitRotation = Surface.ROTATION_90; |
| 1038 | mUpsideDownRotation = Surface.ROTATION_270; |
| 1039 | } else { |
| 1040 | mPortraitRotation = Surface.ROTATION_270; |
| 1041 | mUpsideDownRotation = Surface.ROTATION_90; |
| 1042 | } |
| 1043 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1044 | shortSize = width; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1045 | longSize = height; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1046 | mPortraitRotation = Surface.ROTATION_0; |
| 1047 | mUpsideDownRotation = Surface.ROTATION_180; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1048 | if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) { |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1049 | mLandscapeRotation = Surface.ROTATION_270; |
| 1050 | mSeascapeRotation = Surface.ROTATION_90; |
| 1051 | } else { |
| 1052 | mLandscapeRotation = Surface.ROTATION_90; |
| 1053 | mSeascapeRotation = Surface.ROTATION_270; |
| 1054 | } |
| 1055 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1056 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1057 | mStatusBarHeight = |
| 1058 | res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1059 | |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1060 | // Height of the navigation bar when presented horizontally at bottom |
| 1061 | mNavigationBarHeightForRotation[mPortraitRotation] = |
| 1062 | mNavigationBarHeightForRotation[mUpsideDownRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1063 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1064 | mNavigationBarHeightForRotation[mLandscapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1065 | mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize( |
| 1066 | com.android.internal.R.dimen.navigation_bar_height_landscape); |
Daniel Sandler | 9f65c4c | 2012-04-26 01:35:35 -0400 | [diff] [blame] | 1067 | |
| 1068 | // Width of the navigation bar when presented vertically along one side |
| 1069 | mNavigationBarWidthForRotation[mPortraitRotation] = |
| 1070 | mNavigationBarWidthForRotation[mUpsideDownRotation] = |
| 1071 | mNavigationBarWidthForRotation[mLandscapeRotation] = |
| 1072 | mNavigationBarWidthForRotation[mSeascapeRotation] = |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1073 | res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width); |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1074 | |
| 1075 | // SystemUI (status bar) layout policy |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 1076 | int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1077 | int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density; |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1078 | |
Craig Mautner | d4ec3324 | 2013-07-22 10:37:43 -0700 | [diff] [blame] | 1079 | // Allow the navigation bar to move on small devices (phones). |
| 1080 | mNavigationBarCanMove = shortSizeDp < 600; |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 1081 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1082 | mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar); |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1083 | // Allow a system property to override this. Used by the emulator. |
| 1084 | // See also hasNavigationBar(). |
| 1085 | String navBarOverride = SystemProperties.get("qemu.hw.mainkeys"); |
| 1086 | if ("1".equals(navBarOverride)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1087 | mHasNavigationBar = false; |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1088 | } else if ("0".equals(navBarOverride)) { |
| 1089 | mHasNavigationBar = true; |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 1090 | } |
| 1091 | |
Jeff Brown | 27f1d67 | 2012-10-17 18:32:34 -0700 | [diff] [blame] | 1092 | // For demo purposes, allow the rotation of the HDMI display to be controlled. |
| 1093 | // By default, HDMI locks rotation to landscape. |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1094 | if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1095 | mDemoHdmiRotation = mPortraitRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1096 | } else { |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1097 | mDemoHdmiRotation = mLandscapeRotation; |
Erik Gilling | 9a41ef8 | 2011-09-26 19:21:03 -0700 | [diff] [blame] | 1098 | } |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 1099 | mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false); |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1100 | |
| 1101 | // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per |
| 1102 | // http://developer.android.com/guide/practices/screens_support.html#range |
| 1103 | mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 && |
| 1104 | res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) && |
| 1105 | // For debug purposes the next line turns this feature off with: |
| 1106 | // $ adb shell setprop config.override_forced_orient true |
| 1107 | // $ adb shell wm size reset |
| 1108 | !"true".equals(SystemProperties.get("config.override_forced_orient")); |
| 1109 | } |
| 1110 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1111 | /** |
| 1112 | * @return whether the navigation bar can be hidden, e.g. the device has a |
| 1113 | * navigation bar and touch exploration is not enabled |
| 1114 | */ |
| 1115 | private boolean canHideNavigationBar() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 1116 | return mHasNavigationBar |
| 1117 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 1118 | } |
| 1119 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1120 | @Override |
| 1121 | public boolean isDefaultOrientationForced() { |
| 1122 | return mForceDefaultOrientation; |
Dianne Hackborn | 9d13264 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 1125 | @Override |
| 1126 | public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) { |
| 1127 | if (display.getDisplayId() == Display.DEFAULT_DISPLAY) { |
| 1128 | mOverscanLeft = left; |
| 1129 | mOverscanTop = top; |
| 1130 | mOverscanRight = right; |
| 1131 | mOverscanBottom = bottom; |
| 1132 | } |
| 1133 | } |
| 1134 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1135 | public void updateSettings() { |
| 1136 | ContentResolver resolver = mContext.getContentResolver(); |
| 1137 | boolean updateRotation = false; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1138 | synchronized (mLock) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1139 | mEndcallBehavior = Settings.System.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1140 | Settings.System.END_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1141 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT, |
| 1142 | UserHandle.USER_CURRENT); |
| 1143 | mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 1144 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1145 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT, |
| 1146 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1147 | |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1148 | // Configure rotation lock. |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1149 | int userRotation = Settings.System.getIntForUser(resolver, |
| 1150 | Settings.System.USER_ROTATION, Surface.ROTATION_0, |
| 1151 | UserHandle.USER_CURRENT); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1152 | if (mUserRotation != userRotation) { |
| 1153 | mUserRotation = userRotation; |
| 1154 | updateRotation = true; |
| 1155 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1156 | int userRotationMode = Settings.System.getIntForUser(resolver, |
| 1157 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 1158 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 1159 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
| 1160 | if (mUserRotationMode != userRotationMode) { |
| 1161 | mUserRotationMode = userRotationMode; |
| 1162 | updateRotation = true; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1163 | updateOrientationListenerLp(); |
| 1164 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 1165 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1166 | if (mSystemReady) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1167 | int pointerLocation = Settings.System.getIntForUser(resolver, |
| 1168 | Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1169 | if (mPointerLocationMode != pointerLocation) { |
| 1170 | mPointerLocationMode = pointerLocation; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1171 | mHandler.sendEmptyMessage(pointerLocation != 0 ? |
| 1172 | MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1173 | } |
| 1174 | } |
| 1175 | // use screen off timeout setting as the timeout for the lockscreen |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 1176 | mLockScreenTimeout = Settings.System.getIntForUser(resolver, |
| 1177 | Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT); |
| 1178 | String imId = Settings.Secure.getStringForUser(resolver, |
| 1179 | Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1180 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 1181 | if (mHasSoftInput != hasSoftInput) { |
| 1182 | mHasSoftInput = hasSoftInput; |
| 1183 | updateRotation = true; |
| 1184 | } |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 1185 | if (mImmersiveModeConfirmation != null) { |
John Spurlock | 4355a53 | 2014-02-19 09:49:25 -0500 | [diff] [blame] | 1186 | mImmersiveModeConfirmation.loadSetting(mCurrentUserId); |
John Spurlock | d67ec25 | 2013-09-05 11:31:54 -0400 | [diff] [blame] | 1187 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 1188 | PolicyControl.reloadFromSetting(mContext); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1189 | } |
| 1190 | if (updateRotation) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 1191 | updateRotation(true); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1192 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | private void enablePointerLocation() { |
| 1196 | if (mPointerLocationView == null) { |
| 1197 | mPointerLocationView = new PointerLocationView(mContext); |
| 1198 | mPointerLocationView.setPrintCoords(false); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1199 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 1200 | WindowManager.LayoutParams.MATCH_PARENT, |
| 1201 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1202 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1203 | lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN |
| 1204 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
| 1205 | | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1206 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
Jeff Brown | 90fc905 | 2012-10-01 14:44:24 -0700 | [diff] [blame] | 1207 | if (ActivityManager.isHighEndGfx()) { |
| 1208 | lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED; |
| 1209 | lp.privateFlags |= |
| 1210 | WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED; |
| 1211 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1212 | lp.format = PixelFormat.TRANSLUCENT; |
| 1213 | lp.setTitle("PointerLocation"); |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1214 | WindowManager wm = (WindowManager) |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1215 | mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | cc4f7db | 2011-08-30 20:34:48 -0700 | [diff] [blame] | 1216 | lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL; |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1217 | wm.addView(mPointerLocationView, lp); |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1218 | mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1219 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 1220 | } |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1221 | |
| 1222 | private void disablePointerLocation() { |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1223 | if (mPointerLocationView != null) { |
Michael Wright | c9c487e | 2013-11-07 18:55:09 -0800 | [diff] [blame] | 1224 | mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView); |
| 1225 | WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); |
Jeff Brown | 7082516 | 2012-03-28 17:27:48 -0700 | [diff] [blame] | 1226 | wm.removeView(mPointerLocationView); |
| 1227 | mPointerLocationView = null; |
| 1228 | } |
| 1229 | } |
| 1230 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1231 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1232 | try { |
| 1233 | int rotation = mContext.getResources().getInteger(resID); |
| 1234 | switch (rotation) { |
| 1235 | case 0: |
| 1236 | return Surface.ROTATION_0; |
| 1237 | case 90: |
| 1238 | return Surface.ROTATION_90; |
| 1239 | case 180: |
| 1240 | return Surface.ROTATION_180; |
| 1241 | case 270: |
| 1242 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1243 | } |
| 1244 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1245 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1246 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 1247 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | /** {@inheritDoc} */ |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1251 | @Override |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1252 | public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1253 | int type = attrs.type; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1254 | |
| 1255 | outAppOp[0] = AppOpsManager.OP_NONE; |
| 1256 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1257 | if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW |
| 1258 | || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1259 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1260 | } |
| 1261 | String permission = null; |
| 1262 | switch (type) { |
| 1263 | case TYPE_TOAST: |
| 1264 | // XXX right now the app process has complete control over |
| 1265 | // this... should introduce a token to let the system |
| 1266 | // monitor/control what they are doing. |
| 1267 | break; |
Daniel Sandler | 7d276c3 | 2012-01-30 14:33:52 -0500 | [diff] [blame] | 1268 | case TYPE_DREAM: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1269 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1270 | case TYPE_WALLPAPER: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1271 | case TYPE_PRIVATE_PRESENTATION: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1272 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1273 | break; |
| 1274 | case TYPE_PHONE: |
| 1275 | case TYPE_PRIORITY_PHONE: |
| 1276 | case TYPE_SYSTEM_ALERT: |
| 1277 | case TYPE_SYSTEM_ERROR: |
| 1278 | case TYPE_SYSTEM_OVERLAY: |
| 1279 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
Dianne Hackborn | c229302 | 2013-02-06 23:14:49 -0800 | [diff] [blame] | 1280 | outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1281 | break; |
| 1282 | default: |
| 1283 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 1284 | } |
| 1285 | if (permission != null) { |
| 1286 | if (mContext.checkCallingOrSelfPermission(permission) |
| 1287 | != PackageManager.PERMISSION_GRANTED) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1288 | return WindowManagerGlobal.ADD_PERMISSION_DENIED; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1289 | } |
| 1290 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1291 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1292 | } |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1293 | |
| 1294 | @Override |
| 1295 | public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) { |
| 1296 | |
| 1297 | // If this switch statement is modified, modify the comment in the declarations of |
| 1298 | // the type in {@link WindowManager.LayoutParams} as well. |
| 1299 | switch (attrs.type) { |
| 1300 | default: |
| 1301 | // These are the windows that by default are shown only to the user that created |
| 1302 | // them. If this needs to be overridden, set |
| 1303 | // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in |
| 1304 | // {@link WindowManager.LayoutParams}. Note that permission |
| 1305 | // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well. |
| 1306 | if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) { |
| 1307 | return true; |
| 1308 | } |
| 1309 | break; |
| 1310 | |
| 1311 | // These are the windows that by default are shown to all users. However, to |
| 1312 | // protect against spoofing, check permissions below. |
| 1313 | case TYPE_APPLICATION_STARTING: |
| 1314 | case TYPE_BOOT_PROGRESS: |
| 1315 | case TYPE_DISPLAY_OVERLAY: |
| 1316 | case TYPE_HIDDEN_NAV_CONSUMER: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1317 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1318 | case TYPE_KEYGUARD_DIALOG: |
| 1319 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1320 | case TYPE_NAVIGATION_BAR: |
| 1321 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1322 | case TYPE_PHONE: |
| 1323 | case TYPE_POINTER: |
| 1324 | case TYPE_PRIORITY_PHONE: |
| 1325 | case TYPE_RECENTS_OVERLAY: |
| 1326 | case TYPE_SEARCH_BAR: |
| 1327 | case TYPE_STATUS_BAR: |
| 1328 | case TYPE_STATUS_BAR_PANEL: |
| 1329 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1330 | case TYPE_SYSTEM_DIALOG: |
| 1331 | case TYPE_UNIVERSE_BACKGROUND: |
| 1332 | case TYPE_VOLUME_OVERLAY: |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1333 | case TYPE_PRIVATE_PRESENTATION: |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1334 | break; |
| 1335 | } |
| 1336 | |
| 1337 | // Check if third party app has set window to system window type. |
| 1338 | return mContext.checkCallingOrSelfPermission( |
| 1339 | android.Manifest.permission.INTERNAL_SYSTEM_WINDOW) |
| 1340 | != PackageManager.PERMISSION_GRANTED; |
| 1341 | } |
| 1342 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1343 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1344 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 1345 | switch (attrs.type) { |
| 1346 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1347 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1348 | // These types of windows can't receive input events. |
| 1349 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 1350 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 1351 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1352 | break; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1353 | case TYPE_STATUS_BAR: |
| 1354 | |
| 1355 | // If the Keyguard is in a hidden state (occluded by another window), we force to |
| 1356 | // remove the wallpaper and keyguard flag so that any change in-flight after setting |
| 1357 | // the keyguard as occluded wouldn't set these flags again. |
| 1358 | // See {@link #processKeyguardSetHiddenResultLw}. |
| 1359 | if (mKeyguardHidden) { |
| 1360 | attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 1361 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1362 | } |
| 1363 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1364 | } |
Adrian Roos | 3850211 | 2014-04-09 21:04:11 +0200 | [diff] [blame] | 1365 | |
| 1366 | if (attrs.type != TYPE_STATUS_BAR) { |
| 1367 | // The status bar is the only window allowed to exhibit keyguard behavior. |
| 1368 | attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD; |
| 1369 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | void readLidState() { |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 1373 | mLidState = mWindowManagerFuncs.getLidState(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1374 | } |
| 1375 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1376 | private boolean isHidden(int accessibilityMode) { |
| 1377 | switch (accessibilityMode) { |
| 1378 | case 1: |
| 1379 | return mLidState == LID_CLOSED; |
| 1380 | case 2: |
| 1381 | return mLidState == LID_OPEN; |
| 1382 | default: |
| 1383 | return false; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1384 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 1385 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1386 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1387 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1388 | @Override |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1389 | public void adjustConfigurationLw(Configuration config, int keyboardPresence, |
| 1390 | int navigationPresence) { |
| 1391 | mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0; |
| 1392 | |
Jeff Brown | f71343d | 2013-05-31 17:59:11 -0700 | [diff] [blame] | 1393 | readConfigurationDependentBehaviors(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1394 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 1395 | applyLidSwitchState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1396 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1397 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS |
| 1398 | || (keyboardPresence == PRESENCE_INTERNAL |
| 1399 | && isHidden(mLidKeyboardAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1400 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1401 | if (!mHasSoftInput) { |
| 1402 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 1403 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1404 | } |
| 1405 | |
Jeff Brown | daa3753 | 2012-05-01 15:54:03 -0700 | [diff] [blame] | 1406 | if (config.navigation == Configuration.NAVIGATION_NONAV |
| 1407 | || (navigationPresence == PRESENCE_INTERNAL |
| 1408 | && isHidden(mLidNavigationAccessibility))) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1409 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1410 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1411 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1412 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1413 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 1414 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1415 | public int windowTypeToLayerLw(int type) { |
| 1416 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1417 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1418 | } |
| 1419 | switch (type) { |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1420 | case TYPE_UNIVERSE_BACKGROUND: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1421 | return 1; |
keunyoung | a446bf0 | 2013-06-21 19:07:57 -0700 | [diff] [blame] | 1422 | case TYPE_PRIVATE_PRESENTATION: |
| 1423 | return 2; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1424 | case TYPE_WALLPAPER: |
| 1425 | // wallpaper is at the bottom, though the window manager may move it. |
| 1426 | return 2; |
| 1427 | case TYPE_PHONE: |
| 1428 | return 3; |
| 1429 | case TYPE_SEARCH_BAR: |
| 1430 | return 4; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1431 | case TYPE_RECENTS_OVERLAY: |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1432 | case TYPE_SYSTEM_DIALOG: |
| 1433 | return 5; |
| 1434 | case TYPE_TOAST: |
| 1435 | // toasts and the plugged-in battery thing |
| 1436 | return 6; |
| 1437 | case TYPE_PRIORITY_PHONE: |
| 1438 | // SIM errors and unlock. Not sure if this really should be in a high layer. |
| 1439 | return 7; |
| 1440 | case TYPE_DREAM: |
| 1441 | // used for Dreams (screensavers with TYPE_DREAM windows) |
| 1442 | return 8; |
| 1443 | case TYPE_SYSTEM_ALERT: |
| 1444 | // like the ANR / app crashed dialogs |
| 1445 | return 9; |
| 1446 | case TYPE_INPUT_METHOD: |
| 1447 | // on-screen keyboards and other such input method user interfaces go here. |
| 1448 | return 10; |
| 1449 | case TYPE_INPUT_METHOD_DIALOG: |
| 1450 | // on-screen keyboards and other such input method user interfaces go here. |
| 1451 | return 11; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1452 | case TYPE_KEYGUARD_SCRIM: |
| 1453 | // the safety window that shows behind keyguard while keyguard is starting |
| 1454 | return 12; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1455 | case TYPE_STATUS_BAR_SUB_PANEL: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1456 | return 13; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1457 | case TYPE_STATUS_BAR: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1458 | return 14; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1459 | case TYPE_STATUS_BAR_PANEL: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1460 | return 15; |
| 1461 | case TYPE_KEYGUARD_DIALOG: |
| 1462 | return 16; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1463 | case TYPE_VOLUME_OVERLAY: |
| 1464 | // the on-screen volume indicator and controller shown when the user |
| 1465 | // changes the device volume |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1466 | return 17; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1467 | case TYPE_SYSTEM_OVERLAY: |
| 1468 | // the on-screen volume indicator and controller shown when the user |
| 1469 | // changes the device volume |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1470 | return 18; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1471 | case TYPE_NAVIGATION_BAR: |
| 1472 | // the navigation bar, if available, shows atop most things |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1473 | return 19; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1474 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1475 | // some panels (e.g. search) need to show on top of the navigation bar |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1476 | return 20; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1477 | case TYPE_SYSTEM_ERROR: |
| 1478 | // system-level error dialogs |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1479 | return 21; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1480 | case TYPE_MAGNIFICATION_OVERLAY: |
| 1481 | // used to highlight the magnified portion of a display |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1482 | return 22; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1483 | case TYPE_DISPLAY_OVERLAY: |
| 1484 | // used to simulate secondary display devices |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1485 | return 23; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1486 | case TYPE_DRAG: |
| 1487 | // the drag layer: input for drag-and-drop is associated with this window, |
| 1488 | // which sits above all other focusable windows |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1489 | return 24; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1490 | case TYPE_SECURE_SYSTEM_OVERLAY: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1491 | return 25; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1492 | case TYPE_BOOT_PROGRESS: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1493 | return 26; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1494 | case TYPE_POINTER: |
| 1495 | // the (mouse) pointer layer |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1496 | return 27; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1497 | case TYPE_HIDDEN_NAV_CONSUMER: |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1498 | return 28; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1499 | } |
| 1500 | Log.e(TAG, "Unknown window type: " + type); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1501 | return 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | /** {@inheritDoc} */ |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1505 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1506 | public int subWindowTypeToLayerLw(int type) { |
| 1507 | switch (type) { |
| 1508 | case TYPE_APPLICATION_PANEL: |
| 1509 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 1510 | return APPLICATION_PANEL_SUBLAYER; |
| 1511 | case TYPE_APPLICATION_MEDIA: |
| 1512 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 1513 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 1514 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1515 | case TYPE_APPLICATION_SUB_PANEL: |
| 1516 | return APPLICATION_SUB_PANEL_SUBLAYER; |
| 1517 | } |
| 1518 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 1519 | return 0; |
| 1520 | } |
| 1521 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1522 | @Override |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1523 | public int getMaxWallpaperLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1524 | return windowTypeToLayerLw(TYPE_STATUS_BAR); |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 1527 | @Override |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1528 | public int getAboveUniverseLayer() { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1529 | return windowTypeToLayerLw(TYPE_SYSTEM_ERROR); |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1532 | public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1533 | if (mHasNavigationBar) { |
| 1534 | // For a basic navigation bar, when we are in landscape mode we place |
| 1535 | // the navigation bar to the side. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1536 | if (mNavigationBarCanMove && fullWidth > fullHeight) { |
| 1537 | return fullWidth - mNavigationBarWidthForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1538 | } |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1539 | } |
| 1540 | return fullWidth; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1541 | } |
| 1542 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1543 | public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1544 | if (mHasNavigationBar) { |
| 1545 | // For a basic navigation bar, when we are in portrait mode we place |
| 1546 | // the navigation bar to the bottom. |
Daniel Sandler | 4a066c5 | 2012-04-20 14:49:13 -0400 | [diff] [blame] | 1547 | if (!mNavigationBarCanMove || fullWidth < fullHeight) { |
| 1548 | return fullHeight - mNavigationBarHeightForRotation[rotation]; |
Dianne Hackborn | 077ee85 | 2012-04-09 16:27:07 -0700 | [diff] [blame] | 1549 | } |
| 1550 | } |
| 1551 | return fullHeight; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1552 | } |
| 1553 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1554 | public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) { |
| 1555 | return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation); |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 1558 | public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) { |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1559 | // There is a separate status bar at the top of the display. We don't count that as part |
| 1560 | // 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] | 1561 | // we do want to exclude it since applications can't generally use that part |
| 1562 | // of the screen. |
John Spurlock | 80f00c1 | 2013-06-13 11:10:51 -0400 | [diff] [blame] | 1563 | return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1564 | } |
| 1565 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1566 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1567 | public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1568 | return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1569 | } |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1570 | |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1571 | @Override |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1572 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1573 | switch (attrs.type) { |
| 1574 | case TYPE_STATUS_BAR: |
| 1575 | case TYPE_NAVIGATION_BAR: |
| 1576 | case TYPE_WALLPAPER: |
| 1577 | case TYPE_DREAM: |
| 1578 | case TYPE_UNIVERSE_BACKGROUND: |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1579 | case TYPE_KEYGUARD_SCRIM: |
Craig Mautner | a3f4bf5 | 2012-10-10 20:37:48 -0700 | [diff] [blame] | 1580 | return false; |
| 1581 | default: |
| 1582 | return true; |
| 1583 | } |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1584 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1585 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1586 | /** {@inheritDoc} */ |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1587 | @Override |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1588 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 1589 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1590 | int icon, int logo, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1591 | if (!SHOW_STARTING_ANIMATIONS) { |
| 1592 | return null; |
| 1593 | } |
| 1594 | if (packageName == null) { |
| 1595 | return null; |
| 1596 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1597 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1598 | WindowManager wm = null; |
| 1599 | View view = null; |
| 1600 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1601 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1602 | Context context = mContext; |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1603 | if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName |
| 1604 | + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme=" |
| 1605 | + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1606 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1607 | try { |
| 1608 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1609 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1610 | } catch (PackageManager.NameNotFoundException e) { |
| 1611 | // Ignore |
| 1612 | } |
| 1613 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1614 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1615 | Window win = PolicyManager.makeNewWindow(context); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1616 | final TypedArray ta = win.getWindowStyle(); |
| 1617 | if (ta.getBoolean( |
| 1618 | com.android.internal.R.styleable.Window_windowDisablePreview, false) |
| 1619 | || ta.getBoolean( |
| 1620 | com.android.internal.R.styleable.Window_windowShowWallpaper,false)) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1621 | return null; |
| 1622 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1623 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1624 | Resources r = context.getResources(); |
| 1625 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1626 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1627 | win.setType( |
| 1628 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
| 1629 | // Force the window flags: this is a fake window, so it is not really |
| 1630 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 1631 | // flag because we do know that the next window will take input |
| 1632 | // focus, so we want to get the IME window up on top of us right away. |
| 1633 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1634 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1635 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 1636 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 1637 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1638 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1639 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 1640 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 1641 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1642 | |
Adam Powell | 04fe6eb | 2013-05-31 14:39:48 -0700 | [diff] [blame] | 1643 | win.setDefaultIcon(icon); |
| 1644 | win.setDefaultLogo(logo); |
| 1645 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1646 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1647 | WindowManager.LayoutParams.MATCH_PARENT); |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1648 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1649 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 1650 | params.token = appToken; |
| 1651 | params.packageName = packageName; |
| 1652 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 1653 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
Dianne Hackborn | 5d927c2 | 2011-09-02 12:22:18 -0700 | [diff] [blame] | 1654 | params.privateFlags |= |
| 1655 | WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED; |
Craig Mautner | 88400d3 | 2012-09-30 12:35:45 -0700 | [diff] [blame] | 1656 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS; |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 1657 | |
| 1658 | if (!compatInfo.supportsScreen()) { |
| 1659 | params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW; |
| 1660 | } |
| 1661 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1662 | params.setTitle("Starting " + packageName); |
| 1663 | |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1664 | wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); |
| 1665 | view = win.getDecorView(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1666 | |
| 1667 | if (win.isFloating()) { |
| 1668 | // Whoops, there is no way to display an animation/preview |
| 1669 | // of such a thing! After all that work... let's skip it. |
| 1670 | // (Note that we must do this here because it is in |
| 1671 | // getDecorView() where the theme is evaluated... maybe |
| 1672 | // we should peek the floating attribute from the theme |
| 1673 | // earlier.) |
| 1674 | return null; |
| 1675 | } |
Craig Mautner | 8e4df6c | 2012-05-23 16:57:23 -0700 | [diff] [blame] | 1676 | |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1677 | if (DEBUG_STARTING_WINDOW) Slog.d( |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1678 | TAG, "Adding starting window for " + packageName |
| 1679 | + " / " + appToken + ": " |
| 1680 | + (view.getParent() != null ? view : null)); |
| 1681 | |
| 1682 | wm.addView(view, params); |
| 1683 | |
| 1684 | // Only return the view if it was successfully added to the |
| 1685 | // window manager... which we can tell by it having a parent. |
| 1686 | return view.getParent() != null ? view : null; |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1687 | } catch (WindowManager.BadTokenException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1688 | // ignore |
Craig Mautner | 42bf39e | 2014-02-21 16:46:22 -0800 | [diff] [blame] | 1689 | Log.w(TAG, appToken + " already running, starting window not displayed. " + |
| 1690 | e.getMessage()); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1691 | } catch (RuntimeException e) { |
| 1692 | // don't crash if something else bad happens, for example a |
| 1693 | // failure loading resources because we are loading from an app |
| 1694 | // on external storage that has been unmounted. |
| 1695 | Log.w(TAG, appToken + " failed creating starting window", e); |
Mathias Jeppsson | d1443e9 | 2012-08-24 15:25:32 +0200 | [diff] [blame] | 1696 | } finally { |
| 1697 | if (view != null && view.getParent() == null) { |
| 1698 | Log.w(TAG, "view not successfully added to wm, removing view"); |
| 1699 | wm.removeViewImmediate(view); |
| 1700 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | return null; |
| 1704 | } |
| 1705 | |
| 1706 | /** {@inheritDoc} */ |
| 1707 | public void removeStartingWindow(IBinder appToken, View window) { |
Craig Mautner | 6fbda63 | 2012-07-03 09:26:39 -0700 | [diff] [blame] | 1708 | if (DEBUG_STARTING_WINDOW) { |
| 1709 | RuntimeException e = new RuntimeException("here"); |
| 1710 | e.fillInStackTrace(); |
| 1711 | Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e); |
| 1712 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1713 | |
| 1714 | if (window != null) { |
Dianne Hackborn | 5fd2169 | 2011-06-07 14:09:47 -0700 | [diff] [blame] | 1715 | WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1716 | wm.removeView(window); |
| 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | /** |
| 1721 | * Preflight adding a window to the system. |
| 1722 | * |
| 1723 | * Currently enforces that three window types are singletons: |
| 1724 | * <ul> |
| 1725 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1726 | * <li>KEYGUARD_TYPE</li> |
| 1727 | * </ul> |
| 1728 | * |
| 1729 | * @param win The window to be added |
| 1730 | * @param attrs Information about the window to be added |
| 1731 | * |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1732 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, |
| 1733 | * WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1734 | */ |
| 1735 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 1736 | switch (attrs.type) { |
| 1737 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 1738 | mContext.enforceCallingOrSelfPermission( |
| 1739 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1740 | "PhoneWindowManager"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1741 | if (mStatusBar != null) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1742 | if (mStatusBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1743 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1744 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1745 | } |
| 1746 | mStatusBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1747 | mStatusBarController.setWindow(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1748 | break; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1749 | case TYPE_NAVIGATION_BAR: |
| 1750 | mContext.enforceCallingOrSelfPermission( |
| 1751 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1752 | "PhoneWindowManager"); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1753 | if (mNavigationBar != null) { |
| 1754 | if (mNavigationBar.isAlive()) { |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1755 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1756 | } |
| 1757 | } |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1758 | mNavigationBar = win; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1759 | mNavigationBarController.setWindow(win); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 1760 | if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1761 | break; |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 1762 | case TYPE_NAVIGATION_BAR_PANEL: |
| 1763 | mContext.enforceCallingOrSelfPermission( |
| 1764 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1765 | "PhoneWindowManager"); |
| 1766 | break; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1767 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 1768 | mContext.enforceCallingOrSelfPermission( |
| 1769 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1770 | "PhoneWindowManager"); |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1771 | break; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1772 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1773 | mContext.enforceCallingOrSelfPermission( |
| 1774 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1775 | "PhoneWindowManager"); |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1776 | break; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1777 | case TYPE_KEYGUARD_SCRIM: |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 1778 | if (mKeyguardScrim != null) { |
| 1779 | return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON; |
| 1780 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1781 | mKeyguardScrim = win; |
| 1782 | break; |
| 1783 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1784 | } |
Jeff Brown | 98365d7 | 2012-08-19 20:30:52 -0700 | [diff] [blame] | 1785 | return WindowManagerGlobal.ADD_OKAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | /** {@inheritDoc} */ |
| 1789 | public void removeWindowLw(WindowState win) { |
| 1790 | if (mStatusBar == win) { |
| 1791 | mStatusBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1792 | mStatusBarController.setWindow(null); |
Jim Miller | c0b676d | 2013-03-22 16:11:08 -0700 | [diff] [blame] | 1793 | mKeyguardDelegate.showScrim(); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 1794 | } else if (mKeyguardScrim == win) { |
| 1795 | Log.v(TAG, "Removing keyguard scrim"); |
| 1796 | mKeyguardScrim = null; |
| 1797 | } if (mNavigationBar == win) { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 1798 | mNavigationBar = null; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 1799 | mNavigationBarController.setWindow(null); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1800 | } |
| 1801 | } |
| 1802 | |
| 1803 | static final boolean PRINT_ANIM = false; |
| 1804 | |
| 1805 | /** {@inheritDoc} */ |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1806 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1807 | public int selectAnimationLw(WindowState win, int transit) { |
| 1808 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 1809 | + ": transit=" + transit); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1810 | if (win == mStatusBar) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1811 | boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1812 | if (transit == TRANSIT_EXIT |
| 1813 | || transit == TRANSIT_HIDE) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1814 | return isKeyguard ? -1 : R.anim.dock_top_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1815 | } else if (transit == TRANSIT_ENTER |
| 1816 | || transit == TRANSIT_SHOW) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 1817 | return isKeyguard ? -1 : R.anim.dock_top_enter; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1818 | } |
| 1819 | } else if (win == mNavigationBar) { |
| 1820 | // This can be on either the bottom or the right. |
| 1821 | if (mNavigationBarOnBottom) { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1822 | if (transit == TRANSIT_EXIT |
| 1823 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1824 | return R.anim.dock_bottom_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1825 | } else if (transit == TRANSIT_ENTER |
| 1826 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1827 | return R.anim.dock_bottom_enter; |
| 1828 | } |
| 1829 | } else { |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1830 | if (transit == TRANSIT_EXIT |
| 1831 | || transit == TRANSIT_HIDE) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1832 | return R.anim.dock_right_exit; |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1833 | } else if (transit == TRANSIT_ENTER |
| 1834 | || transit == TRANSIT_SHOW) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 1835 | return R.anim.dock_right_enter; |
| 1836 | } |
| 1837 | } |
Craig Mautner | 4b71aa1 | 2012-12-27 17:20:01 -0800 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | if (transit == TRANSIT_PREVIEW_DONE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1841 | if (win.hasAppShownWindows()) { |
| 1842 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 1843 | return com.android.internal.R.anim.app_starting_exit; |
| 1844 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 1845 | } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 1846 | && transit == TRANSIT_ENTER) { |
| 1847 | // Special case: we are animating in a dream, while the keyguard |
| 1848 | // is shown. We don't want an animation on the dream, because |
| 1849 | // we need it shown immediately with the keyguard animating away |
| 1850 | // to reveal it. |
| 1851 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | return 0; |
| 1855 | } |
| 1856 | |
Craig Mautner | 3c17437 | 2013-02-21 17:54:37 -0800 | [diff] [blame] | 1857 | @Override |
| 1858 | public void selectRotationAnimationLw(int anim[]) { |
| 1859 | if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen=" |
| 1860 | + mTopFullscreenOpaqueWindowState + " rotationAnimation=" |
| 1861 | + (mTopFullscreenOpaqueWindowState == null ? |
| 1862 | "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation)); |
| 1863 | if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) { |
| 1864 | switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) { |
| 1865 | case ROTATION_ANIMATION_CROSSFADE: |
| 1866 | anim[0] = R.anim.rotation_animation_xfade_exit; |
| 1867 | anim[1] = R.anim.rotation_animation_enter; |
| 1868 | break; |
| 1869 | case ROTATION_ANIMATION_JUMPCUT: |
| 1870 | anim[0] = R.anim.rotation_animation_jump_exit; |
| 1871 | anim[1] = R.anim.rotation_animation_enter; |
| 1872 | break; |
| 1873 | case ROTATION_ANIMATION_ROTATE: |
| 1874 | default: |
| 1875 | anim[0] = anim[1] = 0; |
| 1876 | break; |
| 1877 | } |
| 1878 | } else { |
| 1879 | anim[0] = anim[1] = 0; |
| 1880 | } |
| 1881 | } |
| 1882 | |
| 1883 | @Override |
| 1884 | public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId, |
| 1885 | boolean forceDefault) { |
| 1886 | switch (exitAnimId) { |
| 1887 | case R.anim.rotation_animation_xfade_exit: |
| 1888 | case R.anim.rotation_animation_jump_exit: |
| 1889 | // These are the only cases that matter. |
| 1890 | if (forceDefault) { |
| 1891 | return false; |
| 1892 | } |
| 1893 | int anim[] = new int[2]; |
| 1894 | selectRotationAnimationLw(anim); |
| 1895 | return (exitAnimId == anim[0] && enterAnimId == anim[1]); |
| 1896 | default: |
| 1897 | return true; |
| 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | @Override |
Dianne Hackborn | 0c2acff | 2012-04-12 15:17:07 -0700 | [diff] [blame] | 1902 | public Animation createForceHideEnterAnimation(boolean onWallpaper) { |
| 1903 | return AnimationUtils.loadAnimation(mContext, onWallpaper |
| 1904 | ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter |
| 1905 | : com.android.internal.R.anim.lock_screen_behind_enter); |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1906 | } |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 1907 | |
| 1908 | private static void awakenDreams() { |
| 1909 | IDreamManager dreamManager = getDreamManager(); |
| 1910 | if (dreamManager != null) { |
| 1911 | try { |
| 1912 | dreamManager.awaken(); |
| 1913 | } catch (RemoteException e) { |
| 1914 | // fine, stay asleep then |
| 1915 | } |
| 1916 | } |
| 1917 | } |
| 1918 | |
| 1919 | static IDreamManager getDreamManager() { |
| 1920 | return IDreamManager.Stub.asInterface( |
| 1921 | ServiceManager.checkService(DreamService.DREAM_SERVICE)); |
| 1922 | } |
| 1923 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1924 | static ITelephony getTelephonyService() { |
Mike Lockwood | f5f4ec9 | 2011-11-08 14:05:31 -0800 | [diff] [blame] | 1925 | return ITelephony.Stub.asInterface( |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1926 | ServiceManager.checkService(Context.TELEPHONY_SERVICE)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1927 | } |
| 1928 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1929 | static IAudioService getAudioService() { |
| 1930 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 1931 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 1932 | if (audioService == null) { |
| 1933 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 1934 | } |
| 1935 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | boolean keyguardOn() { |
| 1939 | return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode(); |
| 1940 | } |
| 1941 | |
| 1942 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 1943 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 1944 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 1945 | }; |
| 1946 | |
| 1947 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1948 | @Override |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1949 | public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1950 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1951 | final int keyCode = event.getKeyCode(); |
| 1952 | final int repeatCount = event.getRepeatCount(); |
| 1953 | final int metaState = event.getMetaState(); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1954 | final int flags = event.getFlags(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1955 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 1956 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1957 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 1958 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1959 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 1960 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed |
| 1961 | + " canceled=" + canceled); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1962 | } |
| 1963 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1964 | // If we think we might have a volume down & power key chord on the way |
| 1965 | // but we're not sure, then tell the dispatcher to wait a little while and |
| 1966 | // try again later before dispatching. |
Christopher Tate | e90585f | 2012-03-05 18:56:25 -0800 | [diff] [blame] | 1967 | if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 1968 | if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) { |
| 1969 | final long now = SystemClock.uptimeMillis(); |
| 1970 | final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS; |
| 1971 | if (now < timeoutTime) { |
| 1972 | return timeoutTime - now; |
| 1973 | } |
| 1974 | } |
| 1975 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 1976 | && mVolumeDownKeyConsumedByScreenshotChord) { |
| 1977 | if (!down) { |
| 1978 | mVolumeDownKeyConsumedByScreenshotChord = false; |
| 1979 | } |
| 1980 | return -1; |
| 1981 | } |
| 1982 | } |
| 1983 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1984 | // First we always handle the home key here, so applications |
| 1985 | // can never break it, although if keyguard is on, we do let |
| 1986 | // it handle it, because that gives us the correct 5 second |
| 1987 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1988 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1989 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1990 | // If we have released the home key, and didn't do anything else |
| 1991 | // while it was pressed, then it is time to go home! |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1992 | if (!down) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1993 | cancelPreloadRecentApps(); |
| 1994 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1995 | mHomePressed = false; |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 1996 | if (mHomeConsumed) { |
| 1997 | mHomeConsumed = false; |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 1998 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1999 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2000 | |
| 2001 | if (canceled) { |
| 2002 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 2003 | return -1; |
| 2004 | } |
| 2005 | |
| 2006 | // If an incoming call is ringing, HOME is totally disabled. |
| 2007 | // (The user is already on the InCallScreen at this point, |
| 2008 | // and his ONLY options are to answer or reject the call.) |
| 2009 | try { |
| 2010 | ITelephony telephonyService = getTelephonyService(); |
| 2011 | if (telephonyService != null && telephonyService.isRinging()) { |
| 2012 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 2013 | return -1; |
| 2014 | } |
| 2015 | } catch (RemoteException ex) { |
| 2016 | Log.w(TAG, "RemoteException from getPhoneInterface()", ex); |
| 2017 | } |
| 2018 | |
| 2019 | // Delay handling home if a double-tap is possible. |
| 2020 | if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) { |
| 2021 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case |
| 2022 | mHomeDoubleTapPending = true; |
| 2023 | mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable, |
| 2024 | ViewConfiguration.getDoubleTapTimeout()); |
| 2025 | return -1; |
| 2026 | } |
| 2027 | |
| 2028 | // Go home! |
| 2029 | launchHomeFromHotKey(); |
| 2030 | return -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2031 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2032 | |
| 2033 | // If a system window has focus, then it doesn't make sense |
| 2034 | // right now to interact with applications. |
| 2035 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 2036 | if (attrs != null) { |
| 2037 | final int type = attrs.type; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 2038 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM |
| 2039 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG |
| 2040 | || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2041 | // the "app" is keyguard, so give it the key |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2042 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2043 | } |
| 2044 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 2045 | for (int i=0; i<typeCount; i++) { |
| 2046 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 2047 | // 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] | 2048 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2049 | } |
| 2050 | } |
| 2051 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2052 | |
| 2053 | // Remember that home is pressed and handle special actions. |
| 2054 | if (repeatCount == 0) { |
| 2055 | mHomePressed = true; |
| 2056 | if (mHomeDoubleTapPending) { |
| 2057 | mHomeDoubleTapPending = false; |
| 2058 | mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); |
| 2059 | handleDoubleTapOnHome(); |
| 2060 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI |
| 2061 | || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) { |
| 2062 | preloadRecentApps(); |
Michael Jurka | 7f2668c | 2012-03-27 07:49:52 -0700 | [diff] [blame] | 2063 | } |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2064 | } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) { |
| 2065 | if (!keyguardOn) { |
| 2066 | handleLongPressOnHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2067 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2068 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2069 | return -1; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2070 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2071 | // Hijack modified menu keys for debugging features |
| 2072 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 2073 | |
| 2074 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2075 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2076 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 2077 | mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, |
| 2078 | null, null, null, 0, null, null); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2079 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2080 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2081 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2082 | Intent service = new Intent(); |
| 2083 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 2084 | ContentResolver res = mContext.getContentResolver(); |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2085 | boolean shown = Settings.Global.getInt( |
| 2086 | res, Settings.Global.SHOW_PROCESSES, 0) != 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2087 | if (!shown) { |
| 2088 | mContext.startService(service); |
| 2089 | } else { |
| 2090 | mContext.stopService(service); |
| 2091 | } |
Jeff Sharkey | 8d9a1f6 | 2012-10-18 15:38:14 -0700 | [diff] [blame] | 2092 | Settings.Global.putInt( |
| 2093 | res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1); |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2094 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2095 | } |
| 2096 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2097 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2098 | if (down) { |
| 2099 | if (repeatCount == 0) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2100 | mSearchKeyShortcutPending = true; |
| 2101 | mConsumeSearchKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2102 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2103 | } else { |
| 2104 | mSearchKeyShortcutPending = false; |
| 2105 | if (mConsumeSearchKeyUp) { |
| 2106 | mConsumeSearchKeyUp = false; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2107 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2108 | } |
| 2109 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2110 | return 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2111 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2112 | if (!keyguardOn) { |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2113 | if (down && repeatCount == 0) { |
| 2114 | preloadRecentApps(); |
| 2115 | } else if (!down) { |
| 2116 | toggleRecentApps(); |
Michael Wright | c9ebea7 | 2013-01-16 19:25:02 -0800 | [diff] [blame] | 2117 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2118 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2119 | return -1; |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2120 | } else if (keyCode == KeyEvent.KEYCODE_ASSIST) { |
| 2121 | if (down) { |
| 2122 | if (repeatCount == 0) { |
| 2123 | mAssistKeyLongPressed = false; |
| 2124 | } else if (repeatCount == 1) { |
| 2125 | mAssistKeyLongPressed = true; |
| 2126 | if (!keyguardOn) { |
| 2127 | launchAssistLongPressAction(); |
| 2128 | } |
| 2129 | } |
| 2130 | } else { |
| 2131 | if (mAssistKeyLongPressed) { |
| 2132 | mAssistKeyLongPressed = false; |
| 2133 | } else { |
| 2134 | if (!keyguardOn) { |
| 2135 | launchAssistAction(); |
| 2136 | } |
| 2137 | } |
| 2138 | } |
| 2139 | return -1; |
Jeff Sharkey | 2991fa3 | 2012-12-05 18:06:43 -0800 | [diff] [blame] | 2140 | } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) { |
| 2141 | if (down && repeatCount == 0) { |
| 2142 | mHandler.post(mScreenshotRunnable); |
| 2143 | } |
| 2144 | return -1; |
Michael Wright | b854e24 | 2013-02-05 17:54:02 -0800 | [diff] [blame] | 2145 | } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP |
| 2146 | || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) { |
| 2147 | if (down) { |
| 2148 | int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1; |
| 2149 | |
| 2150 | // Disable autobrightness if it's on |
| 2151 | int auto = Settings.System.getIntForUser( |
| 2152 | mContext.getContentResolver(), |
| 2153 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2154 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2155 | UserHandle.USER_CURRENT_OR_SELF); |
| 2156 | if (auto != 0) { |
| 2157 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2158 | Settings.System.SCREEN_BRIGHTNESS_MODE, |
| 2159 | Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, |
| 2160 | UserHandle.USER_CURRENT_OR_SELF); |
| 2161 | } |
| 2162 | |
| 2163 | int min = mPowerManager.getMinimumScreenBrightnessSetting(); |
| 2164 | int max = mPowerManager.getMaximumScreenBrightnessSetting(); |
| 2165 | int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction; |
| 2166 | int brightness = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 2167 | Settings.System.SCREEN_BRIGHTNESS, |
| 2168 | mPowerManager.getDefaultScreenBrightnessSetting(), |
| 2169 | UserHandle.USER_CURRENT_OR_SELF); |
| 2170 | brightness += step; |
| 2171 | // Make sure we don't go beyond the limits. |
| 2172 | brightness = Math.min(max, brightness); |
| 2173 | brightness = Math.max(min, brightness); |
| 2174 | |
| 2175 | Settings.System.putIntForUser(mContext.getContentResolver(), |
| 2176 | Settings.System.SCREEN_BRIGHTNESS, brightness, |
| 2177 | UserHandle.USER_CURRENT_OR_SELF); |
| 2178 | Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG); |
| 2179 | mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF); |
| 2180 | } |
| 2181 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2182 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2183 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2184 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2185 | // Any printing key that is chorded with Search should be consumed |
| 2186 | // even if no shortcut was invoked. This prevents text from being |
| 2187 | // inadvertently inserted when using a keyboard that has built-in macro |
| 2188 | // 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] | 2189 | if (mSearchKeyShortcutPending) { |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2190 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 2191 | if (kcm.isPrintingKey(keyCode)) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2192 | mConsumeSearchKeyUp = true; |
| 2193 | mSearchKeyShortcutPending = false; |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2194 | if (down && repeatCount == 0 && !keyguardOn) { |
| 2195 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 2196 | if (shortcutIntent != null) { |
| 2197 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2198 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2199 | mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2200 | } catch (ActivityNotFoundException ex) { |
| 2201 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2202 | + "the activity to which it is registered was not found: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2203 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 2204 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 2205 | } else { |
| 2206 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2207 | + "SEARCH+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2208 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2209 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2210 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2211 | } |
| 2212 | } |
| 2213 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2214 | // Invoke shortcuts using Meta. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2215 | if (down && repeatCount == 0 && !keyguardOn |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2216 | && (metaState & KeyEvent.META_META_ON) != 0) { |
| 2217 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2218 | if (kcm.isPrintingKey(keyCode)) { |
| 2219 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 2220 | metaState & ~(KeyEvent.META_META_ON |
| 2221 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 2222 | if (shortcutIntent != null) { |
| 2223 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2224 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2225 | mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT); |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2226 | } catch (ActivityNotFoundException ex) { |
| 2227 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 2228 | + "the activity to which it is registered was not found: " |
| 2229 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 2230 | } |
| 2231 | return -1; |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2232 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2233 | } |
| 2234 | } |
| 2235 | |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2236 | // Handle application launch keys. |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2237 | if (down && repeatCount == 0 && !keyguardOn) { |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2238 | String category = sApplicationLaunchKeyCategories.get(keyCode); |
| 2239 | if (category != null) { |
Dianne Hackborn | f5b8671 | 2011-12-05 17:42:41 -0800 | [diff] [blame] | 2240 | Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2241 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2242 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2243 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2244 | } catch (ActivityNotFoundException ex) { |
| 2245 | Slog.w(TAG, "Dropping application launch key because " |
| 2246 | + "the activity to which it is registered was not found: " |
| 2247 | + "keyCode=" + keyCode + ", category=" + category, ex); |
| 2248 | } |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2249 | return -1; |
Jeff Brown | 6651a63 | 2011-11-28 12:59:11 -0800 | [diff] [blame] | 2250 | } |
| 2251 | } |
| 2252 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2253 | // Display task switcher for ALT-TAB or Meta-TAB. |
| 2254 | if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) { |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2255 | if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) { |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2256 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
| 2257 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON) |
| 2258 | || KeyEvent.metaStateHasModifiers( |
| 2259 | shiftlessModifiers, KeyEvent.META_META_ON)) { |
| 2260 | mRecentAppsDialogHeldModifiers = shiftlessModifiers; |
| 2261 | showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW); |
| 2262 | return -1; |
| 2263 | } |
| 2264 | } |
| 2265 | } else if (!down && mRecentAppsDialogHeldModifiers != 0 |
| 2266 | && (metaState & mRecentAppsDialogHeldModifiers) == 0) { |
| 2267 | mRecentAppsDialogHeldModifiers = 0; |
Jeff Brown | 602ab32 | 2012-05-16 13:33:47 -0700 | [diff] [blame] | 2268 | showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS : |
| 2269 | RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH); |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2270 | } |
| 2271 | |
Jeff Brown | cf39bdf | 2012-05-18 14:41:19 -0700 | [diff] [blame] | 2272 | // Handle keyboard language switching. |
| 2273 | if (down && repeatCount == 0 |
| 2274 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2275 | || (keyCode == KeyEvent.KEYCODE_SPACE |
| 2276 | && (metaState & KeyEvent.META_CTRL_MASK) != 0))) { |
| 2277 | int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1; |
| 2278 | mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction); |
| 2279 | return -1; |
| 2280 | } |
| 2281 | if (mLanguageSwitchKeyPressed && !down |
| 2282 | && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH |
| 2283 | || keyCode == KeyEvent.KEYCODE_SPACE)) { |
| 2284 | mLanguageSwitchKeyPressed = false; |
| 2285 | return -1; |
| 2286 | } |
| 2287 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 2288 | if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) { |
| 2289 | return -1; |
| 2290 | } |
| 2291 | |
Jeff Brown | 68b909d | 2011-12-07 16:36:01 -0800 | [diff] [blame] | 2292 | // Let the application handle the key. |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 2293 | return 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2294 | } |
| 2295 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2296 | /** {@inheritDoc} */ |
| 2297 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2298 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2299 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2300 | if (DEBUG_INPUT) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2301 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 2302 | + ", flags=" + event.getFlags() |
| 2303 | + ", keyCode=" + event.getKeyCode() |
| 2304 | + ", scanCode=" + event.getScanCode() |
| 2305 | + ", metaState=" + event.getMetaState() |
| 2306 | + ", repeatCount=" + event.getRepeatCount() |
| 2307 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2308 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2309 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2310 | KeyEvent fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2311 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 2312 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 2313 | final int keyCode = event.getKeyCode(); |
| 2314 | final int metaState = event.getMetaState(); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2315 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 2316 | && event.getRepeatCount() == 0; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2317 | |
Jeff Brown | 5487500 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 2318 | // Check for fallback actions specified by the key character map. |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2319 | final FallbackAction fallbackAction; |
| 2320 | if (initialDown) { |
| 2321 | fallbackAction = kcm.getFallbackAction(keyCode, metaState); |
| 2322 | } else { |
| 2323 | fallbackAction = mFallbackActions.get(keyCode); |
| 2324 | } |
| 2325 | |
| 2326 | if (fallbackAction != null) { |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2327 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2328 | Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode |
| 2329 | + " metaState=" + Integer.toHexString(fallbackAction.metaState)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2330 | } |
| 2331 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2332 | final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 2333 | fallbackEvent = KeyEvent.obtain( |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2334 | event.getDownTime(), event.getEventTime(), |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2335 | event.getAction(), fallbackAction.keyCode, |
| 2336 | event.getRepeatCount(), fallbackAction.metaState, |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2337 | event.getDeviceId(), event.getScanCode(), |
| 2338 | flags, event.getSource(), null); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2339 | |
| 2340 | if (!interceptFallback(win, fallbackEvent, policyFlags)) { |
| 2341 | fallbackEvent.recycle(); |
| 2342 | fallbackEvent = null; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2343 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2344 | |
| 2345 | if (initialDown) { |
| 2346 | mFallbackActions.put(keyCode, fallbackAction); |
| 2347 | } else if (event.getAction() == KeyEvent.ACTION_UP) { |
| 2348 | mFallbackActions.remove(keyCode); |
| 2349 | fallbackAction.recycle(); |
| 2350 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2351 | } |
| 2352 | } |
| 2353 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 2354 | if (DEBUG_INPUT) { |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2355 | if (fallbackEvent == null) { |
| 2356 | Slog.d(TAG, "No fallback."); |
| 2357 | } else { |
| 2358 | Slog.d(TAG, "Performing fallback: " + fallbackEvent); |
| 2359 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 2360 | } |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2361 | return fallbackEvent; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2364 | private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 2365 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags); |
Jeff Brown | fd23e3e | 2012-05-09 13:34:28 -0700 | [diff] [blame] | 2366 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 2367 | long delayMillis = interceptKeyBeforeDispatching( |
| 2368 | win, fallbackEvent, policyFlags); |
| 2369 | if (delayMillis == 0) { |
| 2370 | return true; |
| 2371 | } |
| 2372 | } |
| 2373 | return false; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 2374 | } |
| 2375 | |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2376 | private void launchAssistLongPressAction() { |
| 2377 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 2378 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
| 2379 | |
| 2380 | // launch the search activity |
| 2381 | Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS); |
| 2382 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2383 | try { |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2384 | // TODO: This only stops the factory-installed search manager. |
| 2385 | // Need to formalize an API to handle others |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2386 | SearchManager searchManager = getSearchManager(); |
| 2387 | if (searchManager != null) { |
| 2388 | searchManager.stopSearch(); |
| 2389 | } |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2390 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2391 | } catch (ActivityNotFoundException e) { |
| 2392 | Slog.w(TAG, "No activity to handle assist long press action.", e); |
| 2393 | } |
| 2394 | } |
| 2395 | |
| 2396 | private void launchAssistAction() { |
| 2397 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST); |
Amith Yamasani | c1d07a4 | 2012-08-14 09:32:02 -0700 | [diff] [blame] | 2398 | Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE)) |
Dianne Hackborn | f9c5e0f | 2013-01-23 14:39:13 -0800 | [diff] [blame] | 2399 | .getAssistIntent(mContext, true, UserHandle.USER_CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2400 | if (intent != null) { |
| 2401 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 2402 | | Intent.FLAG_ACTIVITY_SINGLE_TOP |
| 2403 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); |
| 2404 | try { |
Michael Wright | 43e27f7 | 2013-04-10 14:06:48 -0700 | [diff] [blame] | 2405 | mContext.startActivityAsUser(intent, UserHandle.CURRENT); |
Jim Miller | 45308b1 | 2012-06-18 19:23:39 -0700 | [diff] [blame] | 2406 | } catch (ActivityNotFoundException e) { |
| 2407 | Slog.w(TAG, "No activity to handle assist action.", e); |
Jeff Brown | de7a8ea | 2012-06-13 18:28:57 -0700 | [diff] [blame] | 2408 | } |
| 2409 | } |
| 2410 | } |
| 2411 | |
| 2412 | private SearchManager getSearchManager() { |
| 2413 | if (mSearchManager == null) { |
| 2414 | mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE); |
| 2415 | } |
| 2416 | return mSearchManager; |
| 2417 | } |
| 2418 | |
Jeff Brown | caca881 | 2013-05-09 13:34:33 -0700 | [diff] [blame] | 2419 | private void preloadRecentApps() { |
| 2420 | mPreloadedRecentApps = true; |
| 2421 | try { |
| 2422 | IStatusBarService statusbar = getStatusBarService(); |
| 2423 | if (statusbar != null) { |
| 2424 | statusbar.preloadRecentApps(); |
| 2425 | } |
| 2426 | } catch (RemoteException e) { |
| 2427 | Slog.e(TAG, "RemoteException when preloading recent apps", e); |
| 2428 | // re-acquire status bar service next time it is needed. |
| 2429 | mStatusBarService = null; |
| 2430 | } |
| 2431 | } |
| 2432 | |
| 2433 | private void cancelPreloadRecentApps() { |
| 2434 | if (mPreloadedRecentApps) { |
| 2435 | mPreloadedRecentApps = false; |
| 2436 | try { |
| 2437 | IStatusBarService statusbar = getStatusBarService(); |
| 2438 | if (statusbar != null) { |
| 2439 | statusbar.cancelPreloadRecentApps(); |
| 2440 | } |
| 2441 | } catch (RemoteException e) { |
| 2442 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 2443 | // re-acquire status bar service next time it is needed. |
| 2444 | mStatusBarService = null; |
| 2445 | } |
| 2446 | } |
| 2447 | } |
| 2448 | |
| 2449 | private void toggleRecentApps() { |
| 2450 | mPreloadedRecentApps = false; // preloading no longer needs to be canceled |
| 2451 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS); |
| 2452 | try { |
| 2453 | IStatusBarService statusbar = getStatusBarService(); |
| 2454 | if (statusbar != null) { |
| 2455 | statusbar.toggleRecentApps(); |
| 2456 | } |
| 2457 | } catch (RemoteException e) { |
| 2458 | Slog.e(TAG, "RemoteException when showing recent apps", e); |
| 2459 | // re-acquire status bar service next time it is needed. |
| 2460 | mStatusBarService = null; |
| 2461 | } |
| 2462 | } |
| 2463 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2464 | /** |
| 2465 | * A home key -> launch home action was detected. Take the appropriate action |
| 2466 | * given the situation with the keyguard. |
| 2467 | */ |
| 2468 | void launchHomeFromHotKey() { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 2469 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2470 | // don't launch home if keyguard showing |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2471 | } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2472 | // when in keyguard restricted mode, must first verify unlock |
| 2473 | // before launching home |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 2474 | mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2475 | public void onKeyguardExitResult(boolean success) { |
| 2476 | if (success) { |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2477 | try { |
| 2478 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2479 | } catch (RemoteException e) { |
| 2480 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 2481 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2482 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2483 | } |
| 2484 | } |
| 2485 | }); |
| 2486 | } else { |
| 2487 | // no keyguard stuff to worry about, just launch home! |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2488 | try { |
| 2489 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2490 | } catch (RemoteException e) { |
| 2491 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 2492 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2493 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2494 | } |
| 2495 | } |
| 2496 | |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2497 | private final Runnable mClearHideNavigationFlag = new Runnable() { |
| 2498 | @Override |
| 2499 | public void run() { |
| 2500 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
| 2501 | // Clear flags. |
| 2502 | mForceClearedSystemUiFlags &= |
| 2503 | ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
| 2504 | } |
| 2505 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2506 | } |
| 2507 | }; |
| 2508 | |
| 2509 | /** |
| 2510 | * Input handler used while nav bar is hidden. Captures any touch on the screen, |
| 2511 | * to determine when the nav bar should be shown and prevent applications from |
| 2512 | * receiving those touches. |
| 2513 | */ |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2514 | final class HideNavInputEventReceiver extends InputEventReceiver { |
| 2515 | public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) { |
| 2516 | super(inputChannel, looper); |
| 2517 | } |
| 2518 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2519 | @Override |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2520 | public void onInputEvent(InputEvent event) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2521 | boolean handled = false; |
| 2522 | try { |
Jeff Brown | 4952dfd | 2011-11-30 19:23:22 -0800 | [diff] [blame] | 2523 | if (event instanceof MotionEvent |
| 2524 | && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 2525 | final MotionEvent motionEvent = (MotionEvent)event; |
| 2526 | if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2527 | // When the user taps down, we re-show the nav bar. |
| 2528 | boolean changed = false; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2529 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2530 | // Any user activity always causes us to show the |
| 2531 | // navigation controls, if they had been hidden. |
| 2532 | // We also clear the low profile and only content |
| 2533 | // flags so that tapping on the screen will atomically |
| 2534 | // restore all currently hidden screen decorations. |
| 2535 | int newVal = mResettingSystemUiFlags | |
| 2536 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | |
| 2537 | View.SYSTEM_UI_FLAG_LOW_PROFILE | |
| 2538 | View.SYSTEM_UI_FLAG_FULLSCREEN; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2539 | if (mResettingSystemUiFlags != newVal) { |
| 2540 | mResettingSystemUiFlags = newVal; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2541 | changed = true; |
| 2542 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2543 | // We don't allow the system's nav bar to be hidden |
| 2544 | // again for 1 second, to prevent applications from |
| 2545 | // spamming us and keeping it from being shown. |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2546 | newVal = mForceClearedSystemUiFlags | |
| 2547 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2548 | if (mForceClearedSystemUiFlags != newVal) { |
| 2549 | mForceClearedSystemUiFlags = newVal; |
| 2550 | changed = true; |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 2551 | mHandler.postDelayed(mClearHideNavigationFlag, 1000); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2552 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2553 | } |
| 2554 | if (changed) { |
| 2555 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 2556 | } |
| 2557 | } |
| 2558 | } |
| 2559 | } finally { |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2560 | finishInputEvent(event, handled); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2561 | } |
| 2562 | } |
Jeff Brown | 32cbc3855 | 2011-12-01 14:01:49 -0800 | [diff] [blame] | 2563 | } |
| 2564 | final InputEventReceiver.Factory mHideNavInputEventReceiverFactory = |
| 2565 | new InputEventReceiver.Factory() { |
| 2566 | @Override |
| 2567 | public InputEventReceiver createInputEventReceiver( |
| 2568 | InputChannel inputChannel, Looper looper) { |
| 2569 | return new HideNavInputEventReceiver(inputChannel, looper); |
| 2570 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2571 | }; |
| 2572 | |
| 2573 | @Override |
| 2574 | public int adjustSystemUiVisibilityLw(int visibility) { |
John Spurlock | 5b9145b | 2013-08-20 15:13:47 -0400 | [diff] [blame] | 2575 | mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
| 2576 | mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2577 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2578 | // Reset any bits in mForceClearingStatusBarVisibility that |
| 2579 | // are now clear. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2580 | mResettingSystemUiFlags &= visibility; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2581 | // Clear any bits in the new visibility that are currently being |
| 2582 | // force cleared, before reporting it. |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2583 | return visibility & ~mResettingSystemUiFlags |
| 2584 | & ~mForceClearedSystemUiFlags; |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 2585 | } |
| 2586 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2587 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2588 | public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 2589 | final int fl = PolicyControl.getWindowFlags(null, attrs); |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 2590 | final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs); |
| 2591 | final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2592 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2593 | 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] | 2594 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2595 | int availRight, availBottom; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 2596 | if (canHideNavigationBar() && |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2597 | (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2598 | availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 2599 | availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
| 2600 | } else { |
| 2601 | availRight = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 2602 | availBottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 2603 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2604 | if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 2605 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 2606 | contentInset.set(mStableFullscreenLeft, mStableFullscreenTop, |
| 2607 | availRight - mStableFullscreenRight, |
| 2608 | availBottom - mStableFullscreenBottom); |
| 2609 | } else { |
| 2610 | contentInset.set(mStableLeft, mStableTop, |
| 2611 | availRight - mStableRight, availBottom - mStableBottom); |
| 2612 | } |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2613 | } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) { |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2614 | contentInset.setEmpty(); |
| 2615 | } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2616 | | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) { |
| 2617 | contentInset.set(mCurLeft, mCurTop, |
| 2618 | availRight - mCurRight, availBottom - mCurBottom); |
| 2619 | } else { |
| 2620 | contentInset.set(mCurLeft, mCurTop, |
| 2621 | availRight - mCurRight, availBottom - mCurBottom); |
| 2622 | } |
| 2623 | return; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2624 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2625 | contentInset.setEmpty(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2626 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2627 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2628 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2629 | @Override |
| 2630 | public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight, |
| 2631 | int displayRotation) { |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2632 | final int overscanLeft, overscanTop, overscanRight, overscanBottom; |
| 2633 | if (isDefaultDisplay) { |
| 2634 | switch (displayRotation) { |
| 2635 | case Surface.ROTATION_90: |
| 2636 | overscanLeft = mOverscanTop; |
| 2637 | overscanTop = mOverscanRight; |
| 2638 | overscanRight = mOverscanBottom; |
| 2639 | overscanBottom = mOverscanLeft; |
| 2640 | break; |
| 2641 | case Surface.ROTATION_180: |
| 2642 | overscanLeft = mOverscanRight; |
| 2643 | overscanTop = mOverscanBottom; |
| 2644 | overscanRight = mOverscanLeft; |
| 2645 | overscanBottom = mOverscanTop; |
| 2646 | break; |
| 2647 | case Surface.ROTATION_270: |
| 2648 | overscanLeft = mOverscanBottom; |
| 2649 | overscanTop = mOverscanLeft; |
| 2650 | overscanRight = mOverscanTop; |
| 2651 | overscanBottom = mOverscanRight; |
| 2652 | break; |
| 2653 | default: |
| 2654 | overscanLeft = mOverscanLeft; |
| 2655 | overscanTop = mOverscanTop; |
| 2656 | overscanRight = mOverscanRight; |
| 2657 | overscanBottom = mOverscanBottom; |
| 2658 | break; |
| 2659 | } |
| 2660 | } else { |
| 2661 | overscanLeft = 0; |
| 2662 | overscanTop = 0; |
| 2663 | overscanRight = 0; |
| 2664 | overscanBottom = 0; |
| 2665 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2666 | mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0; |
| 2667 | mOverscanScreenTop = mRestrictedOverscanScreenTop = 0; |
| 2668 | mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth; |
| 2669 | mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight; |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2670 | mSystemLeft = 0; |
| 2671 | mSystemTop = 0; |
| 2672 | mSystemRight = displayWidth; |
| 2673 | mSystemBottom = displayHeight; |
| 2674 | mUnrestrictedScreenLeft = overscanLeft; |
| 2675 | mUnrestrictedScreenTop = overscanTop; |
| 2676 | mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight; |
| 2677 | mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom; |
| 2678 | mRestrictedScreenLeft = mUnrestrictedScreenLeft; |
| 2679 | mRestrictedScreenTop = mUnrestrictedScreenTop; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2680 | mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth; |
| 2681 | mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2682 | mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2683 | = mCurLeft = mUnrestrictedScreenLeft; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2684 | mDockTop = mContentTop = mStableTop = mStableFullscreenTop |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2685 | = mCurTop = mUnrestrictedScreenTop; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2686 | mDockRight = mContentRight = mStableRight = mStableFullscreenRight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2687 | = mCurRight = displayWidth - overscanRight; |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2688 | mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2689 | = mCurBottom = displayHeight - overscanBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2690 | mDockLayer = 0x10000000; |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2691 | mStatusBarLayer = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2692 | |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2693 | // start with the current dock rect, which will be (0,0,displayWidth,displayHeight) |
| 2694 | final Rect pf = mTmpParentFrame; |
| 2695 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2696 | final Rect of = mTmpOverscanFrame; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2697 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2698 | final Rect dcf = mTmpDecorFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2699 | pf.left = df.left = of.left = vf.left = mDockLeft; |
| 2700 | pf.top = df.top = of.top = vf.top = mDockTop; |
| 2701 | pf.right = df.right = of.right = vf.right = mDockRight; |
| 2702 | pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2703 | dcf.setEmpty(); // Decor frame N/A for system bars. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2704 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2705 | if (isDefaultDisplay) { |
| 2706 | // For purposes of putting out fake window up to steal focus, we will |
| 2707 | // drive nav being hidden only by whether it is requested. |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2708 | final int sysui = mLastSystemUiFlags; |
| 2709 | boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 2710 | boolean navTranslucent = (sysui & View.NAVIGATION_BAR_TRANSLUCENT) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 2711 | boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0; |
| 2712 | boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
| 2713 | boolean navAllowedHidden = immersive || immersiveSticky; |
| 2714 | navTranslucent &= !immersiveSticky; // transient trumps translucent |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 2715 | navTranslucent &= areTranslucentBarsAllowed(); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2716 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2717 | // When the navigation bar isn't visible, we put up a fake |
| 2718 | // input window to catch all touch events. This way we can |
| 2719 | // detect when the user presses anywhere to bring back the nav |
| 2720 | // bar and ensure the application doesn't see the event. |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 2721 | if (navVisible || navAllowedHidden) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2722 | if (mHideNavFakeWindow != null) { |
| 2723 | mHideNavFakeWindow.dismiss(); |
| 2724 | mHideNavFakeWindow = null; |
| 2725 | } |
| 2726 | } else if (mHideNavFakeWindow == null) { |
| 2727 | mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow( |
| 2728 | mHandler.getLooper(), mHideNavInputEventReceiverFactory, |
Adam Lesinski | 95c4297 | 2013-10-02 10:13:27 -0700 | [diff] [blame] | 2729 | "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2730 | 0, false, false, true); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2731 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 2732 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2733 | // For purposes of positioning and showing the nav bar, if we have |
| 2734 | // decided that it can't be hidden (because of the screen aspect ratio), |
| 2735 | // then take that into account. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 2736 | navVisible |= !canHideNavigationBar(); |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2737 | |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2738 | boolean updateSysUiVisibility = false; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2739 | if (mNavigationBar != null) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2740 | boolean transientNavBarShowing = mNavigationBarController.isTransientShowing(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2741 | // Force the navigation bar to its appropriate place and |
| 2742 | // size. We need to do this directly, instead of relying on |
| 2743 | // it to bubble up from the nav bar, because this needs to |
| 2744 | // change atomically with screen rotations. |
| 2745 | mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight); |
| 2746 | if (mNavigationBarOnBottom) { |
| 2747 | // 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] | 2748 | int top = displayHeight - overscanBottom |
| 2749 | - mNavigationBarHeightForRotation[displayRotation]; |
| 2750 | mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2751 | mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 2752 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2753 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2754 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2755 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2756 | mDockBottom = mTmpNavigationFrame.top; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2757 | mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop; |
| 2758 | mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2759 | } else { |
| 2760 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2761 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2762 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 2763 | if (navVisible && !navTranslucent && !navAllowedHidden |
| 2764 | && !mNavigationBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 2765 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2766 | // If the opaque nav bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2767 | // and not in the process of animating on or off, then |
| 2768 | // we can tell the app that it is covered by it. |
| 2769 | mSystemBottom = mTmpNavigationFrame.top; |
| 2770 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2771 | } else { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2772 | // Landscape screen; nav bar goes to the right. |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 2773 | int left = displayWidth - overscanRight |
| 2774 | - mNavigationBarWidthForRotation[displayRotation]; |
| 2775 | mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2776 | mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left; |
John Spurlock | f95b89a | 2013-10-10 22:10:42 -0400 | [diff] [blame] | 2777 | if (transientNavBarShowing) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2778 | mNavigationBarController.setBarShowingLw(true); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2779 | } else if (navVisible) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2780 | mNavigationBarController.setBarShowingLw(true); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2781 | mDockRight = mTmpNavigationFrame.left; |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 2782 | mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft; |
| 2783 | mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2784 | } else { |
| 2785 | // We currently want to hide the navigation UI. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2786 | mNavigationBarController.setBarShowingLw(false); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2787 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 2788 | if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw() |
| 2789 | && !mNavigationBarController.wasRecentlyTranslucent()) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2790 | // If the nav bar is currently requested to be visible, |
| 2791 | // and not in the process of animating on or off, then |
| 2792 | // we can tell the app that it is covered by it. |
| 2793 | mSystemRight = mTmpNavigationFrame.left; |
| 2794 | } |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2795 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2796 | // Make sure the content and current rectangles are updated to |
| 2797 | // account for the restrictions from the navigation bar. |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 2798 | mContentTop = mCurTop = mDockTop; |
| 2799 | mContentBottom = mCurBottom = mDockBottom; |
| 2800 | mContentLeft = mCurLeft = mDockLeft; |
| 2801 | mContentRight = mCurRight = mDockRight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2802 | mStatusBarLayer = mNavigationBar.getSurfaceLayer(); |
| 2803 | // And compute the final frame. |
| 2804 | mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame, |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2805 | mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2806 | if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2807 | if (mNavigationBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2808 | updateSysUiVisibility = true; |
| 2809 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2810 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2811 | 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] | 2812 | mDockLeft, mDockTop, mDockRight, mDockBottom)); |
| 2813 | |
| 2814 | // decide where the status bar goes ahead of time |
| 2815 | if (mStatusBar != null) { |
| 2816 | // apply any navigation bar insets |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2817 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 2818 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 2819 | pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft; |
| 2820 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight |
| 2821 | + mUnrestrictedScreenTop; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2822 | vf.left = mStableLeft; |
| 2823 | vf.top = mStableTop; |
| 2824 | vf.right = mStableRight; |
| 2825 | vf.bottom = mStableBottom; |
| 2826 | |
| 2827 | mStatusBarLayer = mStatusBar.getSurfaceLayer(); |
| 2828 | |
| 2829 | // Let the status bar determine its size. |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2830 | mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2831 | |
| 2832 | // For layout, the status bar is always at the top with our fixed height. |
| 2833 | mStableTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 2834 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2835 | boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 2836 | boolean statusBarTranslucent = (sysui & View.STATUS_BAR_TRANSLUCENT) != 0; |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 2837 | statusBarTranslucent &= areTranslucentBarsAllowed(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 2838 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2839 | // If the status bar is hidden, we don't want to cause |
| 2840 | // windows behind it to scroll. |
John Spurlock | eda1f69 | 2013-09-16 11:38:44 -0400 | [diff] [blame] | 2841 | if (mStatusBar.isVisibleLw() && !statusBarTransient) { |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2842 | // Status bar may go away, so the screen area it occupies |
| 2843 | // is available to apps but just covering them when the |
| 2844 | // status bar is visible. |
| 2845 | mDockTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 2846 | |
| 2847 | mContentTop = mCurTop = mDockTop; |
| 2848 | mContentBottom = mCurBottom = mDockBottom; |
| 2849 | mContentLeft = mCurLeft = mDockLeft; |
| 2850 | mContentRight = mCurRight = mDockRight; |
| 2851 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2852 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " + |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2853 | String.format( |
| 2854 | "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]", |
| 2855 | mDockLeft, mDockTop, mDockRight, mDockBottom, |
| 2856 | mContentLeft, mContentTop, mContentRight, mContentBottom, |
| 2857 | mCurLeft, mCurTop, mCurRight, mCurBottom)); |
| 2858 | } |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2859 | if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 2860 | && !statusBarTransient && !statusBarTranslucent |
| 2861 | && !mStatusBarController.wasRecentlyTranslucent()) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 2862 | // If the opaque status bar is currently requested to be visible, |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2863 | // and not in the process of animating on or off, then |
| 2864 | // we can tell the app that it is covered by it. |
| 2865 | mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight; |
| 2866 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 2867 | if (mStatusBarController.checkHiddenLw()) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2868 | updateSysUiVisibility = true; |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 2869 | } |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 2870 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 2871 | if (updateSysUiVisibility) { |
| 2872 | updateSystemUiVisibilityLw(); |
| 2873 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2874 | } |
| 2875 | } |
| 2876 | |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 2877 | /** {@inheritDoc} */ |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2878 | @Override |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2879 | public int getSystemDecorLayerLw() { |
Dianne Hackborn | 85afd1b | 2012-05-13 13:31:06 -0700 | [diff] [blame] | 2880 | if (mStatusBar != null) return mStatusBar.getSurfaceLayer(); |
| 2881 | if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer(); |
| 2882 | return 0; |
| 2883 | } |
| 2884 | |
Craig Mautner | 967212c | 2013-04-13 21:10:58 -0700 | [diff] [blame] | 2885 | @Override |
| 2886 | public void getContentRectLw(Rect r) { |
| 2887 | r.set(mContentLeft, mContentTop, mContentRight, mContentBottom); |
| 2888 | } |
| 2889 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2890 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached, |
| 2891 | 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] | 2892 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 2893 | // Here's a special case: if this attached window is a panel that is |
| 2894 | // above the dock window, and the window it is attached to is below |
| 2895 | // the dock window, then the frames we computed for the window it is |
| 2896 | // attached to can not be used because the dock is effectively part |
| 2897 | // of the underlying window and the attached window is floating on top |
| 2898 | // of the whole thing. So, we ignore the attached window and explicitly |
| 2899 | // compute the frames that would be appropriate without the dock. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2900 | df.left = of.left = cf.left = vf.left = mDockLeft; |
| 2901 | df.top = of.top = cf.top = vf.top = mDockTop; |
| 2902 | df.right = of.right = cf.right = vf.right = mDockRight; |
| 2903 | df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2904 | } else { |
| 2905 | // The effective display frame of the attached window depends on |
| 2906 | // whether it is taking care of insetting its content. If not, |
| 2907 | // we need to use the parent's content frame so that the entire |
| 2908 | // window is positioned within that content. Otherwise we can use |
| 2909 | // the display frame and let the attached window take care of |
| 2910 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 2911 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2912 | cf.set(attached.getOverscanFrameLw()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2913 | } else { |
| 2914 | // If the window is resizing, then we want to base the content |
| 2915 | // frame on our attached content frame to resize... however, |
| 2916 | // things can be tricky if the attached window is NOT in resize |
| 2917 | // mode, in which case its content frame will be larger. |
| 2918 | // Ungh. So to deal with that, make sure the content frame |
| 2919 | // we end up using is not covering the IM dock. |
| 2920 | cf.set(attached.getContentFrameLw()); |
| 2921 | if (attached.getSurfaceLayer() < mDockLayer) { |
| 2922 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 2923 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 2924 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 2925 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 2926 | } |
| 2927 | } |
| 2928 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2929 | of.set(insetDecors ? attached.getOverscanFrameLw() : cf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2930 | vf.set(attached.getVisibleFrameLw()); |
| 2931 | } |
| 2932 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 2933 | // window should be positioned relative to its parent or the entire |
| 2934 | // screen. |
| 2935 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 2936 | ? attached.getFrameLw() : df); |
| 2937 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 2938 | |
| 2939 | private void applyStableConstraints(int sysui, int fl, Rect r) { |
| 2940 | if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) { |
| 2941 | // If app is requesting a stable layout, don't let the |
| 2942 | // content insets go below the stable values. |
| 2943 | if ((fl & FLAG_FULLSCREEN) != 0) { |
| 2944 | if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft; |
| 2945 | if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop; |
| 2946 | if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight; |
| 2947 | if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom; |
| 2948 | } else { |
| 2949 | if (r.left < mStableLeft) r.left = mStableLeft; |
| 2950 | if (r.top < mStableTop) r.top = mStableTop; |
| 2951 | if (r.right > mStableRight) r.right = mStableRight; |
| 2952 | if (r.bottom > mStableBottom) r.bottom = mStableBottom; |
| 2953 | } |
| 2954 | } |
| 2955 | } |
| 2956 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2957 | /** {@inheritDoc} */ |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2958 | @Override |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 2959 | public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs, |
| 2960 | WindowState attached) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2961 | // we've already done the status bar |
Dianne Hackborn | 1f903c3 | 2011-09-13 19:18:06 -0700 | [diff] [blame] | 2962 | if (win == mStatusBar || win == mNavigationBar) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2963 | return; |
| 2964 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2965 | final boolean isDefaultDisplay = win.isDefaultDisplay(); |
| 2966 | final boolean needsToOffsetInputMethodTarget = isDefaultDisplay && |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 2967 | (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null); |
| 2968 | if (needsToOffsetInputMethodTarget) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 2969 | 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] | 2970 | offsetInputMethodWindowLw(mLastInputMethodWindow); |
| 2971 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2972 | |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 2973 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2974 | final int sim = attrs.softInputMode; |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 2975 | final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 2976 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2977 | final Rect pf = mTmpParentFrame; |
| 2978 | final Rect df = mTmpDisplayFrame; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2979 | final Rect of = mTmpOverscanFrame; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2980 | final Rect cf = mTmpContentFrame; |
| 2981 | final Rect vf = mTmpVisibleFrame; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 2982 | final Rect dcf = mTmpDecorFrame; |
| 2983 | dcf.setEmpty(); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2984 | |
| 2985 | final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 2986 | && mNavigationBar != null && mNavigationBar.isVisibleLw()); |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 2987 | |
Craig Mautner | f683b56 | 2012-10-02 11:10:57 -0700 | [diff] [blame] | 2988 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 2989 | |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2990 | if (!isDefaultDisplay) { |
| 2991 | if (attached != null) { |
| 2992 | // If this window is attached to another, our display |
| 2993 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2994 | setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 2995 | } else { |
| 2996 | // Give the window full screen. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 2997 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 2998 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 2999 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3000 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3001 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3002 | = mOverscanScreenTop + mOverscanScreenHeight; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3003 | } |
| 3004 | } else if (attrs.type == TYPE_INPUT_METHOD) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3005 | pf.left = df.left = of.left = cf.left = vf.left = mDockLeft; |
| 3006 | pf.top = df.top = of.top = cf.top = vf.top = mDockTop; |
| 3007 | pf.right = df.right = of.right = cf.right = vf.right = mDockRight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3008 | // IM dock windows layout below the nav bar... |
John Spurlock | 57beb3b | 2013-10-10 10:27:44 -0400 | [diff] [blame] | 3009 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | c68d577 | 2013-10-08 11:47:58 -0400 | [diff] [blame] | 3010 | // ...with content insets above the nav bar |
| 3011 | cf.bottom = vf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3012 | // IM dock windows always go to the bottom of the screen. |
| 3013 | attrs.gravity = Gravity.BOTTOM; |
| 3014 | mDockLayer = win.getSurfaceLayer(); |
| 3015 | } else { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3016 | |
| 3017 | // Default policy decor for the default display |
| 3018 | dcf.left = mSystemLeft; |
| 3019 | dcf.top = mSystemTop; |
| 3020 | dcf.right = mSystemRight; |
| 3021 | dcf.bottom = mSystemBottom; |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3022 | final boolean inheritTranslucentDecor = (attrs.privateFlags |
| 3023 | & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0; |
John Spurlock | 65567d4 | 2013-10-08 10:08:32 -0400 | [diff] [blame] | 3024 | final boolean isAppWindow = |
| 3025 | attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW && |
| 3026 | attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 3027 | final boolean topAtRest = |
| 3028 | win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw(); |
| 3029 | if (isAppWindow && !inheritTranslucentDecor && !topAtRest) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3030 | if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0 |
| 3031 | && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0 |
| 3032 | && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3033 | // Ensure policy decor includes status bar |
| 3034 | dcf.top = mStableTop; |
| 3035 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3036 | if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0 |
John Spurlock | 8e0ca28 | 2013-10-03 11:46:06 -0400 | [diff] [blame] | 3037 | && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) { |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3038 | // Ensure policy decor includes navigation bar |
| 3039 | dcf.bottom = mStableBottom; |
| 3040 | dcf.right = mStableRight; |
| 3041 | } |
| 3042 | } |
| 3043 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3044 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 3045 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3046 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3047 | + "): IN_SCREEN, INSET_DECOR"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3048 | // This is the case for a normal activity window: we want it |
| 3049 | // to cover all of the screen space, and it can take care of |
| 3050 | // moving its contents to account for screen decorations that |
| 3051 | // intrude into that space. |
| 3052 | if (attached != null) { |
| 3053 | // If this window is attached to another, our display |
| 3054 | // frame is the same as the one we are attached to. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3055 | 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] | 3056 | } else { |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3057 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3058 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3059 | // Status bar panels are the only windows who can go on top of |
| 3060 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3061 | // permission, so they have the same privileges as the status |
| 3062 | // bar itself. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3063 | // |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3064 | // However, they should still dodge the navigation bar if it exists. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3065 | |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3066 | pf.left = df.left = of.left = hasNavBar |
| 3067 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3068 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3069 | pf.right = df.right = of.right = hasNavBar |
| 3070 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
| 3071 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3072 | pf.bottom = df.bottom = of.bottom = hasNavBar |
| 3073 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
| 3074 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3075 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3076 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3077 | "Laying out status bar window: (%d,%d - %d,%d)", |
| 3078 | pf.left, pf.top, pf.right, pf.bottom)); |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3079 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3080 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3081 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3082 | // Asking to layout into the overscan region, so give it that pure |
| 3083 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3084 | pf.left = df.left = of.left = mOverscanScreenLeft; |
| 3085 | pf.top = df.top = of.top = mOverscanScreenTop; |
| 3086 | pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3087 | pf.bottom = df.bottom = of.bottom = mOverscanScreenTop |
| 3088 | + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3089 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3090 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3091 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3092 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3093 | // Asking for layout as if the nav bar is hidden, lets the |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3094 | // application extend into the unrestricted overscan screen area. We |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3095 | // only do this for application windows to ensure no window that |
| 3096 | // can be above the nav bar can do this. |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3097 | pf.left = df.left = mOverscanScreenLeft; |
| 3098 | pf.top = df.top = mOverscanScreenTop; |
| 3099 | pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth; |
| 3100 | pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3101 | // We need to tell the app about where the frame inside the overscan |
| 3102 | // is, so it can inset its content by that amount -- it didn't ask |
| 3103 | // to actually extend itself into the overscan region. |
| 3104 | of.left = mUnrestrictedScreenLeft; |
| 3105 | of.top = mUnrestrictedScreenTop; |
| 3106 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3107 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3108 | } else { |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 3109 | pf.left = df.left = mRestrictedOverscanScreenLeft; |
| 3110 | pf.top = df.top = mRestrictedOverscanScreenTop; |
| 3111 | pf.right = df.right = mRestrictedOverscanScreenLeft |
| 3112 | + mRestrictedOverscanScreenWidth; |
| 3113 | pf.bottom = df.bottom = mRestrictedOverscanScreenTop |
| 3114 | + mRestrictedOverscanScreenHeight; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3115 | // We need to tell the app about where the frame inside the overscan |
| 3116 | // is, so it can inset its content by that amount -- it didn't ask |
| 3117 | // to actually extend itself into the overscan region. |
| 3118 | of.left = mUnrestrictedScreenLeft; |
| 3119 | of.top = mUnrestrictedScreenTop; |
| 3120 | of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
| 3121 | of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3122 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3123 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3124 | if ((fl & FLAG_FULLSCREEN) == 0) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3125 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 3126 | cf.left = mDockLeft; |
| 3127 | cf.top = mDockTop; |
| 3128 | cf.right = mDockRight; |
| 3129 | cf.bottom = mDockBottom; |
| 3130 | } else { |
| 3131 | cf.left = mContentLeft; |
| 3132 | cf.top = mContentTop; |
| 3133 | cf.right = mContentRight; |
| 3134 | cf.bottom = mContentBottom; |
| 3135 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3136 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3137 | // Full screen windows are always given a layout that is as if the |
| 3138 | // status bar and other transient decors are gone. This is to avoid |
| 3139 | // bad states when moving from a window that is not hding the |
| 3140 | // status bar to one that is. |
| 3141 | cf.left = mRestrictedScreenLeft; |
| 3142 | cf.top = mRestrictedScreenTop; |
| 3143 | cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth; |
| 3144 | cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3145 | } |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3146 | applyStableConstraints(sysUiFl, fl, cf); |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3147 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3148 | vf.left = mCurLeft; |
| 3149 | vf.top = mCurTop; |
| 3150 | vf.right = mCurRight; |
| 3151 | vf.bottom = mCurBottom; |
| 3152 | } else { |
| 3153 | vf.set(cf); |
| 3154 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3155 | } |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3156 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl |
| 3157 | & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 3158 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3159 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3160 | "): IN_SCREEN"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3161 | // A window that has requested to fill the entire screen just |
| 3162 | // gets everything, period. |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3163 | if (attrs.type == TYPE_STATUS_BAR_PANEL |
| 3164 | || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3165 | pf.left = df.left = of.left = cf.left = hasNavBar |
| 3166 | ? mDockLeft : mUnrestrictedScreenLeft; |
| 3167 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3168 | pf.right = df.right = of.right = cf.right = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3169 | ? mRestrictedScreenLeft+mRestrictedScreenWidth |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3170 | : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3171 | pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3172 | ? mRestrictedScreenTop+mRestrictedScreenHeight |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3173 | : mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3174 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 36412a7 | 2011-08-04 09:35:13 -0400 | [diff] [blame] | 3175 | "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)", |
| 3176 | pf.left, pf.top, pf.right, pf.bottom)); |
Jim Miller | e898ac5 | 2012-04-06 17:10:57 -0700 | [diff] [blame] | 3177 | } else if (attrs.type == TYPE_NAVIGATION_BAR |
| 3178 | || attrs.type == TYPE_NAVIGATION_BAR_PANEL) { |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3179 | // The navigation bar has Real Ultimate Power. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3180 | pf.left = df.left = of.left = mUnrestrictedScreenLeft; |
| 3181 | pf.top = df.top = of.top = mUnrestrictedScreenTop; |
| 3182 | pf.right = df.right = of.right = mUnrestrictedScreenLeft |
| 3183 | + mUnrestrictedScreenWidth; |
| 3184 | pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop |
| 3185 | + mUnrestrictedScreenHeight; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3186 | if (DEBUG_LAYOUT) Slog.v(TAG, String.format( |
Daniel Sandler | 8e8b415 | 2011-07-21 01:16:43 -0400 | [diff] [blame] | 3187 | "Laying out navigation bar window: (%d,%d - %d,%d)", |
| 3188 | pf.left, pf.top, pf.right, pf.bottom)); |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3189 | } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY |
| 3190 | || attrs.type == TYPE_BOOT_PROGRESS) |
Jeff Brown | bfcb60a | 2011-09-08 18:51:14 -0700 | [diff] [blame] | 3191 | && ((fl & FLAG_FULLSCREEN) != 0)) { |
| 3192 | // Fullscreen secure system overlays get what they ask for. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3193 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3194 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3195 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3196 | + mOverscanScreenWidth; |
| 3197 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3198 | + mOverscanScreenHeight; |
Dianne Hackborn | a4b7f2f | 2012-05-21 11:28:41 -0700 | [diff] [blame] | 3199 | } else if (attrs.type == TYPE_BOOT_PROGRESS |
| 3200 | || attrs.type == TYPE_UNIVERSE_BACKGROUND) { |
Dianne Hackborn | 01011c3 | 2012-02-21 13:54:21 -0800 | [diff] [blame] | 3201 | // Boot progress screen always covers entire display. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3202 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3203 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3204 | pf.right = df.right = of.right = cf.right = mOverscanScreenLeft |
| 3205 | + mOverscanScreenWidth; |
| 3206 | pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop |
| 3207 | + mOverscanScreenHeight; |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3208 | } else if (attrs.type == TYPE_WALLPAPER) { |
| 3209 | // The wallpaper also has Real Ultimate Power. |
| 3210 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3211 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3212 | pf.right = df.right = of.right = cf.right |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3213 | = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3214 | pf.bottom = df.bottom = of.bottom = cf.bottom |
John Spurlock | ef4adae | 2013-08-26 17:58:58 -0400 | [diff] [blame] | 3215 | = mUnrestrictedScreenTop + mUnrestrictedScreenHeight; |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3216 | } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0 |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3217 | && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3218 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 3219 | // Asking to layout into the overscan region, so give it that pure |
| 3220 | // unrestricted area. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3221 | pf.left = df.left = of.left = cf.left = mOverscanScreenLeft; |
| 3222 | pf.top = df.top = of.top = cf.top = mOverscanScreenTop; |
| 3223 | pf.right = df.right = of.right = cf.right |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3224 | = mOverscanScreenLeft + mOverscanScreenWidth; |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3225 | pf.bottom = df.bottom = of.bottom = cf.bottom |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 3226 | = mOverscanScreenTop + mOverscanScreenHeight; |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 3227 | } else if (canHideNavigationBar() |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3228 | && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0 |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3229 | && (attrs.type == TYPE_TOAST |
| 3230 | || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW |
| 3231 | && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) { |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3232 | // Asking for layout as if the nav bar is hidden, lets the |
| 3233 | // application extend into the unrestricted screen area. We |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 3234 | // 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] | 3235 | // can be above the nav bar can do this. |
| 3236 | // XXX This assumes that an app asking for this will also |
| 3237 | // ask for layout in only content. We can't currently figure out |
| 3238 | // 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] | 3239 | pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft; |
| 3240 | pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop; |
| 3241 | pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft |
| 3242 | + mUnrestrictedScreenWidth; |
| 3243 | pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop |
| 3244 | + mUnrestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3245 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3246 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3247 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3248 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3249 | + mRestrictedScreenWidth; |
| 3250 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3251 | + mRestrictedScreenHeight; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 3252 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3253 | |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 3254 | applyStableConstraints(sysUiFl, fl, cf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3255 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3256 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3257 | vf.left = mCurLeft; |
| 3258 | vf.top = mCurTop; |
| 3259 | vf.right = mCurRight; |
| 3260 | vf.bottom = mCurBottom; |
| 3261 | } else { |
| 3262 | vf.set(cf); |
| 3263 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3264 | } else if (attached != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3265 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3266 | "): attached to " + attached); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3267 | // A child window should be placed inside of the same visible |
| 3268 | // frame that its parent had. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3269 | 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] | 3270 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3271 | if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() + |
| 3272 | "): normal window"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3273 | // Otherwise, a normal window must be placed inside the content |
| 3274 | // of all screen decorations. |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3275 | if (attrs.type == TYPE_STATUS_BAR_PANEL) { |
| 3276 | // Status bar panels are the only windows who can go on top of |
| 3277 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 3278 | // permission, so they have the same privileges as the status |
| 3279 | // bar itself. |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3280 | pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft; |
| 3281 | pf.top = df.top = of.top = cf.top = mRestrictedScreenTop; |
| 3282 | pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft |
| 3283 | + mRestrictedScreenWidth; |
| 3284 | pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop |
| 3285 | + mRestrictedScreenHeight; |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 3286 | } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT |
| 3287 | || attrs.type == TYPE_VOLUME_OVERLAY) { |
| 3288 | // These dialogs are stable to interim decor changes. |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 3289 | pf.left = df.left = of.left = cf.left = mStableLeft; |
| 3290 | pf.top = df.top = of.top = cf.top = mStableTop; |
| 3291 | pf.right = df.right = of.right = cf.right = mStableRight; |
| 3292 | pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3293 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3294 | pf.left = mContentLeft; |
| 3295 | pf.top = mContentTop; |
| 3296 | pf.right = mContentRight; |
| 3297 | pf.bottom = mContentBottom; |
| 3298 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3299 | df.left = of.left = cf.left = mDockLeft; |
| 3300 | df.top = of.top = cf.top = mDockTop; |
| 3301 | df.right = of.right = cf.right = mDockRight; |
| 3302 | df.bottom = of.bottom = cf.bottom = mDockBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3303 | } else { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3304 | df.left = of.left = cf.left = mContentLeft; |
| 3305 | df.top = of.top = cf.top = mContentTop; |
| 3306 | df.right = of.right = cf.right = mContentRight; |
| 3307 | df.bottom = of.bottom = cf.bottom = mContentBottom; |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame] | 3308 | } |
| 3309 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 3310 | vf.left = mCurLeft; |
| 3311 | vf.top = mCurTop; |
| 3312 | vf.right = mCurRight; |
| 3313 | vf.bottom = mCurBottom; |
| 3314 | } else { |
| 3315 | vf.set(cf); |
| 3316 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 3317 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3318 | } |
| 3319 | } |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3320 | |
Craig Mautner | b816bed | 2013-07-23 10:26:17 -0700 | [diff] [blame] | 3321 | // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it. |
| 3322 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) { |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3323 | df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 3324 | df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom |
| 3325 | = vf.right = vf.bottom = 10000; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3326 | } |
| 3327 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3328 | 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] | 3329 | + ": sim=#" + Integer.toHexString(sim) |
Daniel Sandler | 8956dbb | 2011-04-22 07:55:02 -0400 | [diff] [blame] | 3330 | + " attach=" + attached + " type=" + attrs.type |
| 3331 | + String.format(" flags=0x%08x", fl) |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3332 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
Dianne Hackborn | c4aad01 | 2013-02-22 15:05:25 -0800 | [diff] [blame] | 3333 | + " of=" + of.toShortString() |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3334 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString() |
| 3335 | + " dcf=" + dcf.toShortString()); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3336 | |
John Spurlock | 4664623 | 2013-09-30 22:32:42 -0400 | [diff] [blame] | 3337 | win.computeFrameLw(pf, df, of, cf, vf, dcf); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 3338 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3339 | // Dock windows carve out the bottom of the screen, so normal windows |
| 3340 | // can't appear underneath them. |
Craig Mautner | 8bd206b | 2012-10-03 10:32:02 -0700 | [diff] [blame] | 3341 | if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw() |
| 3342 | && !win.getGivenInsetsPendingLw()) { |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3343 | setLastInputMethodWindowLw(null, null); |
| 3344 | offsetInputMethodWindowLw(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3345 | } |
| 3346 | } |
| 3347 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3348 | private void offsetInputMethodWindowLw(WindowState win) { |
| 3349 | int top = win.getContentFrameLw().top; |
| 3350 | top += win.getGivenContentInsetsLw().top; |
| 3351 | if (mContentBottom > top) { |
| 3352 | mContentBottom = top; |
| 3353 | } |
| 3354 | top = win.getVisibleFrameLw().top; |
| 3355 | top += win.getGivenVisibleInsetsLw().top; |
| 3356 | if (mCurBottom > top) { |
| 3357 | mCurBottom = top; |
| 3358 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3359 | if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom=" |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 3360 | + mDockBottom + " mContentBottom=" |
| 3361 | + mContentBottom + " mCurBottom=" + mCurBottom); |
| 3362 | } |
| 3363 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3364 | /** {@inheritDoc} */ |
Craig Mautner | 61ac6bb | 2012-02-02 17:29:33 -0800 | [diff] [blame] | 3365 | @Override |
| 3366 | public void finishLayoutLw() { |
| 3367 | return; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3368 | } |
| 3369 | |
| 3370 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3371 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3372 | public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3373 | mTopFullscreenOpaqueWindowState = null; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 3374 | mAppsToBeHidden.clear(); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3375 | mForceStatusBar = false; |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3376 | mForceStatusBarFromKeyguard = false; |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3377 | mForcingShowNavBar = false; |
| 3378 | mForcingShowNavBarLayer = -1; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3379 | |
| 3380 | mHideLockScreen = false; |
| 3381 | mAllowLockscreenWhenOn = false; |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3382 | mDismissKeyguard = DISMISS_KEYGUARD_NONE; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3383 | mShowingLockscreen = false; |
| 3384 | mShowingDream = false; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3385 | } |
| 3386 | |
| 3387 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3388 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3389 | public void applyPostLayoutPolicyLw(WindowState win, |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3390 | WindowManager.LayoutParams attrs) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3391 | if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw=" |
| 3392 | + win.isVisibleOrBehindKeyguardLw()); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3393 | final int fl = PolicyControl.getWindowFlags(win, attrs); |
John Spurlock | 414c1f0 | 2013-12-04 13:47:36 -0500 | [diff] [blame] | 3394 | if (mTopFullscreenOpaqueWindowState == null |
| 3395 | && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) { |
| 3396 | mForcingShowNavBar = true; |
| 3397 | mForcingShowNavBarLayer = win.getSurfaceLayer(); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 3398 | } |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 3399 | if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Jorim Jaggi | afd4a55 | 2014-04-08 15:13:05 +0200 | [diff] [blame] | 3400 | mForceStatusBarFromKeyguard = true; |
| 3401 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3402 | if (mTopFullscreenOpaqueWindowState == null && |
Dianne Hackborn | 01b02a7 | 2012-01-12 14:05:03 -0800 | [diff] [blame] | 3403 | win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3404 | if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3405 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3406 | mForceStatusBarFromKeyguard = true; |
| 3407 | } else { |
| 3408 | mForceStatusBar = true; |
| 3409 | } |
| 3410 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3411 | if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) { |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3412 | mShowingLockscreen = true; |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 3413 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3414 | boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3415 | && attrs.type <= LAST_APPLICATION_WINDOW; |
| 3416 | if (attrs.type == TYPE_DREAM) { |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 3417 | // If the lockscreen was showing when the dream started then wait |
| 3418 | // for the dream to draw before hiding the lockscreen. |
| 3419 | if (!mDreamingLockscreen |
| 3420 | || (win.isVisibleLw() && win.hasDrawnLw())) { |
| 3421 | mShowingDream = true; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3422 | appWindow = true; |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3423 | } |
| 3424 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3425 | |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 3426 | final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0; |
Craig Mautner | 74ee938 | 2014-04-01 15:20:16 -0700 | [diff] [blame] | 3427 | final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0; |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3428 | if (appWindow) { |
Craig Mautner | 4bdab6b | 2014-04-01 12:05:11 -0700 | [diff] [blame] | 3429 | if (showWhenLocked || (dismissKeyguard && !isKeyguardSecure())) { |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 3430 | mAppsToBeHidden.remove(win.getAppToken()); |
| 3431 | } else { |
| 3432 | mAppsToBeHidden.add(win.getAppToken()); |
| 3433 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3434 | if (attrs.x == 0 && attrs.y == 0 |
| 3435 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 3436 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { |
| 3437 | if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win); |
| 3438 | mTopFullscreenOpaqueWindowState = win; |
Craig Mautner | 2bc789b | 2014-03-19 19:48:38 -0700 | [diff] [blame] | 3439 | if (mAppsToBeHidden.isEmpty()) { |
Craig Mautner | da09ae3 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3440 | if (showWhenLocked) { |
| 3441 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 3442 | "Setting mHideLockScreen to true by win " + win); |
| 3443 | mHideLockScreen = true; |
| 3444 | mForceStatusBarFromKeyguard = false; |
| 3445 | } |
Craig Mautner | 4bdab6b | 2014-04-01 12:05:11 -0700 | [diff] [blame] | 3446 | if (dismissKeyguard && mDismissKeyguard == DISMISS_KEYGUARD_NONE) { |
Craig Mautner | da09ae3 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3447 | if (DEBUG_LAYOUT) Slog.v(TAG, |
| 3448 | "Setting mDismissKeyguard true by win " + win); |
| 3449 | mDismissKeyguard = mWinDismissingKeyguard == win ? |
| 3450 | DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START; |
| 3451 | mWinDismissingKeyguard = win; |
| 3452 | mForceStatusBarFromKeyguard = mShowingLockscreen && isKeyguardSecure(); |
| 3453 | } |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3454 | } |
Craig Mautner | 00156ec | 2014-03-06 22:29:02 -0800 | [diff] [blame] | 3455 | if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
Craig Mautner | ab55e52 | 2014-03-03 13:26:03 -0800 | [diff] [blame] | 3456 | mAllowLockscreenWhenOn = true; |
| 3457 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 3458 | } |
| 3459 | } |
| 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | /** {@inheritDoc} */ |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 3464 | @Override |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3465 | public int finishPostLayoutPolicyLw() { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3466 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3467 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3468 | |
| 3469 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 3470 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 3471 | : null; |
| 3472 | |
Jeff Brown | c8018eb | 2012-10-29 21:33:27 -0700 | [diff] [blame] | 3473 | // If we are not currently showing a dream then remember the current |
| 3474 | // lockscreen state. We will use this to determine whether the dream |
| 3475 | // started while the lockscreen was showing and remember this state |
| 3476 | // while the dream is showing. |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 3477 | if (!mShowingDream) { |
| 3478 | mDreamingLockscreen = mShowingLockscreen; |
| 3479 | } |
| 3480 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3481 | if (mStatusBar != null) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3482 | if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3483 | + " forcefkg=" + mForceStatusBarFromKeyguard |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 3484 | + " top=" + mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 3485 | if (mForceStatusBar || mForceStatusBarFromKeyguard) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3486 | if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3487 | if (mStatusBarController.setBarShowingLw(true)) { |
| 3488 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3489 | } |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 3490 | // Maintain fullscreen layout until incoming animation is complete. |
| 3491 | topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw(); |
John Spurlock | f92b616 | 2013-11-11 15:01:16 -0500 | [diff] [blame] | 3492 | // Transient status bar on the lockscreen is not allowed |
| 3493 | if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) { |
| 3494 | mStatusBarController.updateVisibilityLw(false /*transientAllowed*/, |
| 3495 | mLastSystemUiFlags, mLastSystemUiFlags); |
| 3496 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3497 | } else if (mTopFullscreenOpaqueWindowState != null) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3498 | final int fl = PolicyControl.getWindowFlags(null, lp); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3499 | if (localLOGV) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3500 | Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3501 | + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3502 | Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3503 | + " lp.flags=0x" + Integer.toHexString(fl)); |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3504 | } |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 3505 | topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0 |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3506 | || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 3507 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
| 3508 | // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window |
| 3509 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 3510 | // case though. |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3511 | if (mStatusBarController.isTransientShowing()) { |
| 3512 | if (mStatusBarController.setBarShowingLw(true)) { |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 3513 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3514 | } |
| 3515 | } else if (topIsFullscreen) { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3516 | if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar"); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 3517 | if (mStatusBarController.setBarShowingLw(false)) { |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3518 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3519 | } else { |
Craig Mautner | c5a6e44 | 2013-06-05 17:22:35 -0700 | [diff] [blame] | 3520 | if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding"); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 3521 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3522 | } else { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 3523 | 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] | 3524 | if (mStatusBarController.setBarShowingLw(true)) { |
| 3525 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3526 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3527 | } |
| 3528 | } |
| 3529 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3530 | |
Craig Mautner | 81defc7 | 2013-10-29 11:10:42 -0700 | [diff] [blame] | 3531 | if (mTopIsFullscreen != topIsFullscreen) { |
| 3532 | if (!topIsFullscreen) { |
| 3533 | // Force another layout when status bar becomes fully shown. |
| 3534 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3535 | } |
| 3536 | mTopIsFullscreen = topIsFullscreen; |
| 3537 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 3538 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 3539 | // Hide the key guard if a visible window explicitly specifies that it wants to be |
| 3540 | // displayed when the screen is locked. |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3541 | if (mKeyguardDelegate != null && mStatusBar != null) { |
| 3542 | if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard=" |
| 3543 | + mHideLockScreen); |
| 3544 | if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) { |
| 3545 | mKeyguardHidden = true; |
| 3546 | if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3547 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3548 | | FINISH_LAYOUT_REDO_CONFIG |
| 3549 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3550 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3551 | if (mKeyguardDelegate.isShowing()) { |
| 3552 | mHandler.post(new Runnable() { |
| 3553 | @Override |
| 3554 | public void run() { |
| 3555 | mKeyguardDelegate.keyguardDone(false, false); |
| 3556 | } |
| 3557 | }); |
| 3558 | } |
| 3559 | } else if (mHideLockScreen) { |
| 3560 | mKeyguardHidden = true; |
| 3561 | if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) { |
| 3562 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3563 | | FINISH_LAYOUT_REDO_CONFIG |
| 3564 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3565 | } |
| 3566 | } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) { |
| 3567 | // This is the case of keyguard isSecure() and not mHideLockScreen. |
| 3568 | if (mDismissKeyguard == DISMISS_KEYGUARD_START) { |
| 3569 | // Only launch the next keyguard unlock window once per window. |
| 3570 | mKeyguardHidden = false; |
| 3571 | if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) { |
| 3572 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3573 | | FINISH_LAYOUT_REDO_CONFIG |
| 3574 | | FINISH_LAYOUT_REDO_WALLPAPER; |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3575 | } |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3576 | mHandler.post(new Runnable() { |
| 3577 | @Override |
| 3578 | public void run() { |
| 3579 | mKeyguardDelegate.dismiss(); |
| 3580 | } |
| 3581 | }); |
| 3582 | } |
| 3583 | } else { |
| 3584 | mWinDismissingKeyguard = null; |
| 3585 | mKeyguardHidden = false; |
| 3586 | if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) { |
| 3587 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 3588 | | FINISH_LAYOUT_REDO_CONFIG |
| 3589 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 3590 | } |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 3591 | } |
| 3592 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3593 | |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3594 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3595 | // If the navigation bar has been hidden or shown, we need to do another |
| 3596 | // layout pass to update that window. |
| 3597 | changes |= FINISH_LAYOUT_REDO_LAYOUT; |
| 3598 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3599 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 3600 | // update since mAllowLockscreenWhenOn might have changed |
| 3601 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 3602 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3603 | } |
| 3604 | |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3605 | /** |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3606 | * Processes the result code of {@link IKeyguardService#setOccluded}. This is needed because we |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3607 | * immediately need to put the wallpaper directly behind the Keyguard when a window with flag |
| 3608 | * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we |
| 3609 | * would wait for Keyguard to change the flags, that would be running asynchronously and thus be |
| 3610 | * too late so the user might see the window behind. |
| 3611 | * |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3612 | * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}. |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3613 | * @return Whether the flags have changed and we have to redo the layout. |
| 3614 | */ |
| 3615 | private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3616 | if (setHiddenResult |
| 3617 | == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3618 | mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD; |
| 3619 | mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER; |
| 3620 | return true; |
| 3621 | } else if (setHiddenResult |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3622 | == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3623 | mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD; |
| 3624 | mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER; |
| 3625 | return true; |
| 3626 | } else { |
| 3627 | return false; |
| 3628 | } |
| 3629 | } |
| 3630 | |
| 3631 | private boolean isStatusBarKeyguard() { |
| 3632 | return mStatusBar != null |
| 3633 | && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0; |
| 3634 | } |
| 3635 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3636 | public boolean allowAppAnimationsLw() { |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 3637 | if (isStatusBarKeyguard() || mShowingDream) { |
Craig Mautner | 2881630 | 2013-10-10 20:31:00 -0700 | [diff] [blame] | 3638 | // 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] | 3639 | return false; |
| 3640 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 3641 | return true; |
| 3642 | } |
| 3643 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3644 | public int focusChangedLw(WindowState lastFocus, WindowState newFocus) { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3645 | mFocusedWindow = newFocus; |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 3646 | if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 3647 | // If the navigation bar has been hidden or shown, we need to do another |
| 3648 | // layout pass to update that window. |
| 3649 | return FINISH_LAYOUT_REDO_LAYOUT; |
| 3650 | } |
| 3651 | return 0; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3652 | } |
| 3653 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 3654 | /** {@inheritDoc} */ |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3655 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 3656 | // lid changed state |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3657 | final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED; |
| 3658 | if (newLidState == mLidState) { |
| 3659 | return; |
| 3660 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 3661 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3662 | mLidState = newLidState; |
| 3663 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 3664 | updateRotation(true); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3665 | |
| 3666 | if (lidOpen) { |
Jim Miller | e51cf7ae | 2013-06-25 18:31:56 -0700 | [diff] [blame] | 3667 | mPowerManager.wakeUp(SystemClock.uptimeMillis()); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 3668 | } else if (!mLidControlsSleep) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3669 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 3670 | } |
| 3671 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3672 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3673 | void setHdmiPlugged(boolean plugged) { |
| 3674 | if (mHdmiPlugged != plugged) { |
| 3675 | mHdmiPlugged = plugged; |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 3676 | updateRotation(true, true); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3677 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 3678 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3679 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 3680 | mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 3681 | } |
| 3682 | } |
| 3683 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 3684 | void initializeHdmiState() { |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 3685 | boolean plugged = false; |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 3686 | // watch for HDMI plug messages if the hdmi switch exists |
| 3687 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 3688 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 3689 | |
Joe Onorato | ea495d4 | 2011-04-06 11:41:11 -0700 | [diff] [blame] | 3690 | final String filename = "/sys/class/switch/hdmi/state"; |
| 3691 | FileReader reader = null; |
| 3692 | try { |
| 3693 | reader = new FileReader(filename); |
| 3694 | char[] buf = new char[15]; |
| 3695 | int n = reader.read(buf); |
| 3696 | if (n > 1) { |
| 3697 | plugged = 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 3698 | } |
| 3699 | } catch (IOException ex) { |
| 3700 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 3701 | } catch (NumberFormatException ex) { |
| 3702 | Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex); |
| 3703 | } finally { |
| 3704 | if (reader != null) { |
| 3705 | try { |
| 3706 | reader.close(); |
| 3707 | } catch (IOException ex) { |
| 3708 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 3709 | } |
| 3710 | } |
| 3711 | } |
Joe Onorato | 7ba631f | 2011-05-04 15:28:00 -0700 | [diff] [blame] | 3712 | // This dance forces the code in setHdmiPlugged to run. |
| 3713 | // Always do this so the sticky intent is stuck (to false) if there is no hdmi. |
| 3714 | mHdmiPlugged = !plugged; |
| 3715 | setHdmiPlugged(!mHdmiPlugged); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 3716 | } |
| 3717 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3718 | /** |
Jean-Michel Trivi | fca1e60 | 2013-10-10 18:12:59 -0700 | [diff] [blame] | 3719 | * @return Whether music is being played right now "locally" (e.g. on the device's speakers |
| 3720 | * or wired headphones) or "remotely" (e.g. on a device using the Cast protocol and |
| 3721 | * controlled by this device, or through remote submix). |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3722 | */ |
| 3723 | boolean isMusicActive() { |
Eric Laurent | 413cb9d | 2009-07-17 11:52:43 -0700 | [diff] [blame] | 3724 | final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); |
| 3725 | if (am == null) { |
| 3726 | Log.w(TAG, "isMusicActive: couldn't get AudioManager reference"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3727 | return false; |
| 3728 | } |
Jean-Michel Trivi | fca1e60 | 2013-10-10 18:12:59 -0700 | [diff] [blame] | 3729 | return am.isLocalOrRemoteMusicActive(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3730 | } |
| 3731 | |
| 3732 | /** |
| 3733 | * Tell the audio service to adjust the volume appropriate to the event. |
| 3734 | * @param keycode |
| 3735 | */ |
Mike Lockwood | a53e381 | 2009-09-25 10:51:39 -0400 | [diff] [blame] | 3736 | void handleVolumeKey(int stream, int keycode) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3737 | IAudioService audioService = getAudioService(); |
| 3738 | if (audioService == null) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3739 | return; |
| 3740 | } |
| 3741 | try { |
Jean-Michel Trivi | fca1e60 | 2013-10-10 18:12:59 -0700 | [diff] [blame] | 3742 | // 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] | 3743 | // 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] | 3744 | // that the music stops right before we call this. |
| 3745 | // Otherwise we might also be in a remote playback case. |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 3746 | // TODO: Actually handle MUTE. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3747 | mBroadcastWakeLock.acquire(); |
Jean-Michel Trivi | fca1e60 | 2013-10-10 18:12:59 -0700 | [diff] [blame] | 3748 | if (stream == AudioSystem.STREAM_MUSIC) { |
| 3749 | audioService.adjustLocalOrRemoteStreamVolume(stream, |
| 3750 | keycode == KeyEvent.KEYCODE_VOLUME_UP |
| 3751 | ? AudioManager.ADJUST_RAISE |
| 3752 | : AudioManager.ADJUST_LOWER, |
| 3753 | mContext.getOpPackageName()); |
| 3754 | } else { |
| 3755 | audioService.adjustStreamVolume(stream, |
| 3756 | keycode == KeyEvent.KEYCODE_VOLUME_UP |
| 3757 | ? AudioManager.ADJUST_RAISE |
| 3758 | : AudioManager.ADJUST_LOWER, |
| 3759 | 0, |
| 3760 | mContext.getOpPackageName()); |
| 3761 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3762 | } catch (RemoteException e) { |
Jean-Michel Trivi | fca1e60 | 2013-10-10 18:12:59 -0700 | [diff] [blame] | 3763 | Log.w(TAG, "IAudioService.adjust*StreamVolume() threw RemoteException " + e); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3764 | } finally { |
| 3765 | mBroadcastWakeLock.release(); |
| 3766 | } |
| 3767 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3768 | |
Dianne Hackborn | c0e3f24 | 2011-08-19 14:19:10 -0700 | [diff] [blame] | 3769 | final Object mScreenshotLock = new Object(); |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 3770 | ServiceConnection mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 3771 | |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3772 | final Runnable mScreenshotTimeout = new Runnable() { |
| 3773 | @Override public void run() { |
| 3774 | synchronized (mScreenshotLock) { |
| 3775 | if (mScreenshotConnection != null) { |
| 3776 | mContext.unbindService(mScreenshotConnection); |
| 3777 | mScreenshotConnection = null; |
Dianne Hackborn | fc8fa63 | 2011-08-17 16:20:47 -0700 | [diff] [blame] | 3778 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3779 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3780 | } |
| 3781 | }; |
| 3782 | |
| 3783 | // Assume this is called from the Handler thread. |
| 3784 | private void takeScreenshot() { |
| 3785 | synchronized (mScreenshotLock) { |
| 3786 | if (mScreenshotConnection != null) { |
| 3787 | return; |
| 3788 | } |
| 3789 | ComponentName cn = new ComponentName("com.android.systemui", |
| 3790 | "com.android.systemui.screenshot.TakeScreenshotService"); |
| 3791 | Intent intent = new Intent(); |
| 3792 | intent.setComponent(cn); |
| 3793 | ServiceConnection conn = new ServiceConnection() { |
| 3794 | @Override |
| 3795 | public void onServiceConnected(ComponentName name, IBinder service) { |
| 3796 | synchronized (mScreenshotLock) { |
| 3797 | if (mScreenshotConnection != this) { |
| 3798 | return; |
| 3799 | } |
| 3800 | Messenger messenger = new Messenger(service); |
| 3801 | Message msg = Message.obtain(null, 1); |
| 3802 | final ServiceConnection myConn = this; |
| 3803 | Handler h = new Handler(mHandler.getLooper()) { |
| 3804 | @Override |
| 3805 | public void handleMessage(Message msg) { |
| 3806 | synchronized (mScreenshotLock) { |
| 3807 | if (mScreenshotConnection == myConn) { |
| 3808 | mContext.unbindService(mScreenshotConnection); |
| 3809 | mScreenshotConnection = null; |
| 3810 | mHandler.removeCallbacks(mScreenshotTimeout); |
| 3811 | } |
| 3812 | } |
| 3813 | } |
| 3814 | }; |
| 3815 | msg.replyTo = new Messenger(h); |
Winson Chung | a63bb84 | 2011-10-17 10:26:28 -0700 | [diff] [blame] | 3816 | msg.arg1 = msg.arg2 = 0; |
| 3817 | if (mStatusBar != null && mStatusBar.isVisibleLw()) |
| 3818 | msg.arg1 = 1; |
| 3819 | if (mNavigationBar != null && mNavigationBar.isVisibleLw()) |
| 3820 | msg.arg2 = 1; |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3821 | try { |
| 3822 | messenger.send(msg); |
| 3823 | } catch (RemoteException e) { |
| 3824 | } |
| 3825 | } |
| 3826 | } |
| 3827 | @Override |
| 3828 | public void onServiceDisconnected(ComponentName name) {} |
| 3829 | }; |
Amith Yamasani | 27b89e6 | 2013-01-16 12:30:11 -0800 | [diff] [blame] | 3830 | if (mContext.bindServiceAsUser( |
| 3831 | intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3832 | mScreenshotConnection = conn; |
| 3833 | mHandler.postDelayed(mScreenshotTimeout, 10000); |
| 3834 | } |
| 3835 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 3836 | } |
| 3837 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3838 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3839 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 3840 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) { |
Jeff Brown | 9630704 | 2012-07-27 15:51:34 -0700 | [diff] [blame] | 3841 | if (!mSystemBooted) { |
| 3842 | // If we have not yet booted, don't let key events do anything. |
| 3843 | return 0; |
| 3844 | } |
| 3845 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 3846 | final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0; |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 3847 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 3848 | final boolean canceled = event.isCanceled(); |
| 3849 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 3850 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 3851 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 3852 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 3853 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 3854 | // the same as if it were open and in front. |
| 3855 | // This will prevent any keys other than the power button from waking the screen |
| 3856 | // when the keyguard is hidden by another activity. |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3857 | final boolean keyguardActive = (mKeyguardDelegate == null ? false : |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 3858 | (interactive ? |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 3859 | mKeyguardDelegate.isShowingAndNotOccluded() : |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 3860 | mKeyguardDelegate.isShowing())); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3861 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 3862 | if (DEBUG_INPUT) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 3863 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 3864 | + " interactive=" + interactive + " keyguardActive=" + keyguardActive |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 3865 | + " policyFlags=" + Integer.toHexString(policyFlags)); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3866 | } |
| 3867 | |
Jeff Brown | 98392ef | 2011-09-12 18:24:59 -0700 | [diff] [blame] | 3868 | if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0 |
| 3869 | && event.getRepeatCount() == 0) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3870 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 3871 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3872 | |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 3873 | // Basic policy based on interactive state. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3874 | int result; |
Michael Wright | 337d9d2 | 2014-04-22 15:03:48 -0700 | [diff] [blame^] | 3875 | boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0 |
| 3876 | || event.isWakeKey(); |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 3877 | if (interactive || (isInjected && !isWakeKey)) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3878 | // When the screen is on or if the key is injected pass the key to the application. |
| 3879 | result = ACTION_PASS_TO_USER; |
| 3880 | } else { |
| 3881 | // When the screen is off and the key is not injected, determine whether |
| 3882 | // to wake the device but don't pass the key to the application. |
| 3883 | result = 0; |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 3884 | if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) { |
| 3885 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3886 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3887 | } |
| 3888 | |
Justin Koh | d378ad7 | 2013-04-01 12:18:26 -0700 | [diff] [blame] | 3889 | // If the key would be handled globally, just return the result, don't worry about special |
| 3890 | // key processing. |
| 3891 | if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) { |
| 3892 | return result; |
| 3893 | } |
| 3894 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3895 | // Handle special keys. |
| 3896 | switch (keyCode) { |
| 3897 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 3898 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 3899 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3900 | if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { |
| 3901 | if (down) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 3902 | if (interactive && !mVolumeDownKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3903 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3904 | mVolumeDownKeyTriggered = true; |
| 3905 | mVolumeDownKeyTime = event.getDownTime(); |
| 3906 | mVolumeDownKeyConsumedByScreenshotChord = false; |
| 3907 | cancelPendingPowerKeyAction(); |
| 3908 | interceptScreenshotChord(); |
| 3909 | } |
| 3910 | } else { |
| 3911 | mVolumeDownKeyTriggered = false; |
| 3912 | cancelPendingScreenshotChordAction(); |
| 3913 | } |
| 3914 | } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { |
| 3915 | if (down) { |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 3916 | if (interactive && !mVolumeUpKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 3917 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 3918 | mVolumeUpKeyTriggered = true; |
| 3919 | cancelPendingPowerKeyAction(); |
| 3920 | cancelPendingScreenshotChordAction(); |
| 3921 | } |
| 3922 | } else { |
| 3923 | mVolumeUpKeyTriggered = false; |
| 3924 | cancelPendingScreenshotChordAction(); |
| 3925 | } |
| 3926 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3927 | if (down) { |
| 3928 | ITelephony telephonyService = getTelephonyService(); |
| 3929 | if (telephonyService != null) { |
| 3930 | try { |
| 3931 | if (telephonyService.isRinging()) { |
| 3932 | // If an incoming call is ringing, either VOLUME key means |
| 3933 | // "silence ringer". We handle these keys here, rather than |
| 3934 | // in the InCallScreen, to make sure we'll respond to them |
| 3935 | // even if the InCallScreen hasn't come to the foreground yet. |
| 3936 | // Look for the DOWN event here, to agree with the "fallback" |
| 3937 | // behavior in the InCallScreen. |
| 3938 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 3939 | + " VOLUME key-down while ringing: Silence ringer!"); |
| 3940 | |
| 3941 | // Silence the ringer. (It's safe to call this |
| 3942 | // even if the ringer has already been silenced.) |
| 3943 | telephonyService.silenceRinger(); |
| 3944 | |
| 3945 | // And *don't* pass this key thru to the current activity |
| 3946 | // (which is probably the InCallScreen.) |
| 3947 | result &= ~ACTION_PASS_TO_USER; |
| 3948 | break; |
| 3949 | } |
| 3950 | if (telephonyService.isOffhook() |
| 3951 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 3952 | // If we are in call but we decided not to pass the key to |
| 3953 | // the application, handle the volume change here. |
| 3954 | handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode); |
| 3955 | break; |
| 3956 | } |
| 3957 | } catch (RemoteException ex) { |
| 3958 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 3959 | } |
| 3960 | } |
| 3961 | |
| 3962 | if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) { |
| 3963 | // If music is playing but we decided not to pass the key to the |
| 3964 | // application, handle the volume change here. |
| 3965 | handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode); |
| 3966 | break; |
| 3967 | } |
| 3968 | } |
| 3969 | break; |
| 3970 | } |
| 3971 | |
| 3972 | case KeyEvent.KEYCODE_ENDCALL: { |
| 3973 | result &= ~ACTION_PASS_TO_USER; |
| 3974 | if (down) { |
| 3975 | ITelephony telephonyService = getTelephonyService(); |
| 3976 | boolean hungUp = false; |
| 3977 | if (telephonyService != null) { |
| 3978 | try { |
| 3979 | hungUp = telephonyService.endCall(); |
| 3980 | } catch (RemoteException ex) { |
| 3981 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 3982 | } |
| 3983 | } |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 3984 | interceptPowerKeyDown(!interactive || hungUp); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3985 | } else { |
| 3986 | if (interceptPowerKeyUp(canceled)) { |
| 3987 | if ((mEndcallBehavior |
| 3988 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 3989 | if (goHome()) { |
| 3990 | break; |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 3991 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3992 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3993 | if ((mEndcallBehavior |
| 3994 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 3995 | mPowerManager.goToSleep(event.getEventTime()); |
| 3996 | isWakeKey = false; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3997 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3998 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 3999 | } |
| 4000 | break; |
| 4001 | } |
| 4002 | |
| 4003 | case KeyEvent.KEYCODE_POWER: { |
| 4004 | result &= ~ACTION_PASS_TO_USER; |
| 4005 | if (down) { |
Jeff Brown | 26c6a50 | 2014-04-11 02:15:54 -0700 | [diff] [blame] | 4006 | boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive, |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 4007 | event.getDownTime(), isImmersiveMode(mLastSystemUiFlags)); |
| 4008 | if (panic) { |
| 4009 | mHandler.post(mRequestTransientNav); |
| 4010 | } |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4011 | if (interactive && !mPowerKeyTriggered |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4012 | && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 4013 | mPowerKeyTriggered = true; |
| 4014 | mPowerKeyTime = event.getDownTime(); |
| 4015 | interceptScreenshotChord(); |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4016 | } |
Winson Chung | 9112ec3 | 2011-06-27 13:15:32 -0700 | [diff] [blame] | 4017 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4018 | ITelephony telephonyService = getTelephonyService(); |
| 4019 | boolean hungUp = false; |
| 4020 | if (telephonyService != null) { |
| 4021 | try { |
| 4022 | if (telephonyService.isRinging()) { |
| 4023 | // Pressing Power while there's a ringing incoming |
| 4024 | // call should silence the ringer. |
| 4025 | telephonyService.silenceRinger(); |
| 4026 | } else if ((mIncallPowerBehavior |
| 4027 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
Jeff Brown | 26c6a50 | 2014-04-11 02:15:54 -0700 | [diff] [blame] | 4028 | && telephonyService.isOffhook() && interactive) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4029 | // Otherwise, if "Power button ends call" is enabled, |
| 4030 | // the Power button will hang up any current active call. |
| 4031 | hungUp = telephonyService.endCall(); |
| 4032 | } |
| 4033 | } catch (RemoteException ex) { |
| 4034 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 4035 | } |
| 4036 | } |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4037 | interceptPowerKeyDown(!interactive || hungUp |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4038 | || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4039 | } else { |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4040 | mPowerKeyTriggered = false; |
| 4041 | cancelPendingScreenshotChordAction(); |
| 4042 | if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) { |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4043 | mPowerManager.goToSleep(event.getEventTime()); |
| 4044 | isWakeKey = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4045 | } |
Jeff Brown | d5bb82d | 2011-10-12 13:57:59 -0700 | [diff] [blame] | 4046 | mPendingPowerKeyUpCanceled = false; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4047 | } |
| 4048 | break; |
| 4049 | } |
| 4050 | |
Jeff Brown | 6212a49 | 2014-03-07 13:58:47 -0800 | [diff] [blame] | 4051 | case KeyEvent.KEYCODE_SLEEP: { |
| 4052 | result &= ~ACTION_PASS_TO_USER; |
| 4053 | mPowerManager.goToSleep(event.getEventTime()); |
| 4054 | isWakeKey = false; |
| 4055 | break; |
| 4056 | } |
| 4057 | |
| 4058 | case KeyEvent.KEYCODE_WAKEUP: { |
| 4059 | result &= ~ACTION_PASS_TO_USER; |
| 4060 | break; |
| 4061 | } |
| 4062 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4063 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4064 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4065 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 4066 | if (down) { |
| 4067 | ITelephony telephonyService = getTelephonyService(); |
| 4068 | if (telephonyService != null) { |
| 4069 | try { |
| 4070 | if (!telephonyService.isIdle()) { |
| 4071 | // Suppress PLAY/PAUSE toggle when phone is ringing or in-call |
| 4072 | // to avoid music playback. |
| 4073 | break; |
| 4074 | } |
| 4075 | } catch (RemoteException ex) { |
| 4076 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 4077 | } |
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_HEADSETHOOK: |
| 4081 | case KeyEvent.KEYCODE_MUTE: |
| 4082 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4083 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4084 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4085 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4086 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4087 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
| 4088 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4089 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 4090 | // Only do this if we would otherwise not pass it to the user. In that |
| 4091 | // case, the PhoneWindow class will do the same thing, except it will |
| 4092 | // 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] | 4093 | // Note that we need to make a copy of the key event here because the |
| 4094 | // original key event will be recycled when we return. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4095 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4096 | Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK, |
| 4097 | new KeyEvent(event)); |
| 4098 | msg.setAsynchronous(true); |
| 4099 | msg.sendToTarget(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4100 | } |
| 4101 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4102 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4103 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4104 | case KeyEvent.KEYCODE_CALL: { |
| 4105 | if (down) { |
| 4106 | ITelephony telephonyService = getTelephonyService(); |
| 4107 | if (telephonyService != null) { |
| 4108 | try { |
| 4109 | if (telephonyService.isRinging()) { |
| 4110 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 4111 | + " CALL key-down while ringing: Answer the call!"); |
| 4112 | telephonyService.answerRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4113 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4114 | // And *don't* pass this key thru to the current activity |
| 4115 | // (which is presumably the InCallScreen.) |
| 4116 | result &= ~ACTION_PASS_TO_USER; |
| 4117 | } |
| 4118 | } catch (RemoteException ex) { |
| 4119 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4120 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4121 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 4122 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 4123 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4124 | } |
| 4125 | } |
Jeff Brown | 2687550 | 2014-01-30 21:47:47 -0800 | [diff] [blame] | 4126 | |
| 4127 | if (isWakeKey) { |
| 4128 | mPowerManager.wakeUp(event.getEventTime()); |
| 4129 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4130 | return result; |
| 4131 | } |
| 4132 | |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4133 | /** |
| 4134 | * When the screen is off we ignore some keys that might otherwise typically |
| 4135 | * be considered wake keys. We filter them out here. |
| 4136 | * |
| 4137 | * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it |
| 4138 | * is always considered a wake key. |
| 4139 | */ |
| 4140 | private boolean isWakeKeyWhenScreenOff(int keyCode) { |
| 4141 | switch (keyCode) { |
| 4142 | // ignore volume keys unless docked |
| 4143 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 4144 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
| 4145 | case KeyEvent.KEYCODE_VOLUME_MUTE: |
| 4146 | return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED; |
| 4147 | |
| 4148 | // ignore media and camera keys |
| 4149 | case KeyEvent.KEYCODE_MUTE: |
| 4150 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 4151 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 4152 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 4153 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 4154 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 4155 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 4156 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 4157 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 4158 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 4159 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: |
Jaekyun Seok | bfdad8e | 2013-07-08 13:53:21 +0900 | [diff] [blame] | 4160 | case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: |
Jeff Brown | 1c2e494 | 2012-11-06 16:32:01 -0800 | [diff] [blame] | 4161 | case KeyEvent.KEYCODE_CAMERA: |
| 4162 | return false; |
| 4163 | } |
| 4164 | return true; |
| 4165 | } |
| 4166 | |
| 4167 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4168 | /** {@inheritDoc} */ |
| 4169 | @Override |
Jeff Brown | 037c33e | 2014-04-09 00:31:55 -0700 | [diff] [blame] | 4170 | public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) { |
| 4171 | // We already know this is a wake motion so just wake up. |
| 4172 | // Note that we would observe policyFlags containing |
| 4173 | // FLAG_WAKE and FLAG_INTERACTIVE here. |
| 4174 | mPowerManager.wakeUp(whenNanos / 1000000); |
| 4175 | return 0; |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 4176 | } |
| 4177 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4178 | void dispatchMediaKeyWithWakeLock(KeyEvent event) { |
| 4179 | if (DEBUG_INPUT) { |
| 4180 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4181 | } |
| 4182 | |
Jeff Brown | 4001365 | 2012-05-16 21:22:36 -0700 | [diff] [blame] | 4183 | if (mHavePendingMediaKeyRepeatWithWakeLock) { |
| 4184 | if (DEBUG_INPUT) { |
| 4185 | Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat"); |
| 4186 | } |
| 4187 | |
| 4188 | mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK); |
| 4189 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 4190 | mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock |
| 4191 | } |
| 4192 | |
| 4193 | dispatchMediaKeyWithWakeLockToAudioService(event); |
| 4194 | |
| 4195 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 4196 | && event.getRepeatCount() == 0) { |
| 4197 | mHavePendingMediaKeyRepeatWithWakeLock = true; |
| 4198 | |
| 4199 | Message msg = mHandler.obtainMessage( |
| 4200 | MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event); |
| 4201 | msg.setAsynchronous(true); |
| 4202 | mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout()); |
| 4203 | } else { |
| 4204 | mBroadcastWakeLock.release(); |
| 4205 | } |
| 4206 | } |
| 4207 | |
| 4208 | void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) { |
| 4209 | mHavePendingMediaKeyRepeatWithWakeLock = false; |
| 4210 | |
| 4211 | KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event, |
| 4212 | SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS); |
| 4213 | if (DEBUG_INPUT) { |
| 4214 | Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent); |
| 4215 | } |
| 4216 | |
| 4217 | dispatchMediaKeyWithWakeLockToAudioService(repeatEvent); |
| 4218 | mBroadcastWakeLock.release(); |
| 4219 | } |
| 4220 | |
| 4221 | void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) { |
| 4222 | if (ActivityManagerNative.isSystemReady()) { |
| 4223 | IAudioService audioService = getAudioService(); |
| 4224 | if (audioService != null) { |
| 4225 | try { |
| 4226 | audioService.dispatchMediaKeyEventUnderWakelock(event); |
| 4227 | } catch (RemoteException e) { |
| 4228 | Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e); |
Jean-Michel Trivi | c680222 | 2012-04-30 11:15:03 -0700 | [diff] [blame] | 4229 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4230 | } |
| 4231 | } |
| 4232 | } |
| 4233 | |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4234 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 4235 | @Override |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4236 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 4237 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 4238 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 4239 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4240 | } else { |
| 4241 | try { |
| 4242 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 4243 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 4244 | mUiMode = uiModeService.getCurrentModeType(); |
| 4245 | } catch (RemoteException e) { |
| 4246 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 4247 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4248 | updateRotation(true); |
Craig Mautner | eee29c4 | 2013-01-17 14:44:34 -0800 | [diff] [blame] | 4249 | synchronized (mLock) { |
| 4250 | updateOrientationListenerLp(); |
| 4251 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 4252 | } |
| 4253 | }; |
| 4254 | |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4255 | BroadcastReceiver mDreamReceiver = new BroadcastReceiver() { |
| 4256 | @Override |
| 4257 | public void onReceive(Context context, Intent intent) { |
| 4258 | if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4259 | if (mKeyguardDelegate != null) { |
| 4260 | mKeyguardDelegate.onDreamingStarted(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4261 | } |
| 4262 | } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4263 | if (mKeyguardDelegate != null) { |
| 4264 | mKeyguardDelegate.onDreamingStopped(); |
Jeff Brown | 6aaf295 | 2012-10-05 16:01:08 -0700 | [diff] [blame] | 4265 | } |
| 4266 | } |
| 4267 | } |
| 4268 | }; |
| 4269 | |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4270 | BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() { |
| 4271 | @Override |
| 4272 | public void onReceive(Context context, Intent intent) { |
| 4273 | if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { |
| 4274 | // tickle the settings observer: this first ensures that we're |
| 4275 | // observing the relevant settings for the newly-active user, |
| 4276 | // and then updates our own bookkeeping based on the now- |
| 4277 | // current user. |
| 4278 | mSettingsObserver.onChange(false); |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 4279 | |
| 4280 | // force a re-application of focused window sysui visibility. |
| 4281 | // the window may never have been shown for this user |
| 4282 | // e.g. the keyguard when going through the new-user setup flow |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4283 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | ce479d8 | 2012-11-29 09:52:21 -0500 | [diff] [blame] | 4284 | mLastSystemUiFlags = 0; |
| 4285 | updateSystemUiVisibilityLw(); |
| 4286 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4287 | } |
| 4288 | } |
| 4289 | }; |
| 4290 | |
John Spurlock | d9b70bd | 2014-02-06 17:02:44 -0500 | [diff] [blame] | 4291 | private final Runnable mRequestTransientNav = new Runnable() { |
| 4292 | @Override |
| 4293 | public void run() { |
| 4294 | requestTransientBars(mNavigationBar); |
| 4295 | } |
| 4296 | }; |
| 4297 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 4298 | private void requestTransientBars(WindowState swipeTarget) { |
John Spurlock | 04db176 | 2013-05-13 12:46:41 -0400 | [diff] [blame] | 4299 | synchronized (mWindowManagerFuncs.getWindowManagerLock()) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4300 | boolean sb = mStatusBarController.checkShowTransientBarLw(); |
| 4301 | boolean nb = mNavigationBarController.checkShowTransientBarLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4302 | if (sb || nb) { |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 4303 | WindowState barTarget = sb ? mStatusBar : mNavigationBar; |
| 4304 | if (sb ^ nb && barTarget != swipeTarget) { |
| 4305 | if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target"); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4306 | return; |
| 4307 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 4308 | if (sb) mStatusBarController.showTransient(); |
| 4309 | if (nb) mNavigationBarController.showTransient(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 4310 | mImmersiveModeConfirmation.confirmCurrentPrompt(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4311 | updateSystemUiVisibilityLw(); |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 4312 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 4313 | } |
| 4314 | } |
| 4315 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4316 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4317 | public void screenTurnedOff(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 4318 | EventLog.writeEvent(70000, 0); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4319 | synchronized (mLock) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4320 | mScreenOnEarly = false; |
| 4321 | mScreenOnFully = false; |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4322 | } |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4323 | if (mKeyguardDelegate != null) { |
| 4324 | mKeyguardDelegate.onScreenTurnedOff(why); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4325 | } |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4326 | synchronized (mLock) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4327 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4328 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4329 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4330 | } |
| 4331 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4332 | @Override |
Dianne Hackborn | 38e29a6 | 2011-09-18 14:43:08 -0700 | [diff] [blame] | 4333 | public void screenTurningOn(final ScreenOnListener screenOnListener) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 4334 | EventLog.writeEvent(70000, 1); |
Dianne Hackborn | 4001109 | 2011-09-22 13:37:48 -0700 | [diff] [blame] | 4335 | if (false) { |
| 4336 | RuntimeException here = new RuntimeException("here"); |
| 4337 | here.fillInStackTrace(); |
| 4338 | Slog.i(TAG, "Screen turning on...", here); |
| 4339 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4340 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4341 | synchronized (mLock) { |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4342 | mScreenOnEarly = true; |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4343 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4344 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4345 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4346 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4347 | waitForKeyguard(screenOnListener); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4348 | } |
| 4349 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4350 | private void waitForKeyguard(final ScreenOnListener screenOnListener) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4351 | if (mKeyguardDelegate != null) { |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 4352 | mKeyguardDelegate.onScreenTurnedOn(new KeyguardServiceDelegate.ShowListener() { |
| 4353 | @Override |
| 4354 | public void onShown(IBinder windowToken) { |
| 4355 | waitForKeyguardWindowDrawn(windowToken, screenOnListener); |
| 4356 | } |
| 4357 | }); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4358 | } else { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4359 | Slog.i(TAG, "No keyguard interface!"); |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 4360 | finishScreenTurningOn(screenOnListener); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4361 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4362 | } |
| 4363 | |
| 4364 | private void waitForKeyguardWindowDrawn(IBinder windowToken, |
| 4365 | final ScreenOnListener screenOnListener) { |
Craig Mautner | 6f29590 | 2013-10-11 21:43:06 -0700 | [diff] [blame] | 4366 | if (windowToken != null && !mHideLockScreen) { |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4367 | try { |
| 4368 | if (mWindowManager.waitForWindowDrawn( |
| 4369 | windowToken, new IRemoteCallback.Stub() { |
| 4370 | @Override |
| 4371 | public void sendResult(Bundle data) { |
| 4372 | Slog.i(TAG, "Lock screen displayed!"); |
| 4373 | finishScreenTurningOn(screenOnListener); |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 4374 | setKeyguardDrawn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4375 | } |
| 4376 | })) { |
| 4377 | return; |
| 4378 | } |
Craig Mautner | 4e8a19c | 2013-10-08 17:26:08 -0700 | [diff] [blame] | 4379 | Slog.i(TAG, "No lock screen! waitForWindowDrawn false"); |
| 4380 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4381 | } catch (RemoteException ex) { |
| 4382 | // Can't happen in system process. |
| 4383 | } |
| 4384 | } |
| 4385 | |
Craig Mautner | 4e8a19c | 2013-10-08 17:26:08 -0700 | [diff] [blame] | 4386 | Slog.i(TAG, "No lock screen! windowToken=" + windowToken); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4387 | finishScreenTurningOn(screenOnListener); |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 4388 | setKeyguardDrawn(); |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4389 | } |
| 4390 | |
| 4391 | private void finishScreenTurningOn(ScreenOnListener screenOnListener) { |
| 4392 | synchronized (mLock) { |
| 4393 | mScreenOnFully = true; |
| 4394 | } |
| 4395 | |
Jeff Brown | 4fc4527 | 2012-10-10 18:28:14 -0700 | [diff] [blame] | 4396 | try { |
| 4397 | mWindowManager.setEventDispatching(true); |
| 4398 | } catch (RemoteException unhandled) { |
| 4399 | } |
| 4400 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4401 | if (screenOnListener != null) { |
| 4402 | screenOnListener.onScreenOn(); |
| 4403 | } |
| 4404 | } |
| 4405 | |
| 4406 | @Override |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4407 | public boolean isScreenOnEarly() { |
| 4408 | return mScreenOnEarly; |
| 4409 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4410 | |
| 4411 | @Override |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 4412 | public boolean isScreenOnFully() { |
| 4413 | return mScreenOnFully; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4414 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 4415 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 4416 | /** {@inheritDoc} */ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4417 | public void enableKeyguard(boolean enabled) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4418 | if (mKeyguardDelegate != null) { |
| 4419 | mKeyguardDelegate.setKeyguardEnabled(enabled); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4420 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4421 | } |
| 4422 | |
| 4423 | /** {@inheritDoc} */ |
| 4424 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4425 | if (mKeyguardDelegate != null) { |
| 4426 | mKeyguardDelegate.verifyUnlock(callback); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4427 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4428 | } |
| 4429 | |
Mike Lockwood | f791330 | 2009-11-28 22:27:10 -0500 | [diff] [blame] | 4430 | private boolean keyguardIsShowingTq() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4431 | if (mKeyguardDelegate == null) return false; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 4432 | return mKeyguardDelegate.isShowingAndNotOccluded(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4433 | } |
| 4434 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4435 | |
| 4436 | /** {@inheritDoc} */ |
| 4437 | public boolean isKeyguardLocked() { |
| 4438 | return keyguardOn(); |
| 4439 | } |
| 4440 | |
| 4441 | /** {@inheritDoc} */ |
| 4442 | public boolean isKeyguardSecure() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4443 | if (mKeyguardDelegate == null) return false; |
| 4444 | return mKeyguardDelegate.isSecure(); |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 4445 | } |
| 4446 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4447 | /** {@inheritDoc} */ |
| 4448 | public boolean inKeyguardRestrictedKeyInputMode() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4449 | if (mKeyguardDelegate == null) return false; |
| 4450 | return mKeyguardDelegate.isInputRestricted(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4451 | } |
| 4452 | |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4453 | public void dismissKeyguardLw() { |
Jim Miller | 195b551 | 2013-02-28 03:35:57 -0800 | [diff] [blame] | 4454 | if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) { |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4455 | mHandler.post(new Runnable() { |
| 4456 | public void run() { |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4457 | if (mKeyguardDelegate.isDismissable()) { |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4458 | // Can we just finish the keyguard straight away? |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4459 | mKeyguardDelegate.keyguardDone(false, true); |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4460 | } else { |
| 4461 | // ask the keyguard to prompt the user to authenticate if necessary |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4462 | mKeyguardDelegate.dismiss(); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4463 | } |
Daniel Sandler | 1ce80439 | 2012-11-07 15:07:12 -0500 | [diff] [blame] | 4464 | } |
| 4465 | }); |
Dianne Hackborn | 90c52de | 2011-09-23 12:57:44 -0700 | [diff] [blame] | 4466 | } |
| 4467 | } |
| 4468 | |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 4469 | private void setKeyguardDrawn() { |
| 4470 | synchronized (mLock) { |
| 4471 | mKeyguardDrawn = true; |
| 4472 | } |
| 4473 | try { |
| 4474 | mWindowManager.enableScreenIfNeeded(); |
| 4475 | } catch (RemoteException unhandled) { |
| 4476 | } |
| 4477 | } |
| 4478 | |
| 4479 | @Override |
| 4480 | public boolean isKeyguardDrawnLw() { |
| 4481 | synchronized (mLock) { |
| 4482 | return mKeyguardDrawn; |
| 4483 | } |
| 4484 | } |
| 4485 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4486 | void sendCloseSystemWindows() { |
| 4487 | sendCloseSystemWindows(mContext, null); |
| 4488 | } |
| 4489 | |
| 4490 | void sendCloseSystemWindows(String reason) { |
| 4491 | sendCloseSystemWindows(mContext, reason); |
| 4492 | } |
| 4493 | |
| 4494 | static void sendCloseSystemWindows(Context context, String reason) { |
| 4495 | if (ActivityManagerNative.isSystemReady()) { |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 4496 | try { |
| 4497 | ActivityManagerNative.getDefault().closeSystemDialogs(reason); |
| 4498 | } catch (RemoteException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4499 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4500 | } |
| 4501 | } |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 4502 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4503 | @Override |
| 4504 | public int rotationForOrientationLw(int orientation, int lastRotation) { |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4505 | if (false) { |
| 4506 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 4507 | + orientation + ", last=" + lastRotation |
| 4508 | + "); user=" + mUserRotation + " " |
| 4509 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 4510 | ? "USER_ROTATION_LOCKED" : "") |
| 4511 | ); |
| 4512 | } |
| 4513 | |
Craig Mautner | 46ac6fa | 2013-08-01 10:06:34 -0700 | [diff] [blame] | 4514 | if (mForceDefaultOrientation) { |
| 4515 | return Surface.ROTATION_0; |
| 4516 | } |
| 4517 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 4518 | synchronized (mLock) { |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4519 | int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 |
| 4520 | if (sensorRotation < 0) { |
Jeff Brown | 0f862b4 | 2012-09-27 21:11:01 -0700 | [diff] [blame] | 4521 | sensorRotation = lastRotation; |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4522 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4523 | |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4524 | final int preferredRotation; |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 4525 | if (mLidState == LID_OPEN && mLidOpenRotation >= 0) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4526 | // Ignore sensor when lid switch is open and rotation is forced. |
| 4527 | preferredRotation = mLidOpenRotation; |
| 4528 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4529 | && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4530 | // Ignore sensor when in car dock unless explicitly enabled. |
| 4531 | // This case can override the behavior of NOSENSOR, and can also |
| 4532 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4533 | preferredRotation = mCarDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4534 | ? sensorRotation : mCarDockRotation; |
Jeff Brown | 1a69318 | 2011-11-08 14:44:16 -0800 | [diff] [blame] | 4535 | } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK |
| 4536 | || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK |
| 4537 | || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK) |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4538 | && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4539 | // Ignore sensor when in desk dock unless explicitly enabled. |
| 4540 | // This case can override the behavior of NOSENSOR, and can also |
| 4541 | // enable 180 degree rotation while docked. |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4542 | preferredRotation = mDeskDockEnablesAccelerometer |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4543 | ? sensorRotation : mDeskDockRotation; |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 4544 | } else if (mHdmiPlugged && mDemoHdmiRotationLock) { |
| 4545 | // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled. |
Jeff Brown | eb3e4b9 | 2011-12-06 19:54:24 -0800 | [diff] [blame] | 4546 | // Note that the dock orientation overrides the HDMI orientation. |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 4547 | preferredRotation = mDemoHdmiRotation; |
| 4548 | } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED |
| 4549 | && mUndockedHdmiRotation >= 0) { |
| 4550 | // Ignore sensor when plugged into HDMI and an undocked orientation has |
| 4551 | // been specified in the configuration (only for legacy devices without |
| 4552 | // full multi-display support). |
| 4553 | // Note that the dock orientation overrides the HDMI orientation. |
| 4554 | preferredRotation = mUndockedHdmiRotation; |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4555 | } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { |
| 4556 | // Application just wants to remain locked in the last rotation. |
| 4557 | preferredRotation = lastRotation; |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 4558 | } else if (!mSupportAutoRotation) { |
| 4559 | // If we don't support auto-rotation then bail out here and ignore |
| 4560 | // the sensor and any rotation lock settings. |
| 4561 | preferredRotation = -1; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 4562 | } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4563 | && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4564 | || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 4565 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE |
| 4566 | || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT |
| 4567 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER)) |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4568 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 4569 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 4570 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 4571 | || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
| 4572 | // Otherwise, use sensor only if requested by the application or enabled |
| 4573 | // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR. |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 4574 | if (mAllowAllRotations < 0) { |
| 4575 | // Can't read this during init() because the context doesn't |
| 4576 | // have display metrics at that time so we cannot determine |
| 4577 | // tablet vs. phone then. |
| 4578 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 4579 | com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0; |
| 4580 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4581 | if (sensorRotation != Surface.ROTATION_180 |
Jeff Brown | d3187e3 | 2011-09-21 19:26:44 -0700 | [diff] [blame] | 4582 | || mAllowAllRotations == 1 |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4583 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 4584 | || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) { |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4585 | preferredRotation = sensorRotation; |
| 4586 | } else { |
| 4587 | preferredRotation = lastRotation; |
| 4588 | } |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 4589 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED |
| 4590 | && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 4591 | // Apply rotation lock. Does not apply to NOSENSOR. |
| 4592 | // The idea is that the user rotation expresses a weak preference for the direction |
| 4593 | // of gravity and as NOSENSOR is never affected by gravity, then neither should |
| 4594 | // 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] | 4595 | preferredRotation = mUserRotation; |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4596 | } else { |
| 4597 | // No overriding preference. |
| 4598 | // We will do exactly what the application asked us to do. |
| 4599 | preferredRotation = -1; |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4600 | } |
| 4601 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4602 | switch (orientation) { |
| 4603 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4604 | // Return portrait unless overridden. |
| 4605 | if (isAnyPortrait(preferredRotation)) { |
| 4606 | return preferredRotation; |
| 4607 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4608 | return mPortraitRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4609 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4610 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4611 | // Return landscape unless overridden. |
| 4612 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4613 | return preferredRotation; |
| 4614 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4615 | return mLandscapeRotation; |
| 4616 | |
| 4617 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4618 | // Return reverse portrait unless overridden. |
| 4619 | if (isAnyPortrait(preferredRotation)) { |
| 4620 | return preferredRotation; |
| 4621 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4622 | return mUpsideDownRotation; |
| 4623 | |
| 4624 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
Jeff Brown | dec6cf4 | 2011-11-15 14:08:20 -0800 | [diff] [blame] | 4625 | // Return seascape unless overridden. |
| 4626 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4627 | return preferredRotation; |
| 4628 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4629 | return mSeascapeRotation; |
| 4630 | |
| 4631 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4632 | case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4633 | // Return either landscape rotation. |
| 4634 | if (isLandscapeOrSeascape(preferredRotation)) { |
| 4635 | return preferredRotation; |
| 4636 | } |
| 4637 | if (isLandscapeOrSeascape(lastRotation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 4638 | return lastRotation; |
| 4639 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4640 | return mLandscapeRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4641 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4642 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | b9ec1ac | 2013-04-10 17:34:25 -0700 | [diff] [blame] | 4643 | case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT: |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4644 | // Return either portrait rotation. |
| 4645 | if (isAnyPortrait(preferredRotation)) { |
| 4646 | return preferredRotation; |
| 4647 | } |
| 4648 | if (isAnyPortrait(lastRotation)) { |
| 4649 | return lastRotation; |
| 4650 | } |
| 4651 | return mPortraitRotation; |
| 4652 | |
| 4653 | default: |
Jeff Brown | 4dfce20 | 2011-10-05 12:00:10 -0700 | [diff] [blame] | 4654 | // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR, |
| 4655 | // just return the preferred orientation we already calculated. |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4656 | if (preferredRotation >= 0) { |
| 4657 | return preferredRotation; |
| 4658 | } |
Dianne Hackborn | dacea8c | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 4659 | return Surface.ROTATION_0; |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 4660 | } |
| 4661 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 4662 | } |
| 4663 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4664 | @Override |
| 4665 | public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) { |
| 4666 | switch (orientation) { |
| 4667 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 4668 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 4669 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
| 4670 | return isAnyPortrait(rotation); |
| 4671 | |
| 4672 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 4673 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 4674 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 4675 | return isLandscapeOrSeascape(rotation); |
| 4676 | |
| 4677 | default: |
| 4678 | return true; |
| 4679 | } |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 4680 | } |
| 4681 | |
Jeff Brown | c0347aa | 2011-09-23 17:26:09 -0700 | [diff] [blame] | 4682 | @Override |
| 4683 | public void setRotationLw(int rotation) { |
| 4684 | mOrientationListener.setCurrentRotation(rotation); |
| 4685 | } |
| 4686 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4687 | private boolean isLandscapeOrSeascape(int rotation) { |
| 4688 | return rotation == mLandscapeRotation || rotation == mSeascapeRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4689 | } |
| 4690 | |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4691 | private boolean isAnyPortrait(int rotation) { |
| 4692 | return rotation == mPortraitRotation || rotation == mUpsideDownRotation; |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 4693 | } |
| 4694 | |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 4695 | public int getUserRotationMode() { |
| 4696 | return Settings.System.getIntForUser(mContext.getContentResolver(), |
Brett Chabot | 7e55c40 | 2013-05-16 19:38:08 -0700 | [diff] [blame] | 4697 | Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ? |
| 4698 | WindowManagerPolicy.USER_ROTATION_FREE : |
| 4699 | WindowManagerPolicy.USER_ROTATION_LOCKED; |
Svetoslav Ganov | 80943d8 | 2013-01-02 10:25:37 -0800 | [diff] [blame] | 4700 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4701 | |
| 4702 | // User rotation: to be used when all else fails in assigning an orientation to the device |
| 4703 | public void setUserRotationMode(int mode, int rot) { |
| 4704 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4705 | |
| 4706 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4707 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4708 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4709 | Settings.System.USER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4710 | rot, |
| 4711 | UserHandle.USER_CURRENT); |
| 4712 | Settings.System.putIntForUser(res, |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 4713 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4714 | 0, |
| 4715 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4716 | } else { |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4717 | Settings.System.putIntForUser(res, |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4718 | Settings.System.ACCELEROMETER_ROTATION, |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 4719 | 1, |
| 4720 | UserHandle.USER_CURRENT); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 4721 | } |
| 4722 | } |
| 4723 | |
Jeff Brown | ac14351 | 2012-04-05 18:57:33 -0700 | [diff] [blame] | 4724 | public void setSafeMode(boolean safeMode) { |
| 4725 | mSafeMode = safeMode; |
| 4726 | performHapticFeedbackLw(null, safeMode |
| 4727 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 4728 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4729 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4730 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 4731 | static long[] getLongIntArray(Resources r, int resid) { |
| 4732 | int[] ar = r.getIntArray(resid); |
| 4733 | if (ar == null) { |
| 4734 | return null; |
| 4735 | } |
| 4736 | long[] out = new long[ar.length]; |
| 4737 | for (int i=0; i<ar.length; i++) { |
| 4738 | out[i] = ar[i]; |
| 4739 | } |
| 4740 | return out; |
| 4741 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4742 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4743 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4744 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4745 | public void systemReady() { |
Mike Lockwood | ed8902d | 2013-11-15 11:01:47 -0800 | [diff] [blame] | 4746 | mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null); |
| 4747 | mKeyguardDelegate.onSystemReady(); |
| 4748 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 4749 | synchronized (mLock) { |
| 4750 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 4751 | mSystemReady = true; |
| 4752 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4753 | @Override |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 4754 | public void run() { |
| 4755 | updateSettings(); |
| 4756 | } |
| 4757 | }); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4758 | } |
| 4759 | } |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4760 | |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 4761 | /** {@inheritDoc} */ |
| 4762 | public void systemBooted() { |
Jim Miller | e5f910a | 2013-10-16 18:15:46 -0700 | [diff] [blame] | 4763 | if (mKeyguardDelegate != null) { |
| 4764 | mKeyguardDelegate.onBootCompleted(); |
| 4765 | } |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 4766 | synchronized (mLock) { |
| 4767 | mSystemBooted = true; |
| 4768 | } |
Jorim Jaggi | cff0acb | 2014-03-31 16:35:15 +0200 | [diff] [blame] | 4769 | waitForKeyguard(null); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 4770 | } |
| 4771 | |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4772 | ProgressDialog mBootMsgDialog = null; |
| 4773 | |
| 4774 | /** {@inheritDoc} */ |
| 4775 | public void showBootMessage(final CharSequence msg, final boolean always) { |
| 4776 | mHandler.post(new Runnable() { |
| 4777 | @Override public void run() { |
| 4778 | if (mBootMsgDialog == null) { |
Dianne Hackborn | 295e3c2 | 2011-08-25 13:19:08 -0700 | [diff] [blame] | 4779 | mBootMsgDialog = new ProgressDialog(mContext) { |
| 4780 | // This dialog will consume all events coming in to |
| 4781 | // it, to avoid it trying to do things too early in boot. |
| 4782 | @Override public boolean dispatchKeyEvent(KeyEvent event) { |
| 4783 | return true; |
| 4784 | } |
| 4785 | @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) { |
| 4786 | return true; |
| 4787 | } |
| 4788 | @Override public boolean dispatchTouchEvent(MotionEvent ev) { |
| 4789 | return true; |
| 4790 | } |
| 4791 | @Override public boolean dispatchTrackballEvent(MotionEvent ev) { |
| 4792 | return true; |
| 4793 | } |
| 4794 | @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) { |
| 4795 | return true; |
| 4796 | } |
| 4797 | @Override public boolean dispatchPopulateAccessibilityEvent( |
| 4798 | AccessibilityEvent event) { |
| 4799 | return true; |
| 4800 | } |
| 4801 | }; |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4802 | mBootMsgDialog.setTitle(R.string.android_upgrading_title); |
| 4803 | mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); |
| 4804 | mBootMsgDialog.setIndeterminate(true); |
| 4805 | mBootMsgDialog.getWindow().setType( |
Dianne Hackborn | 29aae6f | 2011-08-18 18:30:09 -0700 | [diff] [blame] | 4806 | WindowManager.LayoutParams.TYPE_BOOT_PROGRESS); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4807 | mBootMsgDialog.getWindow().addFlags( |
| 4808 | WindowManager.LayoutParams.FLAG_DIM_BEHIND |
| 4809 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); |
| 4810 | mBootMsgDialog.getWindow().setDimAmount(1); |
Dianne Hackborn | d9efb95 | 2011-12-07 14:56:51 -0800 | [diff] [blame] | 4811 | WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes(); |
| 4812 | lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR; |
| 4813 | mBootMsgDialog.getWindow().setAttributes(lp); |
Dianne Hackborn | 661cd52 | 2011-08-22 00:26:20 -0700 | [diff] [blame] | 4814 | mBootMsgDialog.setCancelable(false); |
| 4815 | mBootMsgDialog.show(); |
| 4816 | } |
| 4817 | mBootMsgDialog.setMessage(msg); |
| 4818 | } |
| 4819 | }); |
| 4820 | } |
| 4821 | |
| 4822 | /** {@inheritDoc} */ |
| 4823 | public void hideBootMessages() { |
| 4824 | mHandler.post(new Runnable() { |
| 4825 | @Override public void run() { |
| 4826 | if (mBootMsgDialog != null) { |
| 4827 | mBootMsgDialog.dismiss(); |
| 4828 | mBootMsgDialog = null; |
| 4829 | } |
| 4830 | } |
| 4831 | }); |
| 4832 | } |
| 4833 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4834 | /** {@inheritDoc} */ |
| 4835 | public void userActivity() { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 4836 | // *************************************** |
| 4837 | // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE |
| 4838 | // *************************************** |
| 4839 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 4840 | // WITH ITS LOCKS HELD. |
| 4841 | // |
| 4842 | // This code must be VERY careful about the locks |
| 4843 | // it acquires. |
| 4844 | // In fact, the current code acquires way too many, |
| 4845 | // and probably has lurking deadlocks. |
| 4846 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4847 | synchronized (mScreenLockTimeout) { |
| 4848 | if (mLockScreenTimerActive) { |
| 4849 | // reset the timer |
| 4850 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 4851 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 4852 | } |
| 4853 | } |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 4854 | } |
| 4855 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4856 | class ScreenLockTimeout implements Runnable { |
| 4857 | Bundle options; |
| 4858 | |
| 4859 | @Override |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4860 | public void run() { |
| 4861 | synchronized (this) { |
| 4862 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4863 | if (mKeyguardDelegate != null) { |
| 4864 | mKeyguardDelegate.doKeyguardTimeout(options); |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4865 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4866 | mLockScreenTimerActive = false; |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4867 | options = null; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4868 | } |
| 4869 | } |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4870 | |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4871 | public void setLockOptions(Bundle options) { |
| 4872 | this.options = options; |
| 4873 | } |
| 4874 | } |
| 4875 | |
| 4876 | ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout(); |
| 4877 | |
| 4878 | public void lockNow(Bundle options) { |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 4879 | mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null); |
| 4880 | mHandler.removeCallbacks(mScreenLockTimeout); |
Adam Cohen | f752202 | 2012-10-03 20:03:18 -0700 | [diff] [blame] | 4881 | if (options != null) { |
| 4882 | // In case multiple calls are made to lockNow, we don't wipe out the options |
| 4883 | // until the runnable actually executes. |
| 4884 | mScreenLockTimeout.setLockOptions(options); |
| 4885 | } |
Jim Miller | 93c518e | 2012-01-17 15:55:31 -0800 | [diff] [blame] | 4886 | mHandler.post(mScreenLockTimeout); |
| 4887 | } |
| 4888 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4889 | private void updateLockScreenTimeout() { |
| 4890 | synchronized (mScreenLockTimeout) { |
Mike Lockwood | 3a74bd3 | 2011-08-12 13:55:22 -0700 | [diff] [blame] | 4891 | boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly && |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 4892 | mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 4893 | if (mLockScreenTimerActive != enable) { |
| 4894 | if (enable) { |
| 4895 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
| 4896 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 4897 | } else { |
| 4898 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 4899 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 4900 | } |
| 4901 | mLockScreenTimerActive = enable; |
| 4902 | } |
| 4903 | } |
| 4904 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4905 | |
| 4906 | /** {@inheritDoc} */ |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4907 | @Override |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4908 | public void enableScreenAfterBoot() { |
| 4909 | readLidState(); |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4910 | applyLidSwitchState(); |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4911 | updateRotation(true); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4912 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 4913 | |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4914 | private void applyLidSwitchState() { |
Jeff Brown | c458ce9 | 2012-04-30 14:58:40 -0700 | [diff] [blame] | 4915 | if (mLidState == LID_CLOSED && mLidControlsSleep) { |
| 4916 | mPowerManager.goToSleep(SystemClock.uptimeMillis()); |
| 4917 | } |
Jeff Brown | 01a98dd | 2011-09-20 15:08:29 -0700 | [diff] [blame] | 4918 | } |
| 4919 | |
| 4920 | void updateRotation(boolean alwaysSendConfiguration) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4921 | try { |
| 4922 | //set orientation on WindowManager |
Dianne Hackborn | f87d196 | 2012-04-04 12:48:24 -0700 | [diff] [blame] | 4923 | mWindowManager.updateRotation(alwaysSendConfiguration, false); |
| 4924 | } catch (RemoteException e) { |
| 4925 | // Ignore |
| 4926 | } |
| 4927 | } |
| 4928 | |
| 4929 | void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) { |
| 4930 | try { |
| 4931 | //set orientation on WindowManager |
| 4932 | mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 4933 | } catch (RemoteException e) { |
| 4934 | // Ignore |
| 4935 | } |
| 4936 | } |
| 4937 | |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4938 | /** |
| 4939 | * Return an Intent to launch the currently active dock app as home. Returns |
| 4940 | * null if the standard home should be launched, which is the case if any of the following is |
| 4941 | * true: |
| 4942 | * <ul> |
| 4943 | * <li>The device is not in either car mode or desk mode |
| 4944 | * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false |
| 4945 | * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false |
| 4946 | * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME |
| 4947 | * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME |
| 4948 | * </ul> |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 4949 | * @return A dock intent. |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4950 | */ |
| 4951 | Intent createHomeDockIntent() { |
| 4952 | Intent intent = null; |
| 4953 | |
| 4954 | // What home does is based on the mode, not the dock state. That |
| 4955 | // is, when in car mode you should be taken to car home regardless |
| 4956 | // of whether we are actually in a car dock. |
| 4957 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
| 4958 | if (ENABLE_CAR_DOCK_HOME_CAPTURE) { |
| 4959 | intent = mCarDockIntent; |
| 4960 | } |
| 4961 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
| 4962 | if (ENABLE_DESK_DOCK_HOME_CAPTURE) { |
| 4963 | intent = mDeskDockIntent; |
| 4964 | } |
| 4965 | } |
| 4966 | |
| 4967 | if (intent == null) { |
| 4968 | return null; |
| 4969 | } |
| 4970 | |
| 4971 | ActivityInfo ai = null; |
| 4972 | ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser( |
| 4973 | intent, |
John Spurlock | f56bef1 | 2013-07-09 09:51:46 -0400 | [diff] [blame] | 4974 | PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA, |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 4975 | mCurrentUserId); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4976 | if (info != null) { |
| 4977 | ai = info.activityInfo; |
| 4978 | } |
| 4979 | if (ai != null |
| 4980 | && ai.metaData != null |
| 4981 | && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 4982 | intent = new Intent(intent); |
| 4983 | intent.setClassName(ai.packageName, ai.name); |
| 4984 | return intent; |
| 4985 | } |
| 4986 | |
| 4987 | return null; |
| 4988 | } |
| 4989 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 4990 | void startDockOrHome() { |
John Spurlock | c8b46ca | 2013-04-08 12:59:26 -0400 | [diff] [blame] | 4991 | awakenDreams(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 4992 | |
| 4993 | Intent dock = createHomeDockIntent(); |
| 4994 | if (dock != null) { |
| 4995 | try { |
| 4996 | mContext.startActivityAsUser(dock, UserHandle.CURRENT); |
| 4997 | return; |
| 4998 | } catch (ActivityNotFoundException e) { |
| 4999 | } |
| 5000 | } |
| 5001 | |
Dianne Hackborn | d888399 | 2012-09-07 15:58:52 -0700 | [diff] [blame] | 5002 | mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5003 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5004 | |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5005 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5006 | * goes to the home screen |
| 5007 | * @return whether it did anything |
| 5008 | */ |
| 5009 | boolean goHome() { |
| 5010 | if (false) { |
| 5011 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 5012 | try { |
| 5013 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 5014 | } catch (RemoteException e) { |
| 5015 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 5016 | sendCloseSystemWindows(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5017 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5018 | } else { |
| 5019 | // This code brings home to the front or, if it is already |
| 5020 | // at the front, puts the device to sleep. |
| 5021 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 5022 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 5023 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 5024 | Log.d(TAG, "UTS-TEST-MODE"); |
| 5025 | } else { |
| 5026 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 5027 | sendCloseSystemWindows(); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5028 | Intent dock = createHomeDockIntent(); |
| 5029 | if (dock != null) { |
| 5030 | int result = ActivityManagerNative.getDefault() |
| 5031 | .startActivityAsUser(null, null, dock, |
| 5032 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 5033 | null, null, 0, |
| 5034 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
| 5035 | null, null, null, UserHandle.USER_CURRENT); |
| 5036 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 5037 | return false; |
| 5038 | } |
| 5039 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 5040 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5041 | int result = ActivityManagerNative.getDefault() |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5042 | .startActivityAsUser(null, null, mHomeIntent, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5043 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5044 | null, null, 0, |
| 5045 | ActivityManager.START_FLAG_ONLY_IF_NEEDED, |
Dianne Hackborn | 5e03e2c | 2012-09-06 14:21:19 -0700 | [diff] [blame] | 5046 | null, null, null, UserHandle.USER_CURRENT); |
Dianne Hackborn | a4972e9 | 2012-03-14 10:38:05 -0700 | [diff] [blame] | 5047 | if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5048 | return false; |
| 5049 | } |
| 5050 | } catch (RemoteException ex) { |
| 5051 | // bummer, the activity manager, which is in this process, is dead |
| 5052 | } |
| 5053 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5054 | return true; |
| 5055 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5056 | |
| 5057 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5058 | public void setCurrentOrientationLw(int newOrientation) { |
| 5059 | synchronized (mLock) { |
| 5060 | if (newOrientation != mCurrentAppOrientation) { |
| 5061 | mCurrentAppOrientation = newOrientation; |
| 5062 | updateOrientationListenerLp(); |
| 5063 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5064 | } |
| 5065 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5066 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 5067 | private void performAuditoryFeedbackForAccessibilityIfNeed() { |
| 5068 | if (!isGlobalAccessibilityGestureEnabled()) { |
| 5069 | return; |
| 5070 | } |
| 5071 | AudioManager audioManager = (AudioManager) mContext.getSystemService( |
| 5072 | Context.AUDIO_SERVICE); |
| 5073 | if (audioManager.isSilentMode()) { |
| 5074 | return; |
| 5075 | } |
| 5076 | Ringtone ringTone = RingtoneManager.getRingtone(mContext, |
| 5077 | Settings.System.DEFAULT_NOTIFICATION_URI); |
| 5078 | ringTone.setStreamType(AudioManager.STREAM_MUSIC); |
| 5079 | ringTone.play(); |
| 5080 | } |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5081 | |
Svetoslav Ganov | 7befb7d | 2012-09-27 16:49:23 -0700 | [diff] [blame] | 5082 | private boolean isGlobalAccessibilityGestureEnabled() { |
| 5083 | return Settings.Global.getInt(mContext.getContentResolver(), |
| 5084 | Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1; |
| 5085 | } |
| 5086 | |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5087 | @Override |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 5088 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Svetoslav Ganov | 9617921 | 2012-10-10 14:17:45 -0700 | [diff] [blame] | 5089 | if (!mVibrator.hasVibrator()) { |
| 5090 | return false; |
| 5091 | } |
Christopher Tate | 5e08af0 | 2012-09-21 17:17:22 -0700 | [diff] [blame] | 5092 | final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(), |
| 5093 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0; |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5094 | if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotOccluded())) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5095 | return false; |
| 5096 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5097 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5098 | switch (effectId) { |
| 5099 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5100 | pattern = mLongPressVibePattern; |
| 5101 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5102 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5103 | pattern = mVirtualKeyVibePattern; |
| 5104 | break; |
| 5105 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 5106 | pattern = mKeyboardTapVibePattern; |
| 5107 | break; |
Fabrice Di Meglio | eeff63a | 2013-08-05 12:07:24 -0700 | [diff] [blame] | 5108 | case HapticFeedbackConstants.CLOCK_TICK: |
| 5109 | pattern = mClockTickVibePattern; |
| 5110 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5111 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5112 | pattern = mSafeModeDisabledVibePattern; |
| 5113 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 5114 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5115 | pattern = mSafeModeEnabledVibePattern; |
| 5116 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5117 | default: |
| 5118 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5119 | } |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5120 | int owningUid; |
| 5121 | String owningPackage; |
| 5122 | if (win != null) { |
| 5123 | owningUid = win.getOwningUid(); |
| 5124 | owningPackage = win.getOwningPackage(); |
| 5125 | } else { |
| 5126 | owningUid = android.os.Process.myUid(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 5127 | owningPackage = mContext.getOpPackageName(); |
Dianne Hackborn | f265ea9 | 2013-01-31 15:00:51 -0800 | [diff] [blame] | 5128 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5129 | if (pattern.length == 1) { |
| 5130 | // One-shot vibration |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 5131 | mVibrator.vibrate(owningUid, owningPackage, pattern[0], AudioManager.STREAM_SYSTEM); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5132 | } else { |
| 5133 | // Pattern vibration |
John Spurlock | 1af30c7 | 2014-03-10 08:33:35 -0400 | [diff] [blame] | 5134 | mVibrator.vibrate(owningUid, owningPackage, pattern, -1, AudioManager.STREAM_SYSTEM); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 5135 | } |
| 5136 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5137 | } |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5138 | |
| 5139 | @Override |
| 5140 | public void keepScreenOnStartedLw() { |
Daniel Sandler | 0601eb7 | 2011-04-13 01:01:32 -0400 | [diff] [blame] | 5141 | } |
| 5142 | |
Jeff Brown | c38c9be | 2012-10-04 13:16:19 -0700 | [diff] [blame] | 5143 | @Override |
| 5144 | public void keepScreenOnStoppedLw() { |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5145 | if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) { |
Jim Miller | 2519057 | 2013-02-28 17:36:24 -0800 | [diff] [blame] | 5146 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5147 | } |
| 5148 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 5149 | |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5150 | private int updateSystemUiVisibilityLw() { |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5151 | // If there is no window focused, there will be nobody to handle the events |
| 5152 | // 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] | 5153 | WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState; |
| 5154 | if (win == null) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5155 | return 0; |
| 5156 | } |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5157 | if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) { |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5158 | // We are updating at a point where the keyguard has gotten |
| 5159 | // focus, but we were last in a state where the top window is |
| 5160 | // hiding it. This is probably because the keyguard as been |
| 5161 | // shown while the top window was displayed, so we want to ignore |
| 5162 | // it here because this is just a very transient change and it |
| 5163 | // will quickly lose focus once it correctly gets hidden. |
| 5164 | return 0; |
| 5165 | } |
John Spurlock | 32beb2c | 2013-03-11 10:16:47 -0400 | [diff] [blame] | 5166 | |
John Spurlock | 1db8b68 | 2014-02-18 11:18:59 -0500 | [diff] [blame] | 5167 | int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null) |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5168 | & ~mResettingSystemUiFlags |
| 5169 | & ~mForceClearedSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5170 | if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) { |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5171 | tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS); |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5172 | } |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5173 | final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5174 | final int diff = visibility ^ mLastSystemUiFlags; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5175 | final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState); |
Dianne Hackborn | e0f085d | 2011-11-30 18:41:15 -0800 | [diff] [blame] | 5176 | if (diff == 0 && mLastFocusNeedsMenu == needsMenu |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5177 | && mFocusedApp == win.getAppToken()) { |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5178 | return 0; |
| 5179 | } |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5180 | mLastSystemUiFlags = visibility; |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 5181 | mLastFocusNeedsMenu = needsMenu; |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5182 | mFocusedApp = win.getAppToken(); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5183 | mHandler.post(new Runnable() { |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5184 | @Override |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5185 | public void run() { |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 5186 | try { |
| 5187 | IStatusBarService statusbar = getStatusBarService(); |
| 5188 | if (statusbar != null) { |
| 5189 | statusbar.setSystemUiVisibility(visibility, 0xffffffff); |
| 5190 | statusbar.topAppWindowChanged(needsMenu); |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5191 | } |
Dianne Hackborn | 42e620c | 2012-06-24 13:20:51 -0700 | [diff] [blame] | 5192 | } catch (RemoteException e) { |
| 5193 | // re-acquire status bar service next time it is needed. |
| 5194 | mStatusBarService = null; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5195 | } |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5196 | } |
| 5197 | }); |
| 5198 | return diff; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 5199 | } |
| 5200 | |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5201 | private int updateSystemBarsLw(WindowState win, int oldVis, int vis) { |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5202 | // apply translucent bar vis flags |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5203 | WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen |
| 5204 | ? mStatusBar |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5205 | : mTopFullscreenOpaqueWindowState; |
| 5206 | vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 5207 | vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis); |
| 5208 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5209 | // prevent status bar interaction from clearing certain flags |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5210 | boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5211 | if (statusBarHasFocus) { |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5212 | int flags = View.SYSTEM_UI_FLAG_FULLSCREEN |
| 5213 | | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
John Spurlock | cfc359a | 2013-09-05 10:42:03 -0400 | [diff] [blame] | 5214 | | View.SYSTEM_UI_FLAG_IMMERSIVE |
Jorim Jaggi | 5cf1787 | 2014-03-26 18:31:48 +0100 | [diff] [blame] | 5215 | | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; |
| 5216 | if (!isStatusBarKeyguard() || mHideLockScreen) { |
| 5217 | flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT; |
| 5218 | } |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5219 | vis = (vis & ~flags) | (oldVis & flags); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5220 | } |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5221 | |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 5222 | if (!areTranslucentBarsAllowed()) { |
| 5223 | vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5224 | } |
| 5225 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5226 | // update status bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5227 | boolean immersiveSticky = |
| 5228 | (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0; |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5229 | boolean hideStatusBarWM = |
John Spurlock | bd95740 | 2013-10-03 11:38:39 -0400 | [diff] [blame] | 5230 | mTopFullscreenOpaqueWindowState != null && |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5231 | (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5232 | & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
| 5233 | boolean hideStatusBarSysui = |
| 5234 | (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0; |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5235 | boolean hideNavBarSysui = |
| 5236 | (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5237 | |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5238 | boolean transientStatusBarAllowed = |
| 5239 | mStatusBar != null && ( |
| 5240 | hideStatusBarWM |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5241 | || (hideStatusBarSysui && immersiveSticky) |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5242 | || statusBarHasFocus); |
| 5243 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5244 | boolean transientNavBarAllowed = |
| 5245 | mNavigationBar != null && |
| 5246 | hideNavBarSysui && immersiveSticky; |
| 5247 | |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 5248 | boolean denyTransientStatus = mStatusBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5249 | && !transientStatusBarAllowed && hideStatusBarSysui; |
John Spurlock | f25706f | 2013-11-07 18:02:43 -0500 | [diff] [blame] | 5250 | boolean denyTransientNav = mNavigationBarController.isTransientShowRequested() |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5251 | && !transientNavBarAllowed; |
| 5252 | if (denyTransientStatus || denyTransientNav) { |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5253 | // clear the clearable flags instead |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5254 | clearClearableFlagsLw(); |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5255 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5256 | |
| 5257 | vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis); |
| 5258 | |
| 5259 | // update navigation bar |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5260 | boolean oldImmersiveMode = isImmersiveMode(oldVis); |
| 5261 | boolean newImmersiveMode = isImmersiveMode(vis); |
| 5262 | if (win != null && oldImmersiveMode != newImmersiveMode) { |
John Spurlock | 79da833 | 2013-09-20 12:04:47 -0400 | [diff] [blame] | 5263 | final String pkg = win.getOwningPackage(); |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5264 | mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 5265 | } |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5266 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5267 | vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis); |
| 5268 | |
John Spurlock | e1f366f | 2013-08-05 12:22:40 -0400 | [diff] [blame] | 5269 | return vis; |
John Spurlock | ad3e6cb | 2013-04-30 08:47:43 -0400 | [diff] [blame] | 5270 | } |
| 5271 | |
John Spurlock | f1a3664 | 2013-10-12 17:50:42 -0400 | [diff] [blame] | 5272 | private void clearClearableFlagsLw() { |
| 5273 | int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS; |
| 5274 | if (newVal != mResettingSystemUiFlags) { |
| 5275 | mResettingSystemUiFlags = newVal; |
| 5276 | mWindowManagerFuncs.reevaluateStatusBarVisibility(); |
| 5277 | } |
| 5278 | } |
| 5279 | |
| 5280 | private boolean isImmersiveMode(int vis) { |
| 5281 | 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] | 5282 | return mNavigationBar != null |
| 5283 | && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0 |
Daniel Sandler | 900ece5 | 2013-10-18 15:53:27 -0400 | [diff] [blame] | 5284 | && (vis & flags) != 0 |
| 5285 | && canHideNavigationBar(); |
John Spurlock | 34e13d9 | 2013-08-10 06:52:28 -0400 | [diff] [blame] | 5286 | } |
| 5287 | |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5288 | /** |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 5289 | * @return whether the navigation or status bar can be made translucent |
| 5290 | * |
| 5291 | * This should return true unless touch exploration is not enabled or |
| 5292 | * R.boolean.config_enableTranslucentDecor is false. |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5293 | */ |
Daniel Sandler | dd73ee4 | 2013-10-11 22:19:59 -0400 | [diff] [blame] | 5294 | private boolean areTranslucentBarsAllowed() { |
Svetoslav | 8e3feb1 | 2014-02-24 13:46:47 -0800 | [diff] [blame] | 5295 | return mTranslucentDecorEnabled |
| 5296 | && !mAccessibilityManager.isTouchExplorationEnabled(); |
Alan Viverette | 5a0f4ec | 2013-10-07 15:10:29 -0700 | [diff] [blame] | 5297 | } |
| 5298 | |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 5299 | // Use this instead of checking config_showNavigationBar so that it can be consistently |
| 5300 | // overridden by qemu.hw.mainkeys in the emulator. |
Craig Mautner | eda6729 | 2013-04-28 13:50:14 -0700 | [diff] [blame] | 5301 | @Override |
Daniel Sandler | 0c4ccff | 2011-10-19 16:39:14 -0400 | [diff] [blame] | 5302 | public boolean hasNavigationBar() { |
| 5303 | return mHasNavigationBar; |
| 5304 | } |
| 5305 | |
satok | 1bc0a49 | 2012-04-25 22:47:12 +0900 | [diff] [blame] | 5306 | @Override |
| 5307 | public void setLastInputMethodWindowLw(WindowState ime, WindowState target) { |
| 5308 | mLastInputMethodWindow = ime; |
| 5309 | mLastInputMethodTargetWindow = target; |
| 5310 | } |
| 5311 | |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5312 | @Override |
Satoshi Kataoka | 658c7b8 | 2013-10-10 17:03:51 +0900 | [diff] [blame] | 5313 | public int getInputMethodWindowVisibleHeightLw() { |
| 5314 | return mDockBottom - mCurBottom; |
| 5315 | } |
| 5316 | |
| 5317 | @Override |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5318 | public void setCurrentUserLw(int newUserId) { |
Craig Mautner | d625ab2 | 2013-09-06 13:40:31 -0700 | [diff] [blame] | 5319 | mCurrentUserId = newUserId; |
Jim Miller | 5ecd811 | 2013-01-09 18:50:26 -0800 | [diff] [blame] | 5320 | if (mKeyguardDelegate != null) { |
| 5321 | mKeyguardDelegate.setCurrentUser(newUserId); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5322 | } |
John Spurlock | 13451a2 | 2012-09-28 14:40:41 -0400 | [diff] [blame] | 5323 | if (mStatusBarService != null) { |
| 5324 | try { |
| 5325 | mStatusBarService.setCurrentUser(newUserId); |
| 5326 | } catch (RemoteException e) { |
| 5327 | // oh well |
| 5328 | } |
| 5329 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5330 | setLastInputMethodWindowLw(null, null); |
Craig Mautner | f1b6741 | 2012-09-19 13:18:29 -0700 | [diff] [blame] | 5331 | } |
| 5332 | |
| 5333 | @Override |
Svetoslav Ganov | 545252f | 2012-12-10 18:29:24 -0800 | [diff] [blame] | 5334 | public boolean canMagnifyWindow(int windowType) { |
| 5335 | switch (windowType) { |
| 5336 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD: |
| 5337 | case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG: |
| 5338 | case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR: |
| 5339 | case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: { |
| 5340 | return false; |
| 5341 | } |
| 5342 | } |
| 5343 | return true; |
| 5344 | } |
| 5345 | |
| 5346 | @Override |
| 5347 | public boolean isTopLevelWindow(int windowType) { |
| 5348 | if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW |
| 5349 | && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) { |
| 5350 | return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG); |
| 5351 | } |
| 5352 | return true; |
| 5353 | } |
| 5354 | |
Jim Miller | 4eeb4f6 | 2012-11-08 00:04:29 -0800 | [diff] [blame] | 5355 | @Override |
Jeff Brown | d7a04de | 2012-06-17 14:17:52 -0700 | [diff] [blame] | 5356 | public void dump(String prefix, PrintWriter pw, String[] args) { |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5357 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
Dianne Hackborn | ba24e4d | 2011-09-01 11:17:06 -0700 | [diff] [blame] | 5358 | pw.print(" mSystemReady="); pw.print(mSystemReady); |
| 5359 | pw.print(" mSystemBooted="); pw.println(mSystemBooted); |
Jeff Brown | 2e7760e | 2012-04-11 15:14:55 -0700 | [diff] [blame] | 5360 | pw.print(prefix); pw.print("mLidState="); pw.print(mLidState); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5361 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
| 5362 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
Dianne Hackborn | e26ab70 | 2011-10-16 13:21:33 -0700 | [diff] [blame] | 5363 | if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0 |
| 5364 | || mForceClearedSystemUiFlags != 0) { |
| 5365 | pw.print(prefix); pw.print("mLastSystemUiFlags=0x"); |
| 5366 | pw.print(Integer.toHexString(mLastSystemUiFlags)); |
| 5367 | pw.print(" mResettingSystemUiFlags=0x"); |
| 5368 | pw.print(Integer.toHexString(mResettingSystemUiFlags)); |
| 5369 | pw.print(" mForceClearedSystemUiFlags=0x"); |
| 5370 | pw.println(Integer.toHexString(mForceClearedSystemUiFlags)); |
Dianne Hackborn | df89e65 | 2011-10-06 22:35:11 -0700 | [diff] [blame] | 5371 | } |
Dianne Hackborn | 4eff8d3 | 2011-11-10 19:38:40 -0800 | [diff] [blame] | 5372 | if (mLastFocusNeedsMenu) { |
| 5373 | pw.print(prefix); pw.print("mLastFocusNeedsMenu="); |
| 5374 | pw.println(mLastFocusNeedsMenu); |
| 5375 | } |
Jeff Brown | bcdfc62 | 2014-03-06 19:13:04 -0800 | [diff] [blame] | 5376 | pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); |
Daniel Sandler | 6396c72 | 2013-04-16 20:19:09 -0400 | [diff] [blame] | 5377 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 5378 | pw.print(" mDockMode="); pw.print(mDockMode); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5379 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 5380 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 5381 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 5382 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 5383 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5384 | pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5385 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 5386 | pw.print(mCarDockEnablesAccelerometer); |
| 5387 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 5388 | pw.println(mDeskDockEnablesAccelerometer); |
| 5389 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 5390 | pw.print(mLidKeyboardAccessibility); |
| 5391 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5392 | pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep); |
| 5393 | pw.print(prefix); pw.print("mLongPressOnPowerBehavior="); |
| 5394 | pw.print(mLongPressOnPowerBehavior); |
| 5395 | pw.print(" mHasSoftInput="); pw.println(mHasSoftInput); |
Dianne Hackborn | bc1aa7b | 2011-09-20 11:20:31 -0700 | [diff] [blame] | 5396 | pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); |
| 5397 | pw.print(" mScreenOnFully="); pw.print(mScreenOnFully); |
Dianne Hackborn | 6e2281d | 2012-06-19 17:48:32 -0700 | [diff] [blame] | 5398 | pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 5399 | pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); |
| 5400 | pw.print(","); pw.print(mOverscanScreenTop); |
| 5401 | pw.print(") "); pw.print(mOverscanScreenWidth); |
| 5402 | pw.print("x"); pw.println(mOverscanScreenHeight); |
| 5403 | if (mOverscanLeft != 0 || mOverscanTop != 0 |
| 5404 | || mOverscanRight != 0 || mOverscanBottom != 0) { |
| 5405 | pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft); |
| 5406 | pw.print(" top="); pw.print(mOverscanTop); |
| 5407 | pw.print(" right="); pw.print(mOverscanRight); |
| 5408 | pw.print(" bottom="); pw.println(mOverscanBottom); |
| 5409 | } |
Dianne Hackborn | 31344084 | 2013-02-19 19:22:59 -0800 | [diff] [blame] | 5410 | pw.print(prefix); pw.print("mRestrictedOverscanScreen=("); |
| 5411 | pw.print(mRestrictedOverscanScreenLeft); |
| 5412 | pw.print(","); pw.print(mRestrictedOverscanScreenTop); |
| 5413 | pw.print(") "); pw.print(mRestrictedOverscanScreenWidth); |
| 5414 | pw.print("x"); pw.println(mRestrictedOverscanScreenHeight); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5415 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 5416 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 5417 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 5418 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 5419 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 5420 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 5421 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 5422 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
Dianne Hackborn | 5b5cc4d | 2012-05-16 13:15:00 -0700 | [diff] [blame] | 5423 | pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft); |
| 5424 | pw.print(","); pw.print(mStableFullscreenTop); |
| 5425 | pw.print(")-("); pw.print(mStableFullscreenRight); |
| 5426 | pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")"); |
Dianne Hackborn | 3a3a6cf | 2012-03-26 10:24:04 -0700 | [diff] [blame] | 5427 | pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft); |
| 5428 | pw.print(","); pw.print(mStableTop); |
| 5429 | pw.print(")-("); pw.print(mStableRight); |
| 5430 | pw.print(","); pw.print(mStableBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 5431 | pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft); |
| 5432 | pw.print(","); pw.print(mSystemTop); |
| 5433 | pw.print(")-("); pw.print(mSystemRight); |
| 5434 | pw.print(","); pw.print(mSystemBottom); pw.println(")"); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5435 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 5436 | pw.print(","); pw.print(mCurTop); |
| 5437 | pw.print(")-("); pw.print(mCurRight); |
| 5438 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 5439 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 5440 | pw.print(","); pw.print(mContentTop); |
| 5441 | pw.print(")-("); pw.print(mContentRight); |
| 5442 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
| 5443 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 5444 | pw.print(","); pw.print(mDockTop); |
| 5445 | pw.print(")-("); pw.print(mDockRight); |
| 5446 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
Dianne Hackborn | 5c58de3 | 2012-04-28 19:52:37 -0700 | [diff] [blame] | 5447 | pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer); |
| 5448 | pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer); |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5449 | pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen); |
| 5450 | pw.print(" mShowingDream="); pw.print(mShowingDream); |
| 5451 | pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5452 | if (mLastInputMethodWindow != null) { |
| 5453 | pw.print(prefix); pw.print("mLastInputMethodWindow="); |
| 5454 | pw.println(mLastInputMethodWindow); |
| 5455 | } |
| 5456 | if (mLastInputMethodTargetWindow != null) { |
| 5457 | pw.print(prefix); pw.print("mLastInputMethodTargetWindow="); |
| 5458 | pw.println(mLastInputMethodTargetWindow); |
| 5459 | } |
| 5460 | if (mStatusBar != null) { |
| 5461 | pw.print(prefix); pw.print("mStatusBar="); |
| 5462 | pw.println(mStatusBar); |
Jorim Jaggi | 380ecb8 | 2014-03-14 17:25:20 +0100 | [diff] [blame] | 5463 | pw.print(prefix); pw.print("isStatusBarKeyguard="); |
| 5464 | pw.print(isStatusBarKeyguard()); |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5465 | } |
| 5466 | if (mNavigationBar != null) { |
| 5467 | pw.print(prefix); pw.print("mNavigationBar="); |
| 5468 | pw.println(mNavigationBar); |
| 5469 | } |
Dianne Hackborn | 2ea9bae | 2012-11-02 18:43:48 -0700 | [diff] [blame] | 5470 | if (mFocusedWindow != null) { |
| 5471 | pw.print(prefix); pw.print("mFocusedWindow="); |
| 5472 | pw.println(mFocusedWindow); |
| 5473 | } |
| 5474 | if (mFocusedApp != null) { |
| 5475 | pw.print(prefix); pw.print("mFocusedApp="); |
| 5476 | pw.println(mFocusedApp); |
| 5477 | } |
| 5478 | if (mWinDismissingKeyguard != null) { |
| 5479 | pw.print(prefix); pw.print("mWinDismissingKeyguard="); |
| 5480 | pw.println(mWinDismissingKeyguard); |
| 5481 | } |
| 5482 | if (mTopFullscreenOpaqueWindowState != null) { |
| 5483 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 5484 | pw.println(mTopFullscreenOpaqueWindowState); |
| 5485 | } |
Dianne Hackborn | 891d3fb | 2013-01-09 18:31:37 -0800 | [diff] [blame] | 5486 | if (mForcingShowNavBar) { |
| 5487 | pw.print(prefix); pw.print("mForcingShowNavBar="); |
| 5488 | pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer="); |
| 5489 | pw.println(mForcingShowNavBarLayer); |
| 5490 | } |
Dianne Hackborn | 7ad4438 | 2012-10-18 17:46:00 -0700 | [diff] [blame] | 5491 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5492 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
Dianne Hackborn | 4c1e318 | 2012-10-05 18:37:54 -0700 | [diff] [blame] | 5493 | pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar); |
| 5494 | pw.print(" mForceStatusBarFromKeyguard="); |
| 5495 | pw.println(mForceStatusBarFromKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5496 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
Craig Mautner | ad09bcc | 2012-10-08 13:33:11 -0700 | [diff] [blame] | 5497 | pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5498 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 5499 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 5500 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 5501 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 5502 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 5503 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 5504 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 5505 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 5506 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 5507 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 5508 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
Jeff Brown | c82c89ed | 2013-04-17 17:18:15 -0700 | [diff] [blame] | 5509 | pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation); |
| 5510 | pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock); |
| 5511 | pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation); |
John Spurlock | 27735a4 | 2013-08-14 17:57:38 -0400 | [diff] [blame] | 5512 | mStatusBarController.dump(pw, prefix); |
| 5513 | mNavigationBarController.dump(pw, prefix); |
John Spurlock | c6d1c60 | 2014-01-17 15:22:06 -0500 | [diff] [blame] | 5514 | PolicyControl.dump(prefix, pw); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 5515 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 5516 | } |