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