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