The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.internal.policy.impl; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.app.ActivityManagerNative; |
| 21 | import android.app.IActivityManager; |
| 22 | import android.app.IStatusBar; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 23 | import android.app.IUiModeManager; |
| 24 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 25 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 26 | import android.content.BroadcastReceiver; |
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; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 31 | import android.content.pm.ActivityInfo; |
| 32 | import android.content.pm.PackageManager; |
| 33 | import android.content.res.Configuration; |
| 34 | import android.content.res.Resources; |
| 35 | import android.database.ContentObserver; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 36 | import android.graphics.PixelFormat; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 37 | import android.graphics.Rect; |
| 38 | import android.os.Handler; |
| 39 | import android.os.IBinder; |
| 40 | import android.os.LocalPowerManager; |
| 41 | import android.os.PowerManager; |
| 42 | import android.os.RemoteException; |
| 43 | import android.os.ServiceManager; |
| 44 | import android.os.SystemClock; |
| 45 | import android.os.SystemProperties; |
| 46 | import android.os.Vibrator; |
| 47 | import android.provider.Settings; |
| 48 | |
| 49 | import com.android.internal.policy.PolicyManager; |
| 50 | import com.android.internal.telephony.ITelephony; |
Dianne Hackborn | 6019c9d | 2010-03-01 21:43:11 -0800 | [diff] [blame] | 51 | import com.android.internal.widget.PointerLocationView; |
| 52 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 53 | import android.util.Config; |
| 54 | import android.util.EventLog; |
| 55 | import android.util.Log; |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 56 | import android.view.Display; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 57 | import android.view.Gravity; |
| 58 | import android.view.HapticFeedbackConstants; |
| 59 | import android.view.IWindowManager; |
| 60 | import android.view.KeyEvent; |
| 61 | import android.view.MotionEvent; |
| 62 | import android.view.WindowOrientationListener; |
| 63 | import android.view.RawInputEvent; |
| 64 | import android.view.Surface; |
| 65 | import android.view.View; |
| 66 | import android.view.ViewConfiguration; |
| 67 | import android.view.Window; |
| 68 | import android.view.WindowManager; |
| 69 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 70 | import static android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN; |
| 71 | import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN; |
| 72 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
| 73 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR; |
| 74 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 75 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 76 | import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 77 | 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] | 78 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
| 79 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
| 80 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 81 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 82 | 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] | 83 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; |
| 84 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL; |
| 85 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
| 86 | import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD; |
| 87 | import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG; |
| 88 | import static android.view.WindowManager.LayoutParams.TYPE_PHONE; |
| 89 | import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE; |
| 90 | import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR; |
| 91 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
| 92 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; |
Dianne Hackborn | 6a294ce | 2009-12-03 11:37:44 -0800 | [diff] [blame] | 93 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 94 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; |
| 95 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; |
| 96 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 97 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| 98 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; |
| 99 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 100 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 101 | import android.view.WindowManagerImpl; |
| 102 | import android.view.WindowManagerPolicy; |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 103 | import android.view.animation.Animation; |
| 104 | import android.view.animation.AnimationUtils; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 105 | import android.media.IAudioService; |
| 106 | import android.media.AudioManager; |
| 107 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 108 | import java.util.ArrayList; |
| 109 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 110 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 111 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 112 | * introduces a new method suffix, Lp, for an internal lock of the |
| 113 | * PhoneWindowManager. This is used to protect some internal state, and |
| 114 | * can be acquired with either thw Lw and Li lock held, so has the restrictions |
| 115 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 116 | */ |
| 117 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 118 | static final String TAG = "WindowManager"; |
| 119 | static final boolean DEBUG = false; |
| 120 | static final boolean localLOGV = DEBUG ? Config.LOGD : Config.LOGV; |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 121 | static final boolean DEBUG_LAYOUT = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 122 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 123 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
| 124 | |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 125 | // wallpaper is at the bottom, though the window manager may move it. |
Dianne Hackborn | 3c3bd44 | 2009-08-19 17:09:46 -0700 | [diff] [blame] | 126 | static final int WALLPAPER_LAYER = 2; |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 127 | static final int APPLICATION_LAYER = 2; |
| 128 | static final int PHONE_LAYER = 3; |
| 129 | static final int SEARCH_BAR_LAYER = 4; |
| 130 | static final int STATUS_BAR_PANEL_LAYER = 5; |
Dianne Hackborn | 6a294ce | 2009-12-03 11:37:44 -0800 | [diff] [blame] | 131 | static final int SYSTEM_DIALOG_LAYER = 6; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 132 | // toasts and the plugged-in battery thing |
Dianne Hackborn | 6a294ce | 2009-12-03 11:37:44 -0800 | [diff] [blame] | 133 | static final int TOAST_LAYER = 7; |
| 134 | static final int STATUS_BAR_LAYER = 8; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 135 | // SIM errors and unlock. Not sure if this really should be in a high layer. |
Dianne Hackborn | 6a294ce | 2009-12-03 11:37:44 -0800 | [diff] [blame] | 136 | static final int PRIORITY_PHONE_LAYER = 9; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 137 | // like the ANR / app crashed dialogs |
Dianne Hackborn | 6a294ce | 2009-12-03 11:37:44 -0800 | [diff] [blame] | 138 | static final int SYSTEM_ALERT_LAYER = 10; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 139 | // system-level error dialogs |
Dianne Hackborn | 6a294ce | 2009-12-03 11:37:44 -0800 | [diff] [blame] | 140 | static final int SYSTEM_ERROR_LAYER = 11; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 141 | // on-screen keyboards and other such input method user interfaces go here. |
Dianne Hackborn | 6a294ce | 2009-12-03 11:37:44 -0800 | [diff] [blame] | 142 | static final int INPUT_METHOD_LAYER = 12; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 143 | // on-screen keyboards and other such input method user interfaces go here. |
Dianne Hackborn | 6a294ce | 2009-12-03 11:37:44 -0800 | [diff] [blame] | 144 | static final int INPUT_METHOD_DIALOG_LAYER = 13; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 145 | // the keyguard; nothing on top of these can take focus, since they are |
| 146 | // responsible for power management when displayed. |
Dianne Hackborn | 6a294ce | 2009-12-03 11:37:44 -0800 | [diff] [blame] | 147 | static final int KEYGUARD_LAYER = 14; |
| 148 | static final int KEYGUARD_DIALOG_LAYER = 15; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 149 | // things in here CAN NOT take focus, but are shown on top of everything else. |
Dianne Hackborn | 6a294ce | 2009-12-03 11:37:44 -0800 | [diff] [blame] | 150 | static final int SYSTEM_OVERLAY_LAYER = 16; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 151 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 152 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 153 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 154 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 155 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
| 156 | |
| 157 | static final float SLIDE_TOUCH_EVENT_SIZE_LIMIT = 0.6f; |
| 158 | |
| 159 | // Debugging: set this to have the system act like there is no hard keyboard. |
| 160 | static final boolean KEYBOARD_ALWAYS_HIDDEN = false; |
| 161 | |
| 162 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 163 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 164 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 165 | 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] | 166 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 167 | final Object mLock = new Object(); |
| 168 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 169 | Context mContext; |
| 170 | IWindowManager mWindowManager; |
| 171 | LocalPowerManager mPowerManager; |
| 172 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
| 173 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 174 | // Vibrator pattern for haptic feedback of a long press. |
| 175 | long[] mLongPressVibePattern; |
| 176 | |
| 177 | // Vibrator pattern for haptic feedback of virtual key press. |
| 178 | long[] mVirtualKeyVibePattern; |
| 179 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 180 | // Vibrator pattern for a short vibration. |
| 181 | long[] mKeyboardTapVibePattern; |
| 182 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 183 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 184 | long[] mSafeModeDisabledVibePattern; |
| 185 | |
| 186 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 187 | long[] mSafeModeEnabledVibePattern; |
| 188 | |
Adam Powell | 9d86faf | 2010-02-10 11:39:57 -0800 | [diff] [blame] | 189 | // Vibrator pattern for haptic feedback when the user hits a touch scroll barrier. |
| 190 | long[] mScrollBarrierVibePattern; |
| 191 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 192 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 193 | boolean mEnableShiftMenuBugReports = false; |
| 194 | |
| 195 | boolean mSafeMode; |
| 196 | WindowState mStatusBar = null; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 197 | final ArrayList<WindowState> mStatusBarPanels = new ArrayList<WindowState>(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 198 | WindowState mKeyguard = null; |
| 199 | KeyguardViewMediator mKeyguardMediator; |
| 200 | GlobalActions mGlobalActions; |
| 201 | boolean mShouldTurnOffOnKeyUp; |
| 202 | RecentApplicationsDialog mRecentAppsDialog; |
| 203 | Handler mHandler; |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 204 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 205 | boolean mSystemReady; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 206 | boolean mLidOpen; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 207 | int mUiMode = Configuration.UI_MODE_TYPE_NORMAL; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 208 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 209 | int mCarDockRotation; |
| 210 | int mDeskDockRotation; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 211 | boolean mCarDockEnablesAccelerometer; |
| 212 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 213 | int mLidKeyboardAccessibility; |
| 214 | int mLidNavigationAccessibility; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 215 | boolean mScreenOn = false; |
| 216 | boolean mOrientationSensorEnabled = false; |
| 217 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 218 | static final int DEFAULT_ACCELEROMETER_ROTATION = 0; |
| 219 | int mAccelerometerDefault = DEFAULT_ACCELEROMETER_ROTATION; |
| 220 | boolean mHasSoftInput = false; |
| 221 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 222 | int mPointerLocationMode = 0; |
| 223 | PointerLocationView mPointerLocationView = null; |
| 224 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 225 | // The current size of the screen. |
| 226 | int mW, mH; |
| 227 | // During layout, the current screen borders with all outer decoration |
| 228 | // (status bar, input method dock) accounted for. |
| 229 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 230 | // During layout, the frame in which content should be displayed |
| 231 | // to the user, accounting for all screen decoration except for any |
| 232 | // space they deem as available for other content. This is usually |
| 233 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 234 | // content insets. |
| 235 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
| 236 | // During layout, the current screen borders along with input method |
| 237 | // windows are placed. |
| 238 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 239 | // During layout, the layer at which the doc window is placed. |
| 240 | int mDockLayer; |
| 241 | |
| 242 | static final Rect mTmpParentFrame = new Rect(); |
| 243 | static final Rect mTmpDisplayFrame = new Rect(); |
| 244 | static final Rect mTmpContentFrame = new Rect(); |
| 245 | static final Rect mTmpVisibleFrame = new Rect(); |
| 246 | |
| 247 | WindowState mTopFullscreenOpaqueWindowState; |
| 248 | boolean mForceStatusBar; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 249 | boolean mHideLockScreen; |
| 250 | boolean mDismissKeyguard; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 251 | boolean mHomePressed; |
| 252 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 253 | Intent mCarDockIntent; |
| 254 | Intent mDeskDockIntent; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 255 | boolean mSearchKeyPressed; |
| 256 | boolean mConsumeSearchKeyUp; |
| 257 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 258 | // support for activating the lock screen while the screen is on |
| 259 | boolean mAllowLockscreenWhenOn; |
| 260 | int mLockScreenTimeout; |
| 261 | boolean mLockScreenTimerActive; |
| 262 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame^] | 263 | // 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] | 264 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame^] | 265 | |
| 266 | // Behavior of POWER button while in-call and screen on. |
| 267 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 268 | int mIncallPowerBehavior; |
| 269 | |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 270 | int mLandscapeRotation = -1; |
| 271 | int mPortraitRotation = -1; |
| 272 | |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 273 | // Nothing to see here, move along... |
| 274 | int mFancyRotationAnimation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 275 | |
| 276 | ShortcutManager mShortcutManager; |
| 277 | PowerManager.WakeLock mBroadcastWakeLock; |
| 278 | |
| 279 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 280 | SettingsObserver(Handler handler) { |
| 281 | super(handler); |
| 282 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame^] | 283 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 284 | void observe() { |
| 285 | ContentResolver resolver = mContext.getContentResolver(); |
| 286 | resolver.registerContentObserver(Settings.System.getUriFor( |
| 287 | Settings.System.END_BUTTON_BEHAVIOR), false, this); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame^] | 288 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 289 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 290 | resolver.registerContentObserver(Settings.System.getUriFor( |
| 291 | Settings.System.ACCELEROMETER_ROTATION), false, this); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 292 | resolver.registerContentObserver(Settings.System.getUriFor( |
| 293 | Settings.System.SCREEN_OFF_TIMEOUT), false, this); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 294 | resolver.registerContentObserver(Settings.System.getUriFor( |
| 295 | Settings.System.POINTER_LOCATION), false, this); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 296 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 297 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this); |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 298 | resolver.registerContentObserver(Settings.System.getUriFor( |
| 299 | "fancy_rotation_anim"), false, this); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 300 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 304 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 305 | try { |
Dianne Hackborn | 32bc91d | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 306 | mWindowManager.setRotation(USE_LAST_ROTATION, false, |
| 307 | mFancyRotationAnimation); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 308 | } catch (RemoteException e) { |
| 309 | // Ignore |
| 310 | } |
| 311 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | class MyOrientationListener extends WindowOrientationListener { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 315 | MyOrientationListener(Context context) { |
| 316 | super(context); |
| 317 | } |
| 318 | |
| 319 | @Override |
The Android Open Source Project | d06b097 | 2009-03-13 13:04:23 -0700 | [diff] [blame] | 320 | public void onOrientationChanged(int rotation) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 321 | // Send updates based on orientation value |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 322 | if (localLOGV) Log.v(TAG, "onOrientationChanged, rotation changed to " +rotation); |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 323 | try { |
Dianne Hackborn | 32bc91d | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 324 | mWindowManager.setRotation(rotation, false, |
| 325 | mFancyRotationAnimation); |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 326 | } catch (RemoteException e) { |
| 327 | // Ignore |
Wink Saville | 37c124c | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 328 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | } |
| 332 | MyOrientationListener mOrientationListener; |
| 333 | |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 334 | boolean useSensorForOrientationLp(int appOrientation) { |
Joe Onorato | 1b58b3e | 2009-09-22 16:44:16 -0700 | [diff] [blame] | 335 | // The app says use the sensor. |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 336 | if (appOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 337 | return true; |
| 338 | } |
Joe Onorato | 1b58b3e | 2009-09-22 16:44:16 -0700 | [diff] [blame] | 339 | // The user preference says we can rotate, and the app is willing to rotate. |
| 340 | if (mAccelerometerDefault != 0 && |
| 341 | (appOrientation == ActivityInfo.SCREEN_ORIENTATION_USER |
| 342 | || appOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 343 | return true; |
| 344 | } |
Joe Onorato | 1b58b3e | 2009-09-22 16:44:16 -0700 | [diff] [blame] | 345 | // We're in a dock that has a rotation affinity, an the app is willing to rotate. |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 346 | if ((mCarDockEnablesAccelerometer && mUiMode == Configuration.UI_MODE_TYPE_CAR) |
| 347 | || (mDeskDockEnablesAccelerometer && mUiMode == Configuration.UI_MODE_TYPE_DESK)) { |
Joe Onorato | 1b58b3e | 2009-09-22 16:44:16 -0700 | [diff] [blame] | 348 | // Note we override the nosensor flag here. |
| 349 | if (appOrientation == ActivityInfo.SCREEN_ORIENTATION_USER |
| 350 | || appOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
| 351 | || appOrientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
| 352 | return true; |
| 353 | } |
| 354 | } |
| 355 | // Else, don't use the sensor. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 356 | return false; |
| 357 | } |
| 358 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 359 | /* |
| 360 | * We always let the sensor be switched on by default except when |
| 361 | * the user has explicitly disabled sensor based rotation or when the |
| 362 | * screen is switched off. |
| 363 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 364 | boolean needSensorRunningLp() { |
| 365 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 366 | // If the application has explicitly requested to follow the |
| 367 | // orientation, then we need to turn the sensor or. |
| 368 | return true; |
| 369 | } |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 370 | if ((mCarDockEnablesAccelerometer && mUiMode == Configuration.UI_MODE_TYPE_CAR) || |
| 371 | (mDeskDockEnablesAccelerometer && mUiMode == Configuration.UI_MODE_TYPE_DESK)) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 372 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 373 | // orientation management, |
| 374 | return true; |
| 375 | } |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 376 | if (mAccelerometerDefault == 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 377 | // If the setting for using the sensor by default is enabled, then |
| 378 | // we will always leave it on. Note that the user could go to |
| 379 | // a window that forces an orientation that does not use the |
| 380 | // sensor and in theory we could turn it off... however, when next |
| 381 | // turning it on we won't have a good value for the current |
| 382 | // orientation for a little bit, which can cause orientation |
| 383 | // changes to lag, so we'd like to keep it always on. (It will |
| 384 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 385 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 386 | } |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 387 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | /* |
| 391 | * Various use cases for invoking this function |
| 392 | * screen turning off, should always disable listeners if already enabled |
| 393 | * screen turned on and current app has sensor based orientation, enable listeners |
| 394 | * if not already enabled |
| 395 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 396 | * already enabled |
| 397 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 398 | * screen turning on and current app has nosensor based orientation, do nothing |
| 399 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 400 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 401 | if (!mOrientationListener.canDetectOrientation()) { |
| 402 | // If sensor is turned off or nonexistent for some reason |
| 403 | return; |
| 404 | } |
| 405 | //Could have been invoked due to screen turning on or off or |
| 406 | //change of the currently visible window's orientation |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 407 | if (localLOGV) Log.v(TAG, "Screen status="+mScreenOn+ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 408 | ", current orientation="+mCurrentAppOrientation+ |
| 409 | ", SensorEnabled="+mOrientationSensorEnabled); |
| 410 | boolean disable = true; |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 411 | if (mScreenOn) { |
| 412 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 413 | disable = false; |
| 414 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 415 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 416 | mOrientationListener.enable(); |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 417 | if(localLOGV) Log.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 418 | mOrientationSensorEnabled = true; |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 423 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 424 | mOrientationListener.disable(); |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 425 | if(localLOGV) Log.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 426 | mOrientationSensorEnabled = false; |
| 427 | } |
| 428 | } |
| 429 | |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 430 | Runnable mPowerLongPress = new Runnable() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 431 | public void run() { |
| 432 | mShouldTurnOffOnKeyUp = false; |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 433 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 434 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 435 | showGlobalActionsDialog(); |
| 436 | } |
| 437 | }; |
| 438 | |
| 439 | void showGlobalActionsDialog() { |
| 440 | if (mGlobalActions == null) { |
| 441 | mGlobalActions = new GlobalActions(mContext); |
| 442 | } |
Dianne Hackborn | 9dc06cc | 2009-11-17 18:19:23 -0800 | [diff] [blame] | 443 | final boolean keyguardShowing = mKeyguardMediator.isShowingAndNotHidden(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 444 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 445 | if (keyguardShowing) { |
| 446 | // since it took two seconds of long press to bring this up, |
| 447 | // poke the wake lock so they have some time to see the dialog. |
| 448 | mKeyguardMediator.pokeWakelock(); |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | boolean isDeviceProvisioned() { |
| 453 | return Settings.Secure.getInt( |
| 454 | mContext.getContentResolver(), Settings.Secure.DEVICE_PROVISIONED, 0) != 0; |
| 455 | } |
| 456 | |
| 457 | /** |
| 458 | * When a home-key longpress expires, close other system windows and launch the recent apps |
| 459 | */ |
| 460 | Runnable mHomeLongPress = new Runnable() { |
| 461 | public void run() { |
| 462 | /* |
| 463 | * Eat the longpress so it won't dismiss the recent apps dialog when |
| 464 | * the user lets go of the home key |
| 465 | */ |
| 466 | mHomePressed = false; |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 467 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 468 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS); |
| 469 | showRecentAppsDialog(); |
| 470 | } |
| 471 | }; |
| 472 | |
| 473 | /** |
| 474 | * Create (if necessary) and launch the recent apps dialog |
| 475 | */ |
| 476 | void showRecentAppsDialog() { |
| 477 | if (mRecentAppsDialog == null) { |
| 478 | mRecentAppsDialog = new RecentApplicationsDialog(mContext); |
| 479 | } |
| 480 | mRecentAppsDialog.show(); |
| 481 | } |
| 482 | |
| 483 | /** {@inheritDoc} */ |
| 484 | public void init(Context context, IWindowManager windowManager, |
| 485 | LocalPowerManager powerManager) { |
| 486 | mContext = context; |
| 487 | mWindowManager = windowManager; |
| 488 | mPowerManager = powerManager; |
| 489 | mKeyguardMediator = new KeyguardViewMediator(context, this, powerManager); |
| 490 | mHandler = new Handler(); |
| 491 | mOrientationListener = new MyOrientationListener(mContext); |
| 492 | SettingsObserver settingsObserver = new SettingsObserver(mHandler); |
| 493 | settingsObserver.observe(); |
| 494 | mShortcutManager = new ShortcutManager(context, mHandler); |
| 495 | mShortcutManager.observe(); |
| 496 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 497 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 498 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 499 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 500 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 501 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 502 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 503 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 504 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 505 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 506 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 507 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 508 | PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 509 | mBroadcastWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 510 | "PhoneWindowManager.mBroadcastWakeLock"); |
| 511 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 512 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 513 | com.android.internal.R.integer.config_lidOpenRotation); |
| 514 | mCarDockRotation = readRotation( |
| 515 | com.android.internal.R.integer.config_carDockRotation); |
| 516 | mDeskDockRotation = readRotation( |
| 517 | com.android.internal.R.integer.config_deskDockRotation); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 518 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 519 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 520 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 521 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 522 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 523 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 524 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 525 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 526 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 527 | IntentFilter filter = new IntentFilter(); |
| 528 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 529 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 530 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 531 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
| 532 | context.registerReceiver(mDockReceiver, filter); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 533 | mVibrator = new Vibrator(); |
| 534 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 535 | com.android.internal.R.array.config_longPressVibePattern); |
| 536 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 537 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 538 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 539 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 540 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 541 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 542 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 543 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Adam Powell | 9d86faf | 2010-02-10 11:39:57 -0800 | [diff] [blame] | 544 | mScrollBarrierVibePattern = getLongIntArray(mContext.getResources(), |
| 545 | com.android.internal.R.array.config_scrollBarrierVibePattern); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 548 | public void updateSettings() { |
| 549 | ContentResolver resolver = mContext.getContentResolver(); |
| 550 | boolean updateRotation = false; |
| 551 | View addView = null; |
| 552 | View removeView = null; |
| 553 | synchronized (mLock) { |
| 554 | mEndcallBehavior = Settings.System.getInt(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame^] | 555 | Settings.System.END_BUTTON_BEHAVIOR, |
| 556 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT); |
| 557 | mIncallPowerBehavior = Settings.Secure.getInt(resolver, |
| 558 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
| 559 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 560 | mFancyRotationAnimation = Settings.System.getInt(resolver, |
| 561 | "fancy_rotation_anim", 0) != 0 ? 0x80 : 0; |
| 562 | int accelerometerDefault = Settings.System.getInt(resolver, |
| 563 | Settings.System.ACCELEROMETER_ROTATION, DEFAULT_ACCELEROMETER_ROTATION); |
| 564 | if (mAccelerometerDefault != accelerometerDefault) { |
| 565 | mAccelerometerDefault = accelerometerDefault; |
| 566 | updateOrientationListenerLp(); |
| 567 | } |
| 568 | if (mSystemReady) { |
| 569 | int pointerLocation = Settings.System.getInt(resolver, |
| 570 | Settings.System.POINTER_LOCATION, 0); |
| 571 | if (mPointerLocationMode != pointerLocation) { |
| 572 | mPointerLocationMode = pointerLocation; |
| 573 | if (pointerLocation != 0) { |
| 574 | if (mPointerLocationView == null) { |
| 575 | mPointerLocationView = new PointerLocationView(mContext); |
| 576 | mPointerLocationView.setPrintCoords(false); |
| 577 | addView = mPointerLocationView; |
| 578 | } |
| 579 | } else { |
| 580 | removeView = mPointerLocationView; |
| 581 | mPointerLocationView = null; |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | // use screen off timeout setting as the timeout for the lockscreen |
| 586 | mLockScreenTimeout = Settings.System.getInt(resolver, |
| 587 | Settings.System.SCREEN_OFF_TIMEOUT, 0); |
| 588 | String imId = Settings.Secure.getString(resolver, |
| 589 | Settings.Secure.DEFAULT_INPUT_METHOD); |
| 590 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 591 | if (mHasSoftInput != hasSoftInput) { |
| 592 | mHasSoftInput = hasSoftInput; |
| 593 | updateRotation = true; |
| 594 | } |
| 595 | } |
| 596 | if (updateRotation) { |
| 597 | updateRotation(0); |
| 598 | } |
| 599 | if (addView != null) { |
| 600 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 601 | WindowManager.LayoutParams.MATCH_PARENT, |
| 602 | WindowManager.LayoutParams.MATCH_PARENT); |
| 603 | lp.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; |
| 604 | lp.flags = |
| 605 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 606 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 607 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
| 608 | lp.format = PixelFormat.TRANSLUCENT; |
| 609 | lp.setTitle("PointerLocation"); |
| 610 | WindowManagerImpl wm = (WindowManagerImpl) |
| 611 | mContext.getSystemService(Context.WINDOW_SERVICE); |
| 612 | wm.addView(addView, lp); |
| 613 | } |
| 614 | if (removeView != null) { |
| 615 | WindowManagerImpl wm = (WindowManagerImpl) |
| 616 | mContext.getSystemService(Context.WINDOW_SERVICE); |
| 617 | wm.removeView(removeView); |
| 618 | } |
| 619 | } |
| 620 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 621 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 622 | try { |
| 623 | int rotation = mContext.getResources().getInteger(resID); |
| 624 | switch (rotation) { |
| 625 | case 0: |
| 626 | return Surface.ROTATION_0; |
| 627 | case 90: |
| 628 | return Surface.ROTATION_90; |
| 629 | case 180: |
| 630 | return Surface.ROTATION_180; |
| 631 | case 270: |
| 632 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 633 | } |
| 634 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 635 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 636 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 637 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | /** {@inheritDoc} */ |
| 641 | public int checkAddPermission(WindowManager.LayoutParams attrs) { |
| 642 | int type = attrs.type; |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 643 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 644 | if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW |
| 645 | || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) { |
| 646 | return WindowManagerImpl.ADD_OKAY; |
| 647 | } |
| 648 | String permission = null; |
| 649 | switch (type) { |
| 650 | case TYPE_TOAST: |
| 651 | // XXX right now the app process has complete control over |
| 652 | // this... should introduce a token to let the system |
| 653 | // monitor/control what they are doing. |
| 654 | break; |
| 655 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 656 | case TYPE_WALLPAPER: |
| 657 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 658 | break; |
| 659 | case TYPE_PHONE: |
| 660 | case TYPE_PRIORITY_PHONE: |
| 661 | case TYPE_SYSTEM_ALERT: |
| 662 | case TYPE_SYSTEM_ERROR: |
| 663 | case TYPE_SYSTEM_OVERLAY: |
| 664 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
| 665 | break; |
| 666 | default: |
| 667 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 668 | } |
| 669 | if (permission != null) { |
| 670 | if (mContext.checkCallingOrSelfPermission(permission) |
| 671 | != PackageManager.PERMISSION_GRANTED) { |
| 672 | return WindowManagerImpl.ADD_PERMISSION_DENIED; |
| 673 | } |
| 674 | } |
| 675 | return WindowManagerImpl.ADD_OKAY; |
| 676 | } |
| 677 | |
| 678 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 679 | switch (attrs.type) { |
| 680 | case TYPE_SYSTEM_OVERLAY: |
| 681 | case TYPE_TOAST: |
| 682 | // These types of windows can't receive input events. |
| 683 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 684 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
| 685 | break; |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | void readLidState() { |
| 690 | try { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 691 | int sw = mWindowManager.getSwitchState(RawInputEvent.SW_LID); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 692 | if (sw >= 0) { |
| 693 | mLidOpen = sw == 0; |
| 694 | } |
| 695 | } catch (RemoteException e) { |
| 696 | // Ignore |
| 697 | } |
| 698 | } |
| 699 | |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 700 | private int determineHiddenState(boolean lidOpen, |
| 701 | int mode, int hiddenValue, int visibleValue) { |
| 702 | switch (mode) { |
| 703 | case 1: |
| 704 | return lidOpen ? visibleValue : hiddenValue; |
| 705 | case 2: |
| 706 | return lidOpen ? hiddenValue : visibleValue; |
| 707 | } |
| 708 | return visibleValue; |
| 709 | } |
| 710 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 711 | /** {@inheritDoc} */ |
| 712 | public void adjustConfigurationLw(Configuration config) { |
| 713 | readLidState(); |
| 714 | final boolean lidOpen = !KEYBOARD_ALWAYS_HIDDEN && mLidOpen; |
| 715 | mPowerManager.setKeyboardVisibility(lidOpen); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 716 | config.hardKeyboardHidden = determineHiddenState(lidOpen, |
| 717 | mLidKeyboardAccessibility, Configuration.HARDKEYBOARDHIDDEN_YES, |
| 718 | Configuration.HARDKEYBOARDHIDDEN_NO); |
| 719 | config.navigationHidden = determineHiddenState(lidOpen, |
| 720 | mLidNavigationAccessibility, Configuration.NAVIGATIONHIDDEN_YES, |
| 721 | Configuration.NAVIGATIONHIDDEN_NO); |
| 722 | config.keyboardHidden = (config.hardKeyboardHidden |
| 723 | == Configuration.HARDKEYBOARDHIDDEN_NO || mHasSoftInput) |
| 724 | ? Configuration.KEYBOARDHIDDEN_NO |
| 725 | : Configuration.KEYBOARDHIDDEN_YES; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | public boolean isCheekPressedAgainstScreen(MotionEvent ev) { |
| 729 | if(ev.getSize() > SLIDE_TOUCH_EVENT_SIZE_LIMIT) { |
| 730 | return true; |
| 731 | } |
| 732 | int size = ev.getHistorySize(); |
| 733 | for(int i = 0; i < size; i++) { |
| 734 | if(ev.getHistoricalSize(i) > SLIDE_TOUCH_EVENT_SIZE_LIMIT) { |
| 735 | return true; |
| 736 | } |
| 737 | } |
| 738 | return false; |
| 739 | } |
| 740 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 741 | public void dispatchedPointerEventLw(MotionEvent ev, int targetX, int targetY) { |
| 742 | if (mPointerLocationView == null) { |
| 743 | return; |
| 744 | } |
| 745 | synchronized (mLock) { |
| 746 | if (mPointerLocationView == null) { |
| 747 | return; |
| 748 | } |
| 749 | ev.offsetLocation(targetX, targetY); |
| 750 | mPointerLocationView.addTouchEvent(ev); |
| 751 | ev.offsetLocation(-targetX, -targetY); |
| 752 | } |
| 753 | } |
| 754 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 755 | /** {@inheritDoc} */ |
| 756 | public int windowTypeToLayerLw(int type) { |
| 757 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
| 758 | return APPLICATION_LAYER; |
| 759 | } |
| 760 | switch (type) { |
| 761 | case TYPE_STATUS_BAR: |
| 762 | return STATUS_BAR_LAYER; |
| 763 | case TYPE_STATUS_BAR_PANEL: |
| 764 | return STATUS_BAR_PANEL_LAYER; |
Dianne Hackborn | 6a294ce | 2009-12-03 11:37:44 -0800 | [diff] [blame] | 765 | case TYPE_SYSTEM_DIALOG: |
| 766 | return SYSTEM_DIALOG_LAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 767 | case TYPE_SEARCH_BAR: |
| 768 | return SEARCH_BAR_LAYER; |
| 769 | case TYPE_PHONE: |
| 770 | return PHONE_LAYER; |
| 771 | case TYPE_KEYGUARD: |
| 772 | return KEYGUARD_LAYER; |
| 773 | case TYPE_KEYGUARD_DIALOG: |
| 774 | return KEYGUARD_DIALOG_LAYER; |
| 775 | case TYPE_SYSTEM_ALERT: |
| 776 | return SYSTEM_ALERT_LAYER; |
| 777 | case TYPE_SYSTEM_ERROR: |
| 778 | return SYSTEM_ERROR_LAYER; |
| 779 | case TYPE_INPUT_METHOD: |
| 780 | return INPUT_METHOD_LAYER; |
| 781 | case TYPE_INPUT_METHOD_DIALOG: |
| 782 | return INPUT_METHOD_DIALOG_LAYER; |
| 783 | case TYPE_SYSTEM_OVERLAY: |
| 784 | return SYSTEM_OVERLAY_LAYER; |
| 785 | case TYPE_PRIORITY_PHONE: |
| 786 | return PRIORITY_PHONE_LAYER; |
| 787 | case TYPE_TOAST: |
| 788 | return TOAST_LAYER; |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 789 | case TYPE_WALLPAPER: |
| 790 | return WALLPAPER_LAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 791 | } |
| 792 | Log.e(TAG, "Unknown window type: " + type); |
| 793 | return APPLICATION_LAYER; |
| 794 | } |
| 795 | |
| 796 | /** {@inheritDoc} */ |
| 797 | public int subWindowTypeToLayerLw(int type) { |
| 798 | switch (type) { |
| 799 | case TYPE_APPLICATION_PANEL: |
| 800 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 801 | return APPLICATION_PANEL_SUBLAYER; |
| 802 | case TYPE_APPLICATION_MEDIA: |
| 803 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 804 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 805 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 806 | case TYPE_APPLICATION_SUB_PANEL: |
| 807 | return APPLICATION_SUB_PANEL_SUBLAYER; |
| 808 | } |
| 809 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 810 | return 0; |
| 811 | } |
| 812 | |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 813 | public int getMaxWallpaperLayer() { |
| 814 | return STATUS_BAR_LAYER; |
| 815 | } |
| 816 | |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 817 | public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) { |
| 818 | return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD; |
| 819 | } |
| 820 | |
| 821 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
| 822 | return attrs.type != WindowManager.LayoutParams.TYPE_STATUS_BAR |
| 823 | && attrs.type != WindowManager.LayoutParams.TYPE_WALLPAPER; |
| 824 | } |
| 825 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 826 | /** {@inheritDoc} */ |
| 827 | public View addStartingWindow(IBinder appToken, String packageName, |
| 828 | int theme, CharSequence nonLocalizedLabel, |
| 829 | int labelRes, int icon) { |
| 830 | if (!SHOW_STARTING_ANIMATIONS) { |
| 831 | return null; |
| 832 | } |
| 833 | if (packageName == null) { |
| 834 | return null; |
| 835 | } |
| 836 | |
| 837 | Context context = mContext; |
| 838 | boolean setTheme = false; |
| 839 | //Log.i(TAG, "addStartingWindow " + packageName + ": nonLocalizedLabel=" |
| 840 | // + nonLocalizedLabel + " theme=" + Integer.toHexString(theme)); |
| 841 | if (theme != 0 || labelRes != 0) { |
| 842 | try { |
| 843 | context = context.createPackageContext(packageName, 0); |
| 844 | if (theme != 0) { |
| 845 | context.setTheme(theme); |
| 846 | setTheme = true; |
| 847 | } |
| 848 | } catch (PackageManager.NameNotFoundException e) { |
| 849 | // Ignore |
| 850 | } |
| 851 | } |
| 852 | if (!setTheme) { |
| 853 | context.setTheme(com.android.internal.R.style.Theme); |
| 854 | } |
| 855 | |
| 856 | Window win = PolicyManager.makeNewWindow(context); |
| 857 | if (win.getWindowStyle().getBoolean( |
| 858 | com.android.internal.R.styleable.Window_windowDisablePreview, false)) { |
| 859 | return null; |
| 860 | } |
| 861 | |
| 862 | Resources r = context.getResources(); |
| 863 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
| 864 | |
| 865 | win.setType( |
| 866 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
| 867 | // Force the window flags: this is a fake window, so it is not really |
| 868 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 869 | // flag because we do know that the next window will take input |
| 870 | // focus, so we want to get the IME window up on top of us right away. |
| 871 | win.setFlags( |
| 872 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 873 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 874 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
| 875 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 876 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 877 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
| 878 | |
Romain Guy | cc6828c | 2010-01-08 15:06:37 -0800 | [diff] [blame] | 879 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
| 880 | WindowManager.LayoutParams.MATCH_PARENT); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 881 | |
| 882 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 883 | params.token = appToken; |
| 884 | params.packageName = packageName; |
| 885 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 886 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
| 887 | params.setTitle("Starting " + packageName); |
| 888 | |
| 889 | try { |
| 890 | WindowManagerImpl wm = (WindowManagerImpl) |
| 891 | context.getSystemService(Context.WINDOW_SERVICE); |
| 892 | View view = win.getDecorView(); |
| 893 | |
| 894 | if (win.isFloating()) { |
| 895 | // Whoops, there is no way to display an animation/preview |
| 896 | // of such a thing! After all that work... let's skip it. |
| 897 | // (Note that we must do this here because it is in |
| 898 | // getDecorView() where the theme is evaluated... maybe |
| 899 | // we should peek the floating attribute from the theme |
| 900 | // earlier.) |
| 901 | return null; |
| 902 | } |
| 903 | |
| 904 | if (localLOGV) Log.v( |
| 905 | TAG, "Adding starting window for " + packageName |
| 906 | + " / " + appToken + ": " |
| 907 | + (view.getParent() != null ? view : null)); |
| 908 | |
| 909 | wm.addView(view, params); |
| 910 | |
| 911 | // Only return the view if it was successfully added to the |
| 912 | // window manager... which we can tell by it having a parent. |
| 913 | return view.getParent() != null ? view : null; |
| 914 | } catch (WindowManagerImpl.BadTokenException e) { |
| 915 | // ignore |
| 916 | Log.w(TAG, appToken + " already running, starting window not displayed"); |
| 917 | } |
| 918 | |
| 919 | return null; |
| 920 | } |
| 921 | |
| 922 | /** {@inheritDoc} */ |
| 923 | public void removeStartingWindow(IBinder appToken, View window) { |
| 924 | // RuntimeException e = new RuntimeException(); |
| 925 | // Log.i(TAG, "remove " + appToken + " " + window, e); |
| 926 | |
| 927 | if (localLOGV) Log.v( |
| 928 | TAG, "Removing starting window for " + appToken + ": " + window); |
| 929 | |
| 930 | if (window != null) { |
| 931 | WindowManagerImpl wm = (WindowManagerImpl) mContext.getSystemService(Context.WINDOW_SERVICE); |
| 932 | wm.removeView(window); |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | /** |
| 937 | * Preflight adding a window to the system. |
| 938 | * |
| 939 | * Currently enforces that three window types are singletons: |
| 940 | * <ul> |
| 941 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 942 | * <li>KEYGUARD_TYPE</li> |
| 943 | * </ul> |
| 944 | * |
| 945 | * @param win The window to be added |
| 946 | * @param attrs Information about the window to be added |
| 947 | * |
| 948 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
| 949 | */ |
| 950 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 951 | switch (attrs.type) { |
| 952 | case TYPE_STATUS_BAR: |
| 953 | if (mStatusBar != null) { |
| 954 | return WindowManagerImpl.ADD_MULTIPLE_SINGLETON; |
| 955 | } |
| 956 | mStatusBar = win; |
| 957 | break; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 958 | case TYPE_STATUS_BAR_PANEL: |
| 959 | mStatusBarPanels.add(win); |
| 960 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 961 | case TYPE_KEYGUARD: |
| 962 | if (mKeyguard != null) { |
| 963 | return WindowManagerImpl.ADD_MULTIPLE_SINGLETON; |
| 964 | } |
| 965 | mKeyguard = win; |
| 966 | break; |
| 967 | } |
| 968 | return WindowManagerImpl.ADD_OKAY; |
| 969 | } |
| 970 | |
| 971 | /** {@inheritDoc} */ |
| 972 | public void removeWindowLw(WindowState win) { |
| 973 | if (mStatusBar == win) { |
| 974 | mStatusBar = null; |
| 975 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 976 | else if (mKeyguard == win) { |
| 977 | mKeyguard = null; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 978 | } else { |
| 979 | mStatusBarPanels.remove(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 980 | } |
| 981 | } |
| 982 | |
| 983 | static final boolean PRINT_ANIM = false; |
| 984 | |
| 985 | /** {@inheritDoc} */ |
| 986 | public int selectAnimationLw(WindowState win, int transit) { |
| 987 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 988 | + ": transit=" + transit); |
| 989 | if (transit == TRANSIT_PREVIEW_DONE) { |
| 990 | if (win.hasAppShownWindows()) { |
| 991 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 992 | return com.android.internal.R.anim.app_starting_exit; |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | return 0; |
| 997 | } |
| 998 | |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 999 | public Animation createForceHideEnterAnimation() { |
| 1000 | return AnimationUtils.loadAnimation(mContext, |
| 1001 | com.android.internal.R.anim.lock_screen_behind_enter); |
| 1002 | } |
| 1003 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1004 | static ITelephony getPhoneInterface() { |
| 1005 | return ITelephony.Stub.asInterface(ServiceManager.checkService(Context.TELEPHONY_SERVICE)); |
| 1006 | } |
| 1007 | |
| 1008 | static IAudioService getAudioInterface() { |
| 1009 | return IAudioService.Stub.asInterface(ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 1010 | } |
| 1011 | |
| 1012 | boolean keyguardOn() { |
| 1013 | return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode(); |
| 1014 | } |
| 1015 | |
| 1016 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 1017 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 1018 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 1019 | }; |
| 1020 | |
| 1021 | /** {@inheritDoc} */ |
| 1022 | public boolean interceptKeyTi(WindowState win, int code, int metaKeys, boolean down, |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 1023 | int repeatCount, int flags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1024 | boolean keyguardOn = keyguardOn(); |
| 1025 | |
| 1026 | if (false) { |
| 1027 | Log.d(TAG, "interceptKeyTi code=" + code + " down=" + down + " repeatCount=" |
| 1028 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed); |
| 1029 | } |
| 1030 | |
| 1031 | // Clear a pending HOME longpress if the user releases Home |
| 1032 | // TODO: This could probably be inside the next bit of logic, but that code |
| 1033 | // turned out to be a bit fragile so I'm doing it here explicitly, for now. |
| 1034 | if ((code == KeyEvent.KEYCODE_HOME) && !down) { |
| 1035 | mHandler.removeCallbacks(mHomeLongPress); |
| 1036 | } |
| 1037 | |
| 1038 | // If the HOME button is currently being held, then we do special |
| 1039 | // chording with it. |
| 1040 | if (mHomePressed) { |
| 1041 | |
| 1042 | // If we have released the home key, and didn't do anything else |
| 1043 | // while it was pressed, then it is time to go home! |
| 1044 | if (code == KeyEvent.KEYCODE_HOME) { |
| 1045 | if (!down) { |
| 1046 | mHomePressed = false; |
| 1047 | |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 1048 | if ((flags&KeyEvent.FLAG_CANCELED) == 0) { |
| 1049 | // If an incoming call is ringing, HOME is totally disabled. |
| 1050 | // (The user is already on the InCallScreen at this point, |
| 1051 | // and his ONLY options are to answer or reject the call.) |
| 1052 | boolean incomingRinging = false; |
| 1053 | try { |
| 1054 | ITelephony phoneServ = getPhoneInterface(); |
| 1055 | if (phoneServ != null) { |
| 1056 | incomingRinging = phoneServ.isRinging(); |
| 1057 | } else { |
| 1058 | Log.w(TAG, "Unable to find ITelephony interface"); |
| 1059 | } |
| 1060 | } catch (RemoteException ex) { |
| 1061 | Log.w(TAG, "RemoteException from getPhoneInterface()", ex); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1062 | } |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 1063 | |
| 1064 | if (incomingRinging) { |
| 1065 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 1066 | } else { |
| 1067 | launchHomeFromHotKey(); |
| 1068 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1069 | } else { |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 1070 | Log.i(TAG, "Ignoring HOME; event canceled."); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1071 | } |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | return true; |
| 1076 | } |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 1077 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1078 | // First we always handle the home key here, so applications |
| 1079 | // can never break it, although if keyguard is on, we do let |
| 1080 | // it handle it, because that gives us the correct 5 second |
| 1081 | // timeout. |
| 1082 | if (code == KeyEvent.KEYCODE_HOME) { |
| 1083 | |
| 1084 | // If a system window has focus, then it doesn't make sense |
| 1085 | // right now to interact with applications. |
| 1086 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 1087 | if (attrs != null) { |
| 1088 | final int type = attrs.type; |
| 1089 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 1090 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) { |
| 1091 | // the "app" is keyguard, so give it the key |
| 1092 | return false; |
| 1093 | } |
| 1094 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 1095 | for (int i=0; i<typeCount; i++) { |
| 1096 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 1097 | // don't do anything, but also don't pass it to the app |
| 1098 | return true; |
| 1099 | } |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | if (down && repeatCount == 0) { |
| 1104 | if (!keyguardOn) { |
| 1105 | mHandler.postDelayed(mHomeLongPress, ViewConfiguration.getGlobalActionKeyTimeout()); |
| 1106 | } |
| 1107 | mHomePressed = true; |
| 1108 | } |
| 1109 | return true; |
| 1110 | } else if (code == KeyEvent.KEYCODE_MENU) { |
| 1111 | // Hijack modified menu keys for debugging features |
| 1112 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 1113 | |
| 1114 | if (down && repeatCount == 0) { |
| 1115 | if (mEnableShiftMenuBugReports && (metaKeys & chordBug) == chordBug) { |
| 1116 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
| 1117 | mContext.sendOrderedBroadcast(intent, null); |
| 1118 | return true; |
| 1119 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
| 1120 | (metaKeys & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
| 1121 | Intent service = new Intent(); |
| 1122 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 1123 | ContentResolver res = mContext.getContentResolver(); |
| 1124 | boolean shown = Settings.System.getInt( |
| 1125 | res, Settings.System.SHOW_PROCESSES, 0) != 0; |
| 1126 | if (!shown) { |
| 1127 | mContext.startService(service); |
| 1128 | } else { |
| 1129 | mContext.stopService(service); |
| 1130 | } |
| 1131 | Settings.System.putInt( |
| 1132 | res, Settings.System.SHOW_PROCESSES, shown ? 0 : 1); |
| 1133 | return true; |
| 1134 | } |
| 1135 | } |
| 1136 | } else if (code == KeyEvent.KEYCODE_NOTIFICATION) { |
| 1137 | if (down) { |
| 1138 | // this key doesn't exist on current hardware, but if a device |
| 1139 | // didn't have a touchscreen, it would want one of these to open |
| 1140 | // the status bar. |
| 1141 | IStatusBar sbs = IStatusBar.Stub.asInterface(ServiceManager.getService("statusbar")); |
| 1142 | if (sbs != null) { |
| 1143 | try { |
| 1144 | sbs.toggle(); |
| 1145 | } catch (RemoteException e) { |
| 1146 | // we're screwed anyway, since it's in this process |
| 1147 | throw new RuntimeException(e); |
| 1148 | } |
| 1149 | } |
| 1150 | } |
| 1151 | return true; |
| 1152 | } else if (code == KeyEvent.KEYCODE_SEARCH) { |
| 1153 | if (down) { |
| 1154 | if (repeatCount == 0) { |
| 1155 | mSearchKeyPressed = true; |
| 1156 | } |
| 1157 | } else { |
| 1158 | mSearchKeyPressed = false; |
| 1159 | |
| 1160 | if (mConsumeSearchKeyUp) { |
| 1161 | // Consume the up-event |
| 1162 | mConsumeSearchKeyUp = false; |
| 1163 | return true; |
| 1164 | } |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | // Shortcuts are invoked through Search+key, so intercept those here |
| 1169 | if (mSearchKeyPressed) { |
| 1170 | if (down && repeatCount == 0 && !keyguardOn) { |
| 1171 | Intent shortcutIntent = mShortcutManager.getIntent(code, metaKeys); |
| 1172 | if (shortcutIntent != null) { |
| 1173 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1174 | mContext.startActivity(shortcutIntent); |
| 1175 | |
| 1176 | /* |
| 1177 | * We launched an app, so the up-event of the search key |
| 1178 | * should be consumed |
| 1179 | */ |
| 1180 | mConsumeSearchKeyUp = true; |
| 1181 | return true; |
| 1182 | } |
| 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | return false; |
| 1187 | } |
| 1188 | |
| 1189 | /** |
| 1190 | * A home key -> launch home action was detected. Take the appropriate action |
| 1191 | * given the situation with the keyguard. |
| 1192 | */ |
| 1193 | void launchHomeFromHotKey() { |
Dianne Hackborn | 9dc06cc | 2009-11-17 18:19:23 -0800 | [diff] [blame] | 1194 | if (mKeyguardMediator.isShowingAndNotHidden()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1195 | // don't launch home if keyguard showing |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1196 | } else if (!mHideLockScreen && mKeyguardMediator.isInputRestricted()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1197 | // when in keyguard restricted mode, must first verify unlock |
| 1198 | // before launching home |
| 1199 | mKeyguardMediator.verifyUnlock(new OnKeyguardExitResult() { |
| 1200 | public void onKeyguardExitResult(boolean success) { |
| 1201 | if (success) { |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 1202 | try { |
| 1203 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 1204 | } catch (RemoteException e) { |
| 1205 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 1206 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1207 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1208 | } |
| 1209 | } |
| 1210 | }); |
| 1211 | } else { |
| 1212 | // no keyguard stuff to worry about, just launch home! |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 1213 | try { |
| 1214 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 1215 | } catch (RemoteException e) { |
| 1216 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 1217 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1218 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) { |
| 1223 | final int fl = attrs.flags; |
| 1224 | |
| 1225 | if ((fl & |
| 1226 | (FLAG_LAYOUT_IN_SCREEN | FLAG_FULLSCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 1227 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
| 1228 | contentInset.set(mCurLeft, mCurTop, mW - mCurRight, mH - mCurBottom); |
| 1229 | } else { |
| 1230 | contentInset.setEmpty(); |
| 1231 | } |
| 1232 | } |
| 1233 | |
| 1234 | /** {@inheritDoc} */ |
| 1235 | public void beginLayoutLw(int displayWidth, int displayHeight) { |
| 1236 | mW = displayWidth; |
| 1237 | mH = displayHeight; |
| 1238 | mDockLeft = mContentLeft = mCurLeft = 0; |
| 1239 | mDockTop = mContentTop = mCurTop = 0; |
| 1240 | mDockRight = mContentRight = mCurRight = displayWidth; |
| 1241 | mDockBottom = mContentBottom = mCurBottom = displayHeight; |
| 1242 | mDockLayer = 0x10000000; |
| 1243 | |
| 1244 | // decide where the status bar goes ahead of time |
| 1245 | if (mStatusBar != null) { |
| 1246 | final Rect pf = mTmpParentFrame; |
| 1247 | final Rect df = mTmpDisplayFrame; |
| 1248 | final Rect vf = mTmpVisibleFrame; |
| 1249 | pf.left = df.left = vf.left = 0; |
| 1250 | pf.top = df.top = vf.top = 0; |
| 1251 | pf.right = df.right = vf.right = displayWidth; |
| 1252 | pf.bottom = df.bottom = vf.bottom = displayHeight; |
| 1253 | |
| 1254 | mStatusBar.computeFrameLw(pf, df, vf, vf); |
| 1255 | if (mStatusBar.isVisibleLw()) { |
| 1256 | // If the status bar is hidden, we don't want to cause |
| 1257 | // windows behind it to scroll. |
| 1258 | mDockTop = mContentTop = mCurTop = mStatusBar.getFrameLw().bottom; |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 1259 | if (DEBUG_LAYOUT) Log.v(TAG, "Status bar: mDockBottom=" |
| 1260 | + mDockBottom + " mContentBottom=" |
| 1261 | + mContentBottom + " mCurBottom=" + mCurBottom); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1262 | } |
| 1263 | } |
| 1264 | } |
| 1265 | |
| 1266 | void setAttachedWindowFrames(WindowState win, int fl, int sim, |
| 1267 | WindowState attached, boolean insetDecors, Rect pf, Rect df, Rect cf, Rect vf) { |
| 1268 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 1269 | // Here's a special case: if this attached window is a panel that is |
| 1270 | // above the dock window, and the window it is attached to is below |
| 1271 | // the dock window, then the frames we computed for the window it is |
| 1272 | // attached to can not be used because the dock is effectively part |
| 1273 | // of the underlying window and the attached window is floating on top |
| 1274 | // of the whole thing. So, we ignore the attached window and explicitly |
| 1275 | // compute the frames that would be appropriate without the dock. |
| 1276 | df.left = cf.left = vf.left = mDockLeft; |
| 1277 | df.top = cf.top = vf.top = mDockTop; |
| 1278 | df.right = cf.right = vf.right = mDockRight; |
| 1279 | df.bottom = cf.bottom = vf.bottom = mDockBottom; |
| 1280 | } else { |
| 1281 | // The effective display frame of the attached window depends on |
| 1282 | // whether it is taking care of insetting its content. If not, |
| 1283 | // we need to use the parent's content frame so that the entire |
| 1284 | // window is positioned within that content. Otherwise we can use |
| 1285 | // the display frame and let the attached window take care of |
| 1286 | // positioning its content appropriately. |
| 1287 | if ((sim & SOFT_INPUT_MASK_ADJUST) != SOFT_INPUT_ADJUST_RESIZE) { |
| 1288 | cf.set(attached.getDisplayFrameLw()); |
| 1289 | } else { |
| 1290 | // If the window is resizing, then we want to base the content |
| 1291 | // frame on our attached content frame to resize... however, |
| 1292 | // things can be tricky if the attached window is NOT in resize |
| 1293 | // mode, in which case its content frame will be larger. |
| 1294 | // Ungh. So to deal with that, make sure the content frame |
| 1295 | // we end up using is not covering the IM dock. |
| 1296 | cf.set(attached.getContentFrameLw()); |
| 1297 | if (attached.getSurfaceLayer() < mDockLayer) { |
| 1298 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 1299 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 1300 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 1301 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 1302 | } |
| 1303 | } |
| 1304 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
| 1305 | vf.set(attached.getVisibleFrameLw()); |
| 1306 | } |
| 1307 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 1308 | // window should be positioned relative to its parent or the entire |
| 1309 | // screen. |
| 1310 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 1311 | ? attached.getFrameLw() : df); |
| 1312 | } |
| 1313 | |
| 1314 | /** {@inheritDoc} */ |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 1315 | public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs, |
| 1316 | WindowState attached) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1317 | // we've already done the status bar |
| 1318 | if (win == mStatusBar) { |
| 1319 | return; |
| 1320 | } |
| 1321 | |
| 1322 | if (false) { |
| 1323 | if ("com.google.android.youtube".equals(attrs.packageName) |
| 1324 | && attrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| 1325 | Log.i(TAG, "GOTCHA!"); |
| 1326 | } |
| 1327 | } |
| 1328 | |
| 1329 | final int fl = attrs.flags; |
| 1330 | final int sim = attrs.softInputMode; |
| 1331 | |
| 1332 | final Rect pf = mTmpParentFrame; |
| 1333 | final Rect df = mTmpDisplayFrame; |
| 1334 | final Rect cf = mTmpContentFrame; |
| 1335 | final Rect vf = mTmpVisibleFrame; |
| 1336 | |
| 1337 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1338 | pf.left = df.left = cf.left = vf.left = mDockLeft; |
| 1339 | pf.top = df.top = cf.top = vf.top = mDockTop; |
| 1340 | pf.right = df.right = cf.right = vf.right = mDockRight; |
| 1341 | pf.bottom = df.bottom = cf.bottom = vf.bottom = mDockBottom; |
| 1342 | // IM dock windows always go to the bottom of the screen. |
| 1343 | attrs.gravity = Gravity.BOTTOM; |
| 1344 | mDockLayer = win.getSurfaceLayer(); |
| 1345 | } else { |
| 1346 | if ((fl & |
| 1347 | (FLAG_LAYOUT_IN_SCREEN | FLAG_FULLSCREEN | FLAG_LAYOUT_INSET_DECOR)) |
| 1348 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
| 1349 | // This is the case for a normal activity window: we want it |
| 1350 | // to cover all of the screen space, and it can take care of |
| 1351 | // moving its contents to account for screen decorations that |
| 1352 | // intrude into that space. |
| 1353 | if (attached != null) { |
| 1354 | // If this window is attached to another, our display |
| 1355 | // frame is the same as the one we are attached to. |
| 1356 | setAttachedWindowFrames(win, fl, sim, attached, true, pf, df, cf, vf); |
| 1357 | } else { |
| 1358 | pf.left = df.left = 0; |
| 1359 | pf.top = df.top = 0; |
| 1360 | pf.right = df.right = mW; |
| 1361 | pf.bottom = df.bottom = mH; |
| 1362 | if ((sim & SOFT_INPUT_MASK_ADJUST) != SOFT_INPUT_ADJUST_RESIZE) { |
| 1363 | cf.left = mDockLeft; |
| 1364 | cf.top = mDockTop; |
| 1365 | cf.right = mDockRight; |
| 1366 | cf.bottom = mDockBottom; |
| 1367 | } else { |
| 1368 | cf.left = mContentLeft; |
| 1369 | cf.top = mContentTop; |
| 1370 | cf.right = mContentRight; |
| 1371 | cf.bottom = mContentBottom; |
| 1372 | } |
| 1373 | vf.left = mCurLeft; |
| 1374 | vf.top = mCurTop; |
| 1375 | vf.right = mCurRight; |
| 1376 | vf.bottom = mCurBottom; |
| 1377 | } |
| 1378 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0) { |
| 1379 | // A window that has requested to fill the entire screen just |
| 1380 | // gets everything, period. |
| 1381 | pf.left = df.left = cf.left = 0; |
| 1382 | pf.top = df.top = cf.top = 0; |
| 1383 | pf.right = df.right = cf.right = mW; |
| 1384 | pf.bottom = df.bottom = cf.bottom = mH; |
| 1385 | vf.left = mCurLeft; |
| 1386 | vf.top = mCurTop; |
| 1387 | vf.right = mCurRight; |
| 1388 | vf.bottom = mCurBottom; |
| 1389 | } else if (attached != null) { |
| 1390 | // A child window should be placed inside of the same visible |
| 1391 | // frame that its parent had. |
| 1392 | setAttachedWindowFrames(win, fl, sim, attached, false, pf, df, cf, vf); |
| 1393 | } else { |
| 1394 | // Otherwise, a normal window must be placed inside the content |
| 1395 | // of all screen decorations. |
| 1396 | pf.left = mContentLeft; |
| 1397 | pf.top = mContentTop; |
| 1398 | pf.right = mContentRight; |
| 1399 | pf.bottom = mContentBottom; |
| 1400 | if ((sim & SOFT_INPUT_MASK_ADJUST) != SOFT_INPUT_ADJUST_RESIZE) { |
| 1401 | df.left = cf.left = mDockLeft; |
| 1402 | df.top = cf.top = mDockTop; |
| 1403 | df.right = cf.right = mDockRight; |
| 1404 | df.bottom = cf.bottom = mDockBottom; |
| 1405 | } else { |
| 1406 | df.left = cf.left = mContentLeft; |
| 1407 | df.top = cf.top = mContentTop; |
| 1408 | df.right = cf.right = mContentRight; |
| 1409 | df.bottom = cf.bottom = mContentBottom; |
| 1410 | } |
| 1411 | vf.left = mCurLeft; |
| 1412 | vf.top = mCurTop; |
| 1413 | vf.right = mCurRight; |
| 1414 | vf.bottom = mCurBottom; |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0) { |
| 1419 | df.left = df.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 1420 | df.right = df.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
| 1421 | } |
| 1422 | |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 1423 | if (DEBUG_LAYOUT) Log.v(TAG, "Compute frame " + attrs.getTitle() |
| 1424 | + ": sim=#" + Integer.toHexString(sim) |
| 1425 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
| 1426 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()); |
| 1427 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1428 | if (false) { |
| 1429 | if ("com.google.android.youtube".equals(attrs.packageName) |
| 1430 | && attrs.type == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) { |
| 1431 | if (true || localLOGV) Log.v(TAG, "Computing frame of " + win + |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 1432 | ": sim=#" + Integer.toHexString(sim) |
| 1433 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1434 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()); |
| 1435 | } |
| 1436 | } |
| 1437 | |
| 1438 | win.computeFrameLw(pf, df, cf, vf); |
| 1439 | |
| 1440 | // Dock windows carve out the bottom of the screen, so normal windows |
| 1441 | // can't appear underneath them. |
| 1442 | if (attrs.type == TYPE_INPUT_METHOD && !win.getGivenInsetsPendingLw()) { |
| 1443 | int top = win.getContentFrameLw().top; |
| 1444 | top += win.getGivenContentInsetsLw().top; |
| 1445 | if (mContentBottom > top) { |
| 1446 | mContentBottom = top; |
| 1447 | } |
| 1448 | top = win.getVisibleFrameLw().top; |
| 1449 | top += win.getGivenVisibleInsetsLw().top; |
| 1450 | if (mCurBottom > top) { |
| 1451 | mCurBottom = top; |
| 1452 | } |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 1453 | if (DEBUG_LAYOUT) Log.v(TAG, "Input method: mDockBottom=" |
| 1454 | + mDockBottom + " mContentBottom=" |
| 1455 | + mContentBottom + " mCurBottom=" + mCurBottom); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | /** {@inheritDoc} */ |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1460 | public int finishLayoutLw() { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 1461 | return 0; |
| 1462 | } |
| 1463 | |
| 1464 | /** {@inheritDoc} */ |
| 1465 | public void beginAnimationLw(int displayWidth, int displayHeight) { |
| 1466 | mTopFullscreenOpaqueWindowState = null; |
| 1467 | mForceStatusBar = false; |
| 1468 | |
| 1469 | mHideLockScreen = false; |
| 1470 | mAllowLockscreenWhenOn = false; |
| 1471 | mDismissKeyguard = false; |
| 1472 | } |
| 1473 | |
| 1474 | /** {@inheritDoc} */ |
| 1475 | public void animatingWindowLw(WindowState win, |
| 1476 | WindowManager.LayoutParams attrs) { |
| 1477 | if (mTopFullscreenOpaqueWindowState == null && |
| 1478 | win.isVisibleOrBehindKeyguardLw()) { |
| 1479 | if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
| 1480 | mForceStatusBar = true; |
| 1481 | } |
| 1482 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1483 | && attrs.type <= LAST_APPLICATION_WINDOW |
| 1484 | && win.fillsScreenLw(mW, mH, false, false)) { |
| 1485 | if (DEBUG_LAYOUT) Log.v(TAG, "Fullscreen window: " + win); |
| 1486 | mTopFullscreenOpaqueWindowState = win; |
| 1487 | if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) { |
| 1488 | if (localLOGV) Log.v(TAG, "Setting mHideLockScreen to true by win " + win); |
| 1489 | mHideLockScreen = true; |
| 1490 | } |
| 1491 | if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0) { |
| 1492 | if (localLOGV) Log.v(TAG, "Setting mDismissKeyguard to true by win " + win); |
| 1493 | mDismissKeyguard = true; |
| 1494 | } |
| 1495 | if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
| 1496 | mAllowLockscreenWhenOn = true; |
| 1497 | } |
| 1498 | } |
| 1499 | } |
| 1500 | } |
| 1501 | |
| 1502 | /** {@inheritDoc} */ |
| 1503 | public int finishAnimationLw() { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1504 | int changes = 0; |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 1505 | |
The Android Open Source Project | c84bf28 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 1506 | boolean hiding = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1507 | if (mStatusBar != null) { |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 1508 | if (localLOGV) Log.i(TAG, "force=" + mForceStatusBar |
| 1509 | + " top=" + mTopFullscreenOpaqueWindowState); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1510 | if (mForceStatusBar) { |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 1511 | if (DEBUG_LAYOUT) Log.v(TAG, "Showing status bar"); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1512 | if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1513 | } else if (mTopFullscreenOpaqueWindowState != null) { |
| 1514 | //Log.i(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
| 1515 | // + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); |
| 1516 | //Log.i(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()); |
| 1517 | WindowManager.LayoutParams lp = |
| 1518 | mTopFullscreenOpaqueWindowState.getAttrs(); |
| 1519 | boolean hideStatusBar = |
| 1520 | (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
| 1521 | if (hideStatusBar) { |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 1522 | if (DEBUG_LAYOUT) Log.v(TAG, "Hiding status bar"); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1523 | if (mStatusBar.hideLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | c84bf28 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 1524 | hiding = true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1525 | } else { |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 1526 | if (DEBUG_LAYOUT) Log.v(TAG, "Showing status bar"); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1527 | if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1528 | } |
| 1529 | } |
| 1530 | } |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 1531 | |
| 1532 | if (changes != 0 && hiding) { |
| 1533 | IStatusBar sbs = IStatusBar.Stub.asInterface(ServiceManager.getService("statusbar")); |
| 1534 | if (sbs != null) { |
| 1535 | try { |
| 1536 | // Make sure the window shade is hidden. |
| 1537 | sbs.deactivate(); |
| 1538 | } catch (RemoteException e) { |
| 1539 | } |
| 1540 | } |
| 1541 | } |
| 1542 | |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 1543 | // Hide the key guard if a visible window explicitly specifies that it wants to be displayed |
| 1544 | // when the screen is locked |
| 1545 | if (mKeyguard != null) { |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 1546 | if (localLOGV) Log.v(TAG, "finishLayoutLw::mHideKeyguard="+mHideLockScreen); |
| 1547 | if (mDismissKeyguard && !mKeyguardMediator.isSecure()) { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1548 | if (mKeyguard.hideLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1549 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 1550 | | FINISH_LAYOUT_REDO_CONFIG |
| 1551 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 1552 | } |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 1553 | if (mKeyguardMediator.isShowing()) { |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 1554 | mHandler.post(new Runnable() { |
| 1555 | public void run() { |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 1556 | mKeyguardMediator.keyguardDone(false, false); |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 1557 | } |
| 1558 | }); |
| 1559 | } |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 1560 | } else if (mHideLockScreen) { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1561 | if (mKeyguard.hideLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1562 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 1563 | | FINISH_LAYOUT_REDO_CONFIG |
| 1564 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 1565 | } |
Mike Lockwood | f3bfed5 | 2010-01-21 16:38:44 -0500 | [diff] [blame] | 1566 | mKeyguardMediator.setHidden(true); |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 1567 | } else { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1568 | if (mKeyguard.showLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1569 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 1570 | | FINISH_LAYOUT_REDO_CONFIG |
| 1571 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 1572 | } |
Mike Lockwood | f3bfed5 | 2010-01-21 16:38:44 -0500 | [diff] [blame] | 1573 | mKeyguardMediator.setHidden(false); |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 1574 | } |
| 1575 | } |
The Android Open Source Project | c84bf28 | 2009-03-09 11:52:14 -0700 | [diff] [blame] | 1576 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 1577 | // update since mAllowLockscreenWhenOn might have changed |
| 1578 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1579 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1580 | } |
| 1581 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1582 | public boolean allowAppAnimationsLw() { |
| 1583 | if (mKeyguard != null && mKeyguard.isVisibleLw()) { |
| 1584 | // If keyguard is currently visible, no reason to animate |
| 1585 | // behind it. |
| 1586 | return false; |
| 1587 | } |
| 1588 | if (mStatusBar != null && mStatusBar.isVisibleLw()) { |
| 1589 | Rect rect = new Rect(mStatusBar.getShownFrameLw()); |
| 1590 | for (int i=mStatusBarPanels.size()-1; i>=0; i--) { |
| 1591 | WindowState w = mStatusBarPanels.get(i); |
| 1592 | if (w.isVisibleLw()) { |
| 1593 | rect.union(w.getShownFrameLw()); |
| 1594 | } |
| 1595 | } |
| 1596 | final int insetw = mW/10; |
| 1597 | final int inseth = mH/10; |
| 1598 | if (rect.contains(insetw, inseth, mW-insetw, mH-inseth)) { |
| 1599 | // All of the status bar windows put together cover the |
| 1600 | // screen, so the app can't be seen. (Note this test doesn't |
| 1601 | // work if the rects of these windows are at off offsets or |
| 1602 | // sizes, causing gaps in the rect union we have computed.) |
| 1603 | return false; |
| 1604 | } |
| 1605 | } |
| 1606 | return true; |
| 1607 | } |
| 1608 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 1609 | /** {@inheritDoc} */ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1610 | public boolean preprocessInputEventTq(RawInputEvent event) { |
| 1611 | switch (event.type) { |
| 1612 | case RawInputEvent.EV_SW: |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1613 | if (event.keycode == RawInputEvent.SW_LID) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1614 | // lid changed state |
| 1615 | mLidOpen = event.value == 0; |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 1616 | boolean awakeNow = mKeyguardMediator.doLidChangeTq(mLidOpen); |
Dianne Hackborn | 32bc91d | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 1617 | updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 1618 | if (awakeNow) { |
| 1619 | // If the lid opening and we don't have to keep the |
| 1620 | // keyguard up, then we can turn on the screen |
| 1621 | // immediately. |
| 1622 | mKeyguardMediator.pokeWakelock(); |
| 1623 | } else if (keyguardIsShowingTq()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1624 | if (mLidOpen) { |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 1625 | // If we are opening the lid and not hiding the |
| 1626 | // keyguard, then we need to have it turn on the |
| 1627 | // screen once it is shown. |
| 1628 | mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq( |
| 1629 | KeyEvent.KEYCODE_POWER); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1630 | } |
| 1631 | } else { |
| 1632 | // Light up the keyboard if we are sliding up. |
| 1633 | if (mLidOpen) { |
| 1634 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 1635 | LocalPowerManager.BUTTON_EVENT); |
| 1636 | } else { |
| 1637 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 1638 | LocalPowerManager.OTHER_EVENT); |
| 1639 | } |
| 1640 | } |
| 1641 | } |
| 1642 | } |
| 1643 | return false; |
| 1644 | } |
| 1645 | |
| 1646 | |
| 1647 | /** {@inheritDoc} */ |
| 1648 | public boolean isAppSwitchKeyTqTiLwLi(int keycode) { |
| 1649 | return keycode == KeyEvent.KEYCODE_HOME |
| 1650 | || keycode == KeyEvent.KEYCODE_ENDCALL; |
| 1651 | } |
| 1652 | |
| 1653 | /** {@inheritDoc} */ |
| 1654 | public boolean isMovementKeyTi(int keycode) { |
| 1655 | switch (keycode) { |
| 1656 | case KeyEvent.KEYCODE_DPAD_UP: |
| 1657 | case KeyEvent.KEYCODE_DPAD_DOWN: |
| 1658 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 1659 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 1660 | return true; |
| 1661 | } |
| 1662 | return false; |
| 1663 | } |
| 1664 | |
| 1665 | |
| 1666 | /** |
| 1667 | * @return Whether a telephone call is in progress right now. |
| 1668 | */ |
| 1669 | boolean isInCall() { |
| 1670 | final ITelephony phone = getPhoneInterface(); |
| 1671 | if (phone == null) { |
| 1672 | Log.w(TAG, "couldn't get ITelephony reference"); |
| 1673 | return false; |
| 1674 | } |
| 1675 | try { |
| 1676 | return phone.isOffhook(); |
| 1677 | } catch (RemoteException e) { |
| 1678 | Log.w(TAG, "ITelephony.isOffhhook threw RemoteException " + e); |
| 1679 | return false; |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | /** |
| 1684 | * @return Whether music is being played right now. |
| 1685 | */ |
| 1686 | boolean isMusicActive() { |
Eric Laurent | 413cb9d | 2009-07-17 11:52:43 -0700 | [diff] [blame] | 1687 | final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); |
| 1688 | if (am == null) { |
| 1689 | Log.w(TAG, "isMusicActive: couldn't get AudioManager reference"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1690 | return false; |
| 1691 | } |
Eric Laurent | 413cb9d | 2009-07-17 11:52:43 -0700 | [diff] [blame] | 1692 | return am.isMusicActive(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | /** |
| 1696 | * Tell the audio service to adjust the volume appropriate to the event. |
| 1697 | * @param keycode |
| 1698 | */ |
Mike Lockwood | a53e381 | 2009-09-25 10:51:39 -0400 | [diff] [blame] | 1699 | void handleVolumeKey(int stream, int keycode) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1700 | final IAudioService audio = getAudioInterface(); |
| 1701 | if (audio == null) { |
Mike Lockwood | a53e381 | 2009-09-25 10:51:39 -0400 | [diff] [blame] | 1702 | Log.w(TAG, "handleVolumeKey: couldn't get IAudioService reference"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1703 | return; |
| 1704 | } |
| 1705 | try { |
| 1706 | // since audio is playing, we shouldn't have to hold a wake lock |
| 1707 | // during the call, but we do it as a precaution for the rare possibility |
| 1708 | // that the music stops right before we call this |
| 1709 | mBroadcastWakeLock.acquire(); |
Mike Lockwood | a53e381 | 2009-09-25 10:51:39 -0400 | [diff] [blame] | 1710 | audio.adjustStreamVolume(stream, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1711 | keycode == KeyEvent.KEYCODE_VOLUME_UP |
| 1712 | ? AudioManager.ADJUST_RAISE |
| 1713 | : AudioManager.ADJUST_LOWER, |
| 1714 | 0); |
| 1715 | } catch (RemoteException e) { |
| 1716 | Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e); |
| 1717 | } finally { |
| 1718 | mBroadcastWakeLock.release(); |
| 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | static boolean isMediaKey(int code) { |
| 1723 | if (code == KeyEvent.KEYCODE_HEADSETHOOK || |
Andy Stadler | 8b89d69 | 2009-04-10 16:24:49 -0700 | [diff] [blame] | 1724 | code == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE || |
| 1725 | code == KeyEvent.KEYCODE_MEDIA_STOP || |
| 1726 | code == KeyEvent.KEYCODE_MEDIA_NEXT || |
| 1727 | code == KeyEvent.KEYCODE_MEDIA_PREVIOUS || |
Johan Redestig | 2e2a3d0 | 2010-01-05 08:45:33 +0100 | [diff] [blame] | 1728 | code == KeyEvent.KEYCODE_MEDIA_REWIND || |
Andy Stadler | 8b89d69 | 2009-04-10 16:24:49 -0700 | [diff] [blame] | 1729 | code == KeyEvent.KEYCODE_MEDIA_FAST_FORWARD) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1730 | return true; |
| 1731 | } |
| 1732 | return false; |
| 1733 | } |
| 1734 | |
| 1735 | /** {@inheritDoc} */ |
| 1736 | public int interceptKeyTq(RawInputEvent event, boolean screenIsOn) { |
| 1737 | int result = ACTION_PASS_TO_USER; |
| 1738 | final boolean isWakeKey = isWakeKeyTq(event); |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 1739 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 1740 | // the same as if it were open and in front. |
| 1741 | // This will prevent any keys other than the power button from waking the screen |
| 1742 | // when the keyguard is hidden by another activity. |
| 1743 | final boolean keyguardActive = (screenIsOn ? |
| 1744 | mKeyguardMediator.isShowingAndNotHidden() : |
| 1745 | mKeyguardMediator.isShowing()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1746 | |
| 1747 | if (false) { |
| 1748 | Log.d(TAG, "interceptKeyTq event=" + event + " keycode=" + event.keycode |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 1749 | + " screenIsOn=" + screenIsOn + " keyguardActive=" + keyguardActive); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1750 | } |
| 1751 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 1752 | if (keyguardActive) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1753 | if (screenIsOn) { |
| 1754 | // when the screen is on, always give the event to the keyguard |
| 1755 | result |= ACTION_PASS_TO_USER; |
| 1756 | } else { |
| 1757 | // otherwise, don't pass it to the user |
| 1758 | result &= ~ACTION_PASS_TO_USER; |
| 1759 | |
| 1760 | final boolean isKeyDown = |
| 1761 | (event.type == RawInputEvent.EV_KEY) && (event.value != 0); |
| 1762 | if (isWakeKey && isKeyDown) { |
| 1763 | |
| 1764 | // tell the mediator about a wake key, it may decide to |
| 1765 | // turn on the screen depending on whether the key is |
| 1766 | // appropriate. |
| 1767 | if (!mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(event.keycode) |
| 1768 | && (event.keycode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 1769 | || event.keycode == KeyEvent.KEYCODE_VOLUME_UP)) { |
Mike Lockwood | 99ff0a8 | 2009-12-02 01:37:38 -0500 | [diff] [blame] | 1770 | // when keyguard is showing and screen off, we need |
| 1771 | // to handle the volume key for calls and music here |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1772 | if (isInCall()) { |
Mike Lockwood | 99ff0a8 | 2009-12-02 01:37:38 -0500 | [diff] [blame] | 1773 | handleVolumeKey(AudioManager.STREAM_VOICE_CALL, event.keycode); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1774 | } else if (isMusicActive()) { |
Mike Lockwood | a53e381 | 2009-09-25 10:51:39 -0400 | [diff] [blame] | 1775 | handleVolumeKey(AudioManager.STREAM_MUSIC, event.keycode); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1776 | } |
| 1777 | } |
| 1778 | } |
| 1779 | } |
| 1780 | } else if (!screenIsOn) { |
Mike Lockwood | a53e381 | 2009-09-25 10:51:39 -0400 | [diff] [blame] | 1781 | // If we are in-call with screen off and keyguard is not showing, |
| 1782 | // then handle the volume key ourselves. |
| 1783 | // This is necessary because the phone app will disable the keyguard |
| 1784 | // when the proximity sensor is in use. |
| 1785 | if (isInCall() && event.type == RawInputEvent.EV_KEY && |
| 1786 | (event.keycode == KeyEvent.KEYCODE_VOLUME_DOWN |
| 1787 | || event.keycode == KeyEvent.KEYCODE_VOLUME_UP)) { |
| 1788 | result &= ~ACTION_PASS_TO_USER; |
| 1789 | handleVolumeKey(AudioManager.STREAM_VOICE_CALL, event.keycode); |
| 1790 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1791 | if (isWakeKey) { |
| 1792 | // a wake key has a sole purpose of waking the device; don't pass |
| 1793 | // it to the user |
| 1794 | result |= ACTION_POKE_USER_ACTIVITY; |
| 1795 | result &= ~ACTION_PASS_TO_USER; |
| 1796 | } |
| 1797 | } |
| 1798 | |
| 1799 | int type = event.type; |
| 1800 | int code = event.keycode; |
| 1801 | boolean down = event.value != 0; |
| 1802 | |
| 1803 | if (type == RawInputEvent.EV_KEY) { |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 1804 | if (code == KeyEvent.KEYCODE_ENDCALL |
| 1805 | || code == KeyEvent.KEYCODE_POWER) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1806 | if (down) { |
Mike Lockwood | 2eb4796 | 2009-10-23 11:29:52 -0400 | [diff] [blame] | 1807 | boolean handled = false; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame^] | 1808 | boolean hungUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1809 | // key repeats are generated by the window manager, and we don't see them |
| 1810 | // here, so unless the driver is doing something it shouldn't be, we know |
| 1811 | // this is the real press event. |
Mike Lockwood | 75d3caa | 2009-10-22 13:14:31 -0400 | [diff] [blame] | 1812 | ITelephony phoneServ = getPhoneInterface(); |
| 1813 | if (phoneServ != null) { |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 1814 | try { |
Mike Lockwood | 2eb4796 | 2009-10-23 11:29:52 -0400 | [diff] [blame] | 1815 | if (code == KeyEvent.KEYCODE_ENDCALL) { |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame^] | 1816 | handled = hungUp = phoneServ.endCall(); |
| 1817 | } else if (code == KeyEvent.KEYCODE_POWER) { |
| 1818 | if (phoneServ.isRinging()) { |
| 1819 | // Pressing Power while there's a ringing incoming |
| 1820 | // call should silence the ringer. |
| 1821 | phoneServ.silenceRinger(); |
| 1822 | handled = true; |
| 1823 | } else if (phoneServ.isOffhook() && |
| 1824 | ((mIncallPowerBehavior |
| 1825 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) |
| 1826 | != 0)) { |
| 1827 | // Otherwise, if "Power button ends call" is enabled, |
| 1828 | // the Power button will hang up any current active call. |
| 1829 | handled = hungUp = phoneServ.endCall(); |
| 1830 | } |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 1831 | } |
| 1832 | } catch (RemoteException ex) { |
Mike Lockwood | 75d3caa | 2009-10-22 13:14:31 -0400 | [diff] [blame] | 1833 | Log.w(TAG, "ITelephony threw RemoteException" + ex); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1834 | } |
Mike Lockwood | 75d3caa | 2009-10-22 13:14:31 -0400 | [diff] [blame] | 1835 | } else { |
| 1836 | Log.w(TAG, "!!! Unable to find ITelephony interface !!!"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1837 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame^] | 1838 | |
| 1839 | if (!screenIsOn |
| 1840 | || (handled && code != KeyEvent.KEYCODE_POWER) |
| 1841 | || (handled && hungUp && code == KeyEvent.KEYCODE_POWER)) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1842 | mShouldTurnOffOnKeyUp = false; |
| 1843 | } else { |
| 1844 | // only try to turn off the screen if we didn't already hang up |
| 1845 | mShouldTurnOffOnKeyUp = true; |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 1846 | mHandler.postDelayed(mPowerLongPress, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1847 | ViewConfiguration.getGlobalActionKeyTimeout()); |
| 1848 | result &= ~ACTION_PASS_TO_USER; |
| 1849 | } |
| 1850 | } else { |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 1851 | mHandler.removeCallbacks(mPowerLongPress); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1852 | if (mShouldTurnOffOnKeyUp) { |
| 1853 | mShouldTurnOffOnKeyUp = false; |
Mike Lockwood | b4e2d1c | 2009-11-23 15:54:10 -0500 | [diff] [blame] | 1854 | boolean gohome, sleeps; |
| 1855 | if (code == KeyEvent.KEYCODE_ENDCALL) { |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame^] | 1856 | gohome = (mEndcallBehavior |
| 1857 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0; |
| 1858 | sleeps = (mEndcallBehavior |
| 1859 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0; |
Mike Lockwood | b4e2d1c | 2009-11-23 15:54:10 -0500 | [diff] [blame] | 1860 | } else { |
| 1861 | gohome = false; |
| 1862 | sleeps = true; |
| 1863 | } |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 1864 | if (keyguardActive |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1865 | || (sleeps && !gohome) |
| 1866 | || (gohome && !goHome() && sleeps)) { |
| 1867 | // they must already be on the keyguad or home screen, |
| 1868 | // go to sleep instead |
| 1869 | Log.d(TAG, "I'm tired mEndcallBehavior=0x" |
| 1870 | + Integer.toHexString(mEndcallBehavior)); |
| 1871 | result &= ~ACTION_POKE_USER_ACTIVITY; |
| 1872 | result |= ACTION_GO_TO_SLEEP; |
| 1873 | } |
| 1874 | result &= ~ACTION_PASS_TO_USER; |
| 1875 | } |
| 1876 | } |
| 1877 | } else if (isMediaKey(code)) { |
| 1878 | // This key needs to be handled even if the screen is off. |
| 1879 | // If others need to be handled while it's off, this is a reasonable |
| 1880 | // pattern to follow. |
| 1881 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 1882 | // Only do this if we would otherwise not pass it to the user. In that |
| 1883 | // case, the PhoneWindow class will do the same thing, except it will |
| 1884 | // only do it if the showing app doesn't process the key on its own. |
| 1885 | KeyEvent keyEvent = new KeyEvent(event.when, event.when, |
| 1886 | down ? KeyEvent.ACTION_DOWN : KeyEvent.ACTION_UP, |
| 1887 | code, 0); |
| 1888 | mBroadcastWakeLock.acquire(); |
| 1889 | mHandler.post(new PassHeadsetKey(keyEvent)); |
| 1890 | } |
| 1891 | } else if (code == KeyEvent.KEYCODE_CALL) { |
| 1892 | // If an incoming call is ringing, answer it! |
| 1893 | // (We handle this key here, rather than in the InCallScreen, to make |
| 1894 | // sure we'll respond to the key even if the InCallScreen hasn't come to |
| 1895 | // the foreground yet.) |
| 1896 | |
| 1897 | // We answer the call on the DOWN event, to agree with |
| 1898 | // the "fallback" behavior in the InCallScreen. |
| 1899 | if (down) { |
| 1900 | try { |
| 1901 | ITelephony phoneServ = getPhoneInterface(); |
| 1902 | if (phoneServ != null) { |
| 1903 | if (phoneServ.isRinging()) { |
| 1904 | Log.i(TAG, "interceptKeyTq:" |
| 1905 | + " CALL key-down while ringing: Answer the call!"); |
| 1906 | phoneServ.answerRingingCall(); |
| 1907 | |
| 1908 | // And *don't* pass this key thru to the current activity |
| 1909 | // (which is presumably the InCallScreen.) |
| 1910 | result &= ~ACTION_PASS_TO_USER; |
| 1911 | } |
| 1912 | } else { |
| 1913 | Log.w(TAG, "CALL button: Unable to find ITelephony interface"); |
| 1914 | } |
| 1915 | } catch (RemoteException ex) { |
| 1916 | Log.w(TAG, "CALL button: RemoteException from getPhoneInterface()", ex); |
| 1917 | } |
| 1918 | } |
| 1919 | } else if ((code == KeyEvent.KEYCODE_VOLUME_UP) |
| 1920 | || (code == KeyEvent.KEYCODE_VOLUME_DOWN)) { |
| 1921 | // If an incoming call is ringing, either VOLUME key means |
| 1922 | // "silence ringer". We handle these keys here, rather than |
| 1923 | // in the InCallScreen, to make sure we'll respond to them |
| 1924 | // even if the InCallScreen hasn't come to the foreground yet. |
| 1925 | |
| 1926 | // Look for the DOWN event here, to agree with the "fallback" |
| 1927 | // behavior in the InCallScreen. |
| 1928 | if (down) { |
| 1929 | try { |
| 1930 | ITelephony phoneServ = getPhoneInterface(); |
| 1931 | if (phoneServ != null) { |
| 1932 | if (phoneServ.isRinging()) { |
| 1933 | Log.i(TAG, "interceptKeyTq:" |
| 1934 | + " VOLUME key-down while ringing: Silence ringer!"); |
| 1935 | // Silence the ringer. (It's safe to call this |
| 1936 | // even if the ringer has already been silenced.) |
| 1937 | phoneServ.silenceRinger(); |
| 1938 | |
| 1939 | // And *don't* pass this key thru to the current activity |
| 1940 | // (which is probably the InCallScreen.) |
| 1941 | result &= ~ACTION_PASS_TO_USER; |
| 1942 | } |
| 1943 | } else { |
| 1944 | Log.w(TAG, "VOLUME button: Unable to find ITelephony interface"); |
| 1945 | } |
| 1946 | } catch (RemoteException ex) { |
| 1947 | Log.w(TAG, "VOLUME button: RemoteException from getPhoneInterface()", ex); |
| 1948 | } |
| 1949 | } |
| 1950 | } |
| 1951 | } |
| 1952 | |
| 1953 | return result; |
| 1954 | } |
| 1955 | |
| 1956 | class PassHeadsetKey implements Runnable { |
| 1957 | KeyEvent mKeyEvent; |
| 1958 | |
| 1959 | PassHeadsetKey(KeyEvent keyEvent) { |
| 1960 | mKeyEvent = keyEvent; |
| 1961 | } |
| 1962 | |
| 1963 | public void run() { |
| 1964 | if (ActivityManagerNative.isSystemReady()) { |
| 1965 | Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON, null); |
| 1966 | intent.putExtra(Intent.EXTRA_KEY_EVENT, mKeyEvent); |
| 1967 | mContext.sendOrderedBroadcast(intent, null, mBroadcastDone, |
| 1968 | mHandler, Activity.RESULT_OK, null, null); |
| 1969 | } |
| 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | BroadcastReceiver mBroadcastDone = new BroadcastReceiver() { |
| 1974 | public void onReceive(Context context, Intent intent) { |
| 1975 | mBroadcastWakeLock.release(); |
| 1976 | } |
| 1977 | }; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1978 | |
| 1979 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
| 1980 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1981 | try { |
| 1982 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 1983 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 1984 | mUiMode = uiModeService.getCurrentModeType(); |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 1985 | } catch (RemoteException e) { |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 1986 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1987 | updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 1988 | updateOrientationListenerLp(); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 1989 | } |
| 1990 | }; |
| 1991 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1992 | /** {@inheritDoc} */ |
| 1993 | public boolean isWakeRelMovementTq(int device, int classes, |
| 1994 | RawInputEvent event) { |
| 1995 | // if it's tagged with one of the wake bits, it wakes up the device |
| 1996 | return ((event.flags & (FLAG_WAKE | FLAG_WAKE_DROPPED)) != 0); |
| 1997 | } |
| 1998 | |
| 1999 | /** {@inheritDoc} */ |
| 2000 | public boolean isWakeAbsMovementTq(int device, int classes, |
| 2001 | RawInputEvent event) { |
| 2002 | // if it's tagged with one of the wake bits, it wakes up the device |
| 2003 | return ((event.flags & (FLAG_WAKE | FLAG_WAKE_DROPPED)) != 0); |
| 2004 | } |
| 2005 | |
| 2006 | /** |
| 2007 | * Given the current state of the world, should this key wake up the device? |
| 2008 | */ |
| 2009 | protected boolean isWakeKeyTq(RawInputEvent event) { |
| 2010 | // There are not key maps for trackball devices, but we'd still |
| 2011 | // like to have pressing it wake the device up, so force it here. |
| 2012 | int keycode = event.keycode; |
| 2013 | int flags = event.flags; |
| 2014 | if (keycode == RawInputEvent.BTN_MOUSE) { |
| 2015 | flags |= WindowManagerPolicy.FLAG_WAKE; |
| 2016 | } |
| 2017 | return (flags |
| 2018 | & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0; |
| 2019 | } |
| 2020 | |
| 2021 | /** {@inheritDoc} */ |
| 2022 | public void screenTurnedOff(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 2023 | EventLog.writeEvent(70000, 0); |
| 2024 | mKeyguardMediator.onScreenTurnedOff(why); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2025 | synchronized (mLock) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2026 | mScreenOn = false; |
| 2027 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 2028 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2029 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | /** {@inheritDoc} */ |
| 2033 | public void screenTurnedOn() { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 2034 | EventLog.writeEvent(70000, 1); |
| 2035 | mKeyguardMediator.onScreenTurnedOn(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2036 | synchronized (mLock) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2037 | mScreenOn = true; |
| 2038 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 2039 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2040 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | /** {@inheritDoc} */ |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2044 | public boolean isScreenOn() { |
| 2045 | return mScreenOn; |
| 2046 | } |
| 2047 | |
| 2048 | /** {@inheritDoc} */ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2049 | public void enableKeyguard(boolean enabled) { |
| 2050 | mKeyguardMediator.setKeyguardEnabled(enabled); |
| 2051 | } |
| 2052 | |
| 2053 | /** {@inheritDoc} */ |
| 2054 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
| 2055 | mKeyguardMediator.verifyUnlock(callback); |
| 2056 | } |
| 2057 | |
Mike Lockwood | f791330 | 2009-11-28 22:27:10 -0500 | [diff] [blame] | 2058 | private boolean keyguardIsShowingTq() { |
Dianne Hackborn | 9dc06cc | 2009-11-17 18:19:23 -0800 | [diff] [blame] | 2059 | return mKeyguardMediator.isShowingAndNotHidden(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | /** {@inheritDoc} */ |
| 2063 | public boolean inKeyguardRestrictedKeyInputMode() { |
| 2064 | return mKeyguardMediator.isInputRestricted(); |
| 2065 | } |
| 2066 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2067 | void sendCloseSystemWindows() { |
| 2068 | sendCloseSystemWindows(mContext, null); |
| 2069 | } |
| 2070 | |
| 2071 | void sendCloseSystemWindows(String reason) { |
| 2072 | sendCloseSystemWindows(mContext, reason); |
| 2073 | } |
| 2074 | |
| 2075 | static void sendCloseSystemWindows(Context context, String reason) { |
| 2076 | if (ActivityManagerNative.isSystemReady()) { |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 2077 | try { |
| 2078 | ActivityManagerNative.getDefault().closeSystemDialogs(reason); |
| 2079 | } catch (RemoteException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2080 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2081 | } |
| 2082 | } |
| 2083 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2084 | public int rotationForOrientationLw(int orientation, int lastRotation, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2085 | boolean displayEnabled) { |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 2086 | |
| 2087 | if (mPortraitRotation < 0) { |
| 2088 | // Initialize the rotation angles for each orientation once. |
| 2089 | Display d = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)) |
| 2090 | .getDefaultDisplay(); |
| 2091 | if (d.getWidth() > d.getHeight()) { |
| 2092 | mPortraitRotation = Surface.ROTATION_90; |
| 2093 | mLandscapeRotation = Surface.ROTATION_0; |
| 2094 | } else { |
| 2095 | mPortraitRotation = Surface.ROTATION_0; |
| 2096 | mLandscapeRotation = Surface.ROTATION_90; |
| 2097 | } |
| 2098 | } |
| 2099 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2100 | synchronized (mLock) { |
| 2101 | switch (orientation) { |
| 2102 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 2103 | //always return landscape if orientation set to landscape |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 2104 | return mLandscapeRotation; |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2105 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 2106 | //always return portrait if orientation set to portrait |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 2107 | return mPortraitRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2108 | } |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2109 | // case for nosensor meaning ignore sensor and consider only lid |
| 2110 | // or orientation sensor disabled |
| 2111 | //or case.unspecified |
| 2112 | if (mLidOpen) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2113 | return mLidOpenRotation; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 2114 | } else if (mUiMode == Configuration.UI_MODE_TYPE_CAR && mCarDockRotation >= 0) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2115 | return mCarDockRotation; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 2116 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK && mDeskDockRotation >= 0) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2117 | return mDeskDockRotation; |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2118 | } else { |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 2119 | if (useSensorForOrientationLp(orientation)) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2120 | // If the user has enabled auto rotation by default, do it. |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 2121 | int curRotation = mOrientationListener.getCurrentRotation(); |
| 2122 | return curRotation >= 0 ? curRotation : lastRotation; |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2123 | } |
| 2124 | return Surface.ROTATION_0; |
| 2125 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2126 | } |
| 2127 | } |
| 2128 | |
| 2129 | public boolean detectSafeMode() { |
| 2130 | try { |
| 2131 | int menuState = mWindowManager.getKeycodeState(KeyEvent.KEYCODE_MENU); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2132 | int sState = mWindowManager.getKeycodeState(KeyEvent.KEYCODE_S); |
Dianne Hackborn | a8730f9 | 2009-11-17 15:53:36 -0800 | [diff] [blame] | 2133 | int dpadState = mWindowManager.getDPadKeycodeState(KeyEvent.KEYCODE_DPAD_CENTER); |
| 2134 | int trackballState = mWindowManager.getTrackballScancodeState(RawInputEvent.BTN_MOUSE); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2135 | mSafeMode = menuState > 0 || sState > 0 || dpadState > 0 || trackballState > 0; |
| 2136 | performHapticFeedbackLw(null, mSafeMode |
| 2137 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 2138 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
Dianne Hackborn | 73b1ec8 | 2009-10-04 13:33:00 -0700 | [diff] [blame] | 2139 | if (mSafeMode) { |
| 2140 | Log.i(TAG, "SAFE MODE ENABLED (menu=" + menuState + " s=" + sState |
| 2141 | + " dpad=" + dpadState + " trackball=" + trackballState + ")"); |
| 2142 | } else { |
| 2143 | Log.i(TAG, "SAFE MODE not enabled"); |
| 2144 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2145 | return mSafeMode; |
| 2146 | } catch (RemoteException e) { |
| 2147 | // Doom! (it's also local) |
| 2148 | throw new RuntimeException("window manager dead"); |
| 2149 | } |
| 2150 | } |
| 2151 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 2152 | static long[] getLongIntArray(Resources r, int resid) { |
| 2153 | int[] ar = r.getIntArray(resid); |
| 2154 | if (ar == null) { |
| 2155 | return null; |
| 2156 | } |
| 2157 | long[] out = new long[ar.length]; |
| 2158 | for (int i=0; i<ar.length; i++) { |
| 2159 | out[i] = ar[i]; |
| 2160 | } |
| 2161 | return out; |
| 2162 | } |
| 2163 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2164 | /** {@inheritDoc} */ |
| 2165 | public void systemReady() { |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2166 | // tell the keyguard |
| 2167 | mKeyguardMediator.onSystemReady(); |
| 2168 | android.os.SystemProperties.set("dev.bootcomplete", "1"); |
| 2169 | synchronized (mLock) { |
| 2170 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2171 | mSystemReady = true; |
| 2172 | mHandler.post(new Runnable() { |
| 2173 | public void run() { |
| 2174 | updateSettings(); |
| 2175 | } |
| 2176 | }); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2177 | } |
| 2178 | } |
| 2179 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 2180 | /** {@inheritDoc} */ |
| 2181 | public void userActivity() { |
| 2182 | synchronized (mScreenLockTimeout) { |
| 2183 | if (mLockScreenTimerActive) { |
| 2184 | // reset the timer |
| 2185 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 2186 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 2187 | } |
| 2188 | } |
| 2189 | } |
| 2190 | |
| 2191 | Runnable mScreenLockTimeout = new Runnable() { |
| 2192 | public void run() { |
| 2193 | synchronized (this) { |
| 2194 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
| 2195 | mKeyguardMediator.doKeyguardTimeout(); |
| 2196 | mLockScreenTimerActive = false; |
| 2197 | } |
| 2198 | } |
| 2199 | }; |
| 2200 | |
| 2201 | private void updateLockScreenTimeout() { |
| 2202 | synchronized (mScreenLockTimeout) { |
| 2203 | boolean enable = (mAllowLockscreenWhenOn && mScreenOn && mKeyguardMediator.isSecure()); |
| 2204 | if (mLockScreenTimerActive != enable) { |
| 2205 | if (enable) { |
| 2206 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
| 2207 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 2208 | } else { |
| 2209 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 2210 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 2211 | } |
| 2212 | mLockScreenTimerActive = enable; |
| 2213 | } |
| 2214 | } |
| 2215 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2216 | |
| 2217 | /** {@inheritDoc} */ |
| 2218 | public void enableScreenAfterBoot() { |
| 2219 | readLidState(); |
Dianne Hackborn | 32bc91d | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 2220 | updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2221 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 2222 | |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 2223 | void updateRotation(int animFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2224 | mPowerManager.setKeyboardVisibility(mLidOpen); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2225 | int rotation = Surface.ROTATION_0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2226 | if (mLidOpen) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2227 | rotation = mLidOpenRotation; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 2228 | } else if (mUiMode == Configuration.UI_MODE_TYPE_CAR && mCarDockRotation >= 0) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2229 | rotation = mCarDockRotation; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 2230 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK && mDeskDockRotation >= 0) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2231 | rotation = mDeskDockRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2232 | } |
| 2233 | //if lid is closed orientation will be portrait |
| 2234 | try { |
| 2235 | //set orientation on WindowManager |
Dianne Hackborn | 32bc91d | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 2236 | mWindowManager.setRotation(rotation, true, |
| 2237 | mFancyRotationAnimation | animFlags); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2238 | } catch (RemoteException e) { |
| 2239 | // Ignore |
| 2240 | } |
| 2241 | } |
| 2242 | |
| 2243 | /** |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2244 | * Return an Intent to launch the currently active dock as home. Returns |
| 2245 | * null if the standard home should be launched. |
| 2246 | * @return |
| 2247 | */ |
| 2248 | Intent createHomeDockIntent() { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2249 | Intent intent; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 2250 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2251 | intent = mCarDockIntent; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 2252 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2253 | intent = mDeskDockIntent; |
| 2254 | } else { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2255 | return null; |
| 2256 | } |
| 2257 | |
| 2258 | ActivityInfo ai = intent.resolveActivityInfo( |
| 2259 | mContext.getPackageManager(), PackageManager.GET_META_DATA); |
| 2260 | if (ai == null) { |
| 2261 | return null; |
| 2262 | } |
| 2263 | |
| 2264 | if (ai.metaData != null && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 2265 | intent = new Intent(intent); |
| 2266 | intent.setClassName(ai.packageName, ai.name); |
| 2267 | return intent; |
| 2268 | } |
| 2269 | |
| 2270 | return null; |
| 2271 | } |
| 2272 | |
| 2273 | void startDockOrHome() { |
| 2274 | Intent dock = createHomeDockIntent(); |
| 2275 | if (dock != null) { |
| 2276 | try { |
| 2277 | mContext.startActivity(dock); |
| 2278 | return; |
| 2279 | } catch (ActivityNotFoundException e) { |
| 2280 | } |
| 2281 | } |
| 2282 | mContext.startActivity(mHomeIntent); |
| 2283 | } |
| 2284 | |
| 2285 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2286 | * goes to the home screen |
| 2287 | * @return whether it did anything |
| 2288 | */ |
| 2289 | boolean goHome() { |
| 2290 | if (false) { |
| 2291 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2292 | try { |
| 2293 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2294 | } catch (RemoteException e) { |
| 2295 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 2296 | sendCloseSystemWindows(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2297 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2298 | } else { |
| 2299 | // This code brings home to the front or, if it is already |
| 2300 | // at the front, puts the device to sleep. |
| 2301 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 2302 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 2303 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 2304 | Log.d(TAG, "UTS-TEST-MODE"); |
| 2305 | } else { |
| 2306 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2307 | sendCloseSystemWindows(); |
| 2308 | Intent dock = createHomeDockIntent(); |
| 2309 | if (dock != null) { |
| 2310 | int result = ActivityManagerNative.getDefault() |
| 2311 | .startActivity(null, dock, |
| 2312 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 2313 | null, 0, null, null, 0, true /* onlyIfNeeded*/, false); |
| 2314 | if (result == IActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 2315 | return false; |
| 2316 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2317 | } |
| 2318 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2319 | int result = ActivityManagerNative.getDefault() |
| 2320 | .startActivity(null, mHomeIntent, |
| 2321 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 2322 | null, 0, null, null, 0, true /* onlyIfNeeded*/, false); |
| 2323 | if (result == IActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 2324 | return false; |
| 2325 | } |
| 2326 | } catch (RemoteException ex) { |
| 2327 | // bummer, the activity manager, which is in this process, is dead |
| 2328 | } |
| 2329 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2330 | return true; |
| 2331 | } |
| 2332 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2333 | public void setCurrentOrientationLw(int newOrientation) { |
| 2334 | synchronized (mLock) { |
| 2335 | if (newOrientation != mCurrentAppOrientation) { |
| 2336 | mCurrentAppOrientation = newOrientation; |
| 2337 | updateOrientationListenerLp(); |
| 2338 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2339 | } |
| 2340 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 2341 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2342 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Jim Miller | 89b1722 | 2009-10-27 14:54:09 -0700 | [diff] [blame] | 2343 | final boolean hapticsDisabled = Settings.System.getInt(mContext.getContentResolver(), |
| 2344 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) == 0; |
Dianne Hackborn | 9dc06cc | 2009-11-17 18:19:23 -0800 | [diff] [blame] | 2345 | if (!always && (hapticsDisabled || mKeyguardMediator.isShowingAndNotHidden())) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2346 | return false; |
| 2347 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 2348 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2349 | switch (effectId) { |
| 2350 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 2351 | pattern = mLongPressVibePattern; |
| 2352 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2353 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 2354 | pattern = mVirtualKeyVibePattern; |
| 2355 | break; |
| 2356 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 2357 | pattern = mKeyboardTapVibePattern; |
| 2358 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2359 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 2360 | pattern = mSafeModeDisabledVibePattern; |
| 2361 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2362 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 2363 | pattern = mSafeModeEnabledVibePattern; |
| 2364 | break; |
Adam Powell | 9d86faf | 2010-02-10 11:39:57 -0800 | [diff] [blame] | 2365 | case HapticFeedbackConstants.SCROLL_BARRIER: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 2366 | pattern = mScrollBarrierVibePattern; |
| 2367 | break; |
| 2368 | default: |
| 2369 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2370 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 2371 | if (pattern.length == 1) { |
| 2372 | // One-shot vibration |
| 2373 | mVibrator.vibrate(pattern[0]); |
| 2374 | } else { |
| 2375 | // Pattern vibration |
| 2376 | mVibrator.vibrate(pattern, -1); |
| 2377 | } |
| 2378 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2379 | } |
| 2380 | |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 2381 | public void keyFeedbackFromInput(KeyEvent event) { |
| 2382 | if (event.getAction() == KeyEvent.ACTION_DOWN |
| 2383 | && (event.getFlags()&KeyEvent.FLAG_VIRTUAL_HARD_KEY) != 0) { |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2384 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 2385 | } |
| 2386 | } |
| 2387 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2388 | public void screenOnStoppedLw() { |
Dianne Hackborn | 9dc06cc | 2009-11-17 18:19:23 -0800 | [diff] [blame] | 2389 | if (!mKeyguardMediator.isShowingAndNotHidden() && mPowerManager.isScreenOn()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2390 | long curTime = SystemClock.uptimeMillis(); |
| 2391 | mPowerManager.userActivity(curTime, false, LocalPowerManager.OTHER_EVENT); |
| 2392 | } |
| 2393 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 2394 | |
| 2395 | public boolean allowKeyRepeat() { |
| 2396 | // disable key repeat when screen is off |
| 2397 | return mScreenOn; |
| 2398 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2399 | } |