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