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; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 22 | import android.app.IUiModeManager; |
| 23 | import android.app.UiModeManager; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 24 | import android.content.ActivityNotFoundException; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 25 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 26 | import android.content.ContentResolver; |
| 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 29 | import android.content.IntentFilter; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 30 | import android.content.pm.ActivityInfo; |
| 31 | import android.content.pm.PackageManager; |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 32 | import android.content.res.CompatibilityInfo; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 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; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 38 | import android.os.Binder; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 39 | import android.os.Handler; |
| 40 | import android.os.IBinder; |
| 41 | import android.os.LocalPowerManager; |
| 42 | import android.os.PowerManager; |
| 43 | import android.os.RemoteException; |
| 44 | import android.os.ServiceManager; |
| 45 | import android.os.SystemClock; |
| 46 | import android.os.SystemProperties; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 47 | import android.os.UEventObserver; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 48 | import android.os.Vibrator; |
| 49 | import android.provider.Settings; |
| 50 | |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 51 | import com.android.internal.R; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 52 | import com.android.internal.app.ShutdownThread; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 53 | import com.android.internal.policy.PolicyManager; |
Joe Onorato | 0cbda99 | 2010-05-02 16:28:15 -0700 | [diff] [blame] | 54 | import com.android.internal.statusbar.IStatusBarService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 55 | import com.android.internal.telephony.ITelephony; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 56 | import com.android.internal.view.BaseInputHandler; |
Dianne Hackborn | 6019c9d | 2010-03-01 21:43:11 -0800 | [diff] [blame] | 57 | import com.android.internal.widget.PointerLocationView; |
| 58 | |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 59 | import android.util.DisplayMetrics; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 60 | import android.util.EventLog; |
| 61 | import android.util.Log; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 62 | import android.util.Slog; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 63 | import android.view.Gravity; |
| 64 | import android.view.HapticFeedbackConstants; |
| 65 | import android.view.IWindowManager; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 66 | import android.view.InputChannel; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 67 | import android.view.InputDevice; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 68 | import android.view.InputQueue; |
| 69 | import android.view.InputHandler; |
Jeff Brown | 6b53e8d | 2010-11-10 16:03:06 -0800 | [diff] [blame] | 70 | import android.view.KeyCharacterMap; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 71 | import android.view.KeyEvent; |
| 72 | import android.view.MotionEvent; |
| 73 | import android.view.WindowOrientationListener; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 74 | import android.view.Surface; |
| 75 | import android.view.View; |
| 76 | import android.view.ViewConfiguration; |
| 77 | import android.view.Window; |
| 78 | import android.view.WindowManager; |
| 79 | import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; |
| 80 | import static android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN; |
| 81 | import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN; |
| 82 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
| 83 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR; |
| 84 | import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 85 | import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 86 | import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD; |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 87 | 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] | 88 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST; |
| 89 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 90 | import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 91 | import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW; |
| 92 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 93 | 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] | 94 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; |
| 95 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL; |
| 96 | import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 97 | import static android.view.WindowManager.LayoutParams.TYPE_DRAG; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 98 | import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD; |
| 99 | import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG; |
| 100 | import static android.view.WindowManager.LayoutParams.TYPE_PHONE; |
| 101 | import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE; |
| 102 | import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR; |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 103 | import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 104 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR; |
| 105 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 106 | import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL; |
Dianne Hackborn | 6a294ce | 2009-12-03 11:37:44 -0800 | [diff] [blame] | 107 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 108 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; |
| 109 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR; |
| 110 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD; |
| 111 | import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG; |
| 112 | import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY; |
| 113 | import static android.view.WindowManager.LayoutParams.TYPE_TOAST; |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 114 | import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 115 | import static android.view.WindowManager.LayoutParams.TYPE_POINTER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 116 | import android.view.WindowManagerImpl; |
| 117 | import android.view.WindowManagerPolicy; |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 118 | import android.view.KeyCharacterMap.FallbackAction; |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 119 | import android.view.animation.Animation; |
| 120 | import android.view.animation.AnimationUtils; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 121 | import android.media.IAudioService; |
| 122 | import android.media.AudioManager; |
| 123 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 124 | import java.io.File; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 125 | import java.io.FileDescriptor; |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 126 | import java.io.FileReader; |
| 127 | import java.io.IOException; |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 128 | import java.io.PrintWriter; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 129 | import java.util.ArrayList; |
| 130 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 131 | /** |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 132 | * WindowManagerPolicy implementation for the Android phone UI. This |
| 133 | * introduces a new method suffix, Lp, for an internal lock of the |
| 134 | * PhoneWindowManager. This is used to protect some internal state, and |
| 135 | * can be acquired with either thw Lw and Li lock held, so has the restrictions |
| 136 | * of both of those when held. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 137 | */ |
| 138 | public class PhoneWindowManager implements WindowManagerPolicy { |
| 139 | static final String TAG = "WindowManager"; |
| 140 | static final boolean DEBUG = false; |
Dianne Hackborn | 2973568 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 141 | static final boolean localLOGV = false; |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 142 | static final boolean DEBUG_LAYOUT = false; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 143 | static final boolean DEBUG_FALLBACK = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 144 | static final boolean SHOW_STARTING_ANIMATIONS = true; |
| 145 | static final boolean SHOW_PROCESSES_ON_ALT_MENU = false; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 146 | |
| 147 | static final int LONG_PRESS_POWER_NOTHING = 0; |
| 148 | static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1; |
| 149 | static final int LONG_PRESS_POWER_SHUT_OFF = 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 150 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 151 | static final int LONG_PRESS_HOME_NOTHING = 0; |
| 152 | static final int LONG_PRESS_HOME_RECENT_DIALOG = 1; |
| 153 | static final int LONG_PRESS_HOME_RECENT_ACTIVITY = 2; |
| 154 | |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 155 | // wallpaper is at the bottom, though the window manager may move it. |
Dianne Hackborn | 3c3bd44 | 2009-08-19 17:09:46 -0700 | [diff] [blame] | 156 | static final int WALLPAPER_LAYER = 2; |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 157 | static final int APPLICATION_LAYER = 2; |
| 158 | static final int PHONE_LAYER = 3; |
| 159 | static final int SEARCH_BAR_LAYER = 4; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 160 | static final int STATUS_BAR_SUB_PANEL_LAYER = 5; |
Dianne Hackborn | 6a294ce | 2009-12-03 11:37:44 -0800 | [diff] [blame] | 161 | static final int SYSTEM_DIALOG_LAYER = 6; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 162 | // toasts and the plugged-in battery thing |
Dianne Hackborn | 6a294ce | 2009-12-03 11:37:44 -0800 | [diff] [blame] | 163 | static final int TOAST_LAYER = 7; |
| 164 | static final int STATUS_BAR_LAYER = 8; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 165 | static final int STATUS_BAR_PANEL_LAYER = 9; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 166 | // SIM errors and unlock. Not sure if this really should be in a high layer. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 167 | static final int PRIORITY_PHONE_LAYER = 10; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 168 | // like the ANR / app crashed dialogs |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 169 | static final int SYSTEM_ALERT_LAYER = 11; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 170 | // system-level error dialogs |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 171 | static final int SYSTEM_ERROR_LAYER = 12; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 172 | // on-screen keyboards and other such input method user interfaces go here. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 173 | static final int INPUT_METHOD_LAYER = 13; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 174 | // on-screen keyboards and other such input method user interfaces go here. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 175 | static final int INPUT_METHOD_DIALOG_LAYER = 14; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 176 | // the keyguard; nothing on top of these can take focus, since they are |
| 177 | // responsible for power management when displayed. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 178 | static final int KEYGUARD_LAYER = 15; |
| 179 | static final int KEYGUARD_DIALOG_LAYER = 16; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 180 | // the drag layer: input for drag-and-drop is associated with this window, |
| 181 | // which sits above all other focusable windows |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 182 | static final int DRAG_LAYER = 17; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 183 | // things in here CAN NOT take focus, but are shown on top of everything else. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 184 | static final int SYSTEM_OVERLAY_LAYER = 18; |
| 185 | static final int SECURE_SYSTEM_OVERLAY_LAYER = 19; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 186 | // the (mouse) pointer layer |
| 187 | static final int POINTER_LAYER = 20; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 188 | |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 189 | static final int APPLICATION_MEDIA_SUBLAYER = -2; |
| 190 | static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 191 | static final int APPLICATION_PANEL_SUBLAYER = 1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 192 | static final int APPLICATION_SUB_PANEL_SUBLAYER = 2; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 193 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 194 | static public final String SYSTEM_DIALOG_REASON_KEY = "reason"; |
| 195 | static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions"; |
| 196 | static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps"; |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 197 | 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] | 198 | |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 199 | // Useful scan codes. |
| 200 | private static final int SW_LID = 0x00; |
| 201 | private static final int BTN_MOUSE = 0x110; |
| 202 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 203 | final Object mLock = new Object(); |
| 204 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 205 | Context mContext; |
| 206 | IWindowManager mWindowManager; |
| 207 | LocalPowerManager mPowerManager; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 208 | IStatusBarService mStatusBarService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 209 | Vibrator mVibrator; // Vibrator for giving feedback of orientation changes |
| 210 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 211 | // Vibrator pattern for haptic feedback of a long press. |
| 212 | long[] mLongPressVibePattern; |
| 213 | |
| 214 | // Vibrator pattern for haptic feedback of virtual key press. |
| 215 | long[] mVirtualKeyVibePattern; |
| 216 | |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 217 | // Vibrator pattern for a short vibration. |
| 218 | long[] mKeyboardTapVibePattern; |
| 219 | |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 220 | // Vibrator pattern for haptic feedback during boot when safe mode is disabled. |
| 221 | long[] mSafeModeDisabledVibePattern; |
| 222 | |
| 223 | // Vibrator pattern for haptic feedback during boot when safe mode is enabled. |
| 224 | long[] mSafeModeEnabledVibePattern; |
Romain Guy | 8154cd3 | 2010-03-29 14:41:15 -0700 | [diff] [blame] | 225 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 226 | /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */ |
| 227 | boolean mEnableShiftMenuBugReports = false; |
| 228 | |
| 229 | boolean mSafeMode; |
| 230 | WindowState mStatusBar = null; |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 231 | boolean mStatusBarCanHide; |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 232 | int mStatusBarHeight; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 233 | final ArrayList<WindowState> mStatusBarPanels = new ArrayList<WindowState>(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 234 | WindowState mKeyguard = null; |
| 235 | KeyguardViewMediator mKeyguardMediator; |
| 236 | GlobalActions mGlobalActions; |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 237 | volatile boolean mPowerKeyHandled; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 238 | RecentApplicationsDialog mRecentAppsDialog; |
| 239 | Handler mHandler; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 240 | |
| 241 | private static final int LID_ABSENT = -1; |
| 242 | private static final int LID_CLOSED = 0; |
| 243 | private static final int LID_OPEN = 1; |
| 244 | |
| 245 | int mLidOpen = LID_ABSENT; |
| 246 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 247 | boolean mSystemReady; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 248 | boolean mHdmiPlugged; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 249 | int mUiMode = Configuration.UI_MODE_TYPE_NORMAL; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 250 | int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 251 | int mLidOpenRotation; |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 252 | int mCarDockRotation; |
| 253 | int mDeskDockRotation; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 254 | |
| 255 | int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE; |
| 256 | int mUserRotation = Surface.ROTATION_0; |
| 257 | |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 258 | boolean mAllowAllRotations; |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 259 | boolean mCarDockEnablesAccelerometer; |
| 260 | boolean mDeskDockEnablesAccelerometer; |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 261 | int mLidKeyboardAccessibility; |
| 262 | int mLidNavigationAccessibility; |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 263 | int mLongPressOnPowerBehavior = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 264 | boolean mScreenOn = false; |
| 265 | boolean mOrientationSensorEnabled = false; |
| 266 | int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; |
| 267 | static final int DEFAULT_ACCELEROMETER_ROTATION = 0; |
| 268 | int mAccelerometerDefault = DEFAULT_ACCELEROMETER_ROTATION; |
| 269 | boolean mHasSoftInput = false; |
| 270 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 271 | int mPointerLocationMode = 0; |
| 272 | PointerLocationView mPointerLocationView = null; |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 273 | InputChannel mPointerLocationInputChannel; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 274 | |
| 275 | // The last window we were told about in focusChanged. |
| 276 | WindowState mFocusedWindow; |
| 277 | |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 278 | private final InputHandler mPointerLocationInputHandler = new BaseInputHandler() { |
| 279 | @Override |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 280 | public void handleMotion(MotionEvent event, InputQueue.FinishedCallback finishedCallback) { |
| 281 | boolean handled = false; |
| 282 | try { |
| 283 | if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) { |
| 284 | synchronized (mLock) { |
| 285 | if (mPointerLocationView != null) { |
Jeff Brown | 33bbfd2 | 2011-02-24 20:55:35 -0800 | [diff] [blame] | 286 | mPointerLocationView.addPointerEvent(event); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 287 | handled = true; |
| 288 | } |
| 289 | } |
Jeff Brown | 93ed4e3 | 2010-09-23 13:51:48 -0700 | [diff] [blame] | 290 | } |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 291 | } finally { |
| 292 | finishedCallback.finished(handled); |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | }; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 296 | |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 297 | // The current size of the screen; really; (ir)regardless of whether the status |
| 298 | // bar can be hidden or not |
| 299 | int mUnrestrictedScreenLeft, mUnrestrictedScreenTop; |
| 300 | int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight; |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 301 | // The current size of the screen; these may be different than (0,0)-(dw,dh) |
| 302 | // if the status bar can't be hidden; in that case it effectively carves out |
| 303 | // that area of the display from all other windows. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 304 | int mRestrictedScreenLeft, mRestrictedScreenTop; |
| 305 | int mRestrictedScreenWidth, mRestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 306 | // During layout, the current screen borders with all outer decoration |
| 307 | // (status bar, input method dock) accounted for. |
| 308 | int mCurLeft, mCurTop, mCurRight, mCurBottom; |
| 309 | // During layout, the frame in which content should be displayed |
| 310 | // to the user, accounting for all screen decoration except for any |
| 311 | // space they deem as available for other content. This is usually |
| 312 | // the same as mCur*, but may be larger if the screen decor has supplied |
| 313 | // content insets. |
| 314 | int mContentLeft, mContentTop, mContentRight, mContentBottom; |
Dianne Hackborn | 8e11ef0 | 2010-11-18 19:47:42 -0800 | [diff] [blame] | 315 | // During layout, the current screen borders along which input method |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 316 | // windows are placed. |
| 317 | int mDockLeft, mDockTop, mDockRight, mDockBottom; |
| 318 | // During layout, the layer at which the doc window is placed. |
| 319 | int mDockLayer; |
| 320 | |
| 321 | static final Rect mTmpParentFrame = new Rect(); |
| 322 | static final Rect mTmpDisplayFrame = new Rect(); |
| 323 | static final Rect mTmpContentFrame = new Rect(); |
| 324 | static final Rect mTmpVisibleFrame = new Rect(); |
| 325 | |
| 326 | WindowState mTopFullscreenOpaqueWindowState; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 327 | boolean mTopIsFullscreen; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 328 | boolean mForceStatusBar; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 329 | boolean mHideLockScreen; |
| 330 | boolean mDismissKeyguard; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 331 | boolean mHomePressed; |
| 332 | Intent mHomeIntent; |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 333 | Intent mCarDockIntent; |
| 334 | Intent mDeskDockIntent; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 335 | int mShortcutKeyPressed = -1; |
| 336 | boolean mConsumeShortcutKeyUp; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 337 | boolean mShowMenuKey = false; // track FLAG_NEEDS_MENU_KEY on frontmost window |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 338 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 339 | // support for activating the lock screen while the screen is on |
| 340 | boolean mAllowLockscreenWhenOn; |
| 341 | int mLockScreenTimeout; |
| 342 | boolean mLockScreenTimerActive; |
| 343 | |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 344 | // 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] | 345 | int mEndcallBehavior; |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 346 | |
| 347 | // Behavior of POWER button while in-call and screen on. |
| 348 | // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.) |
| 349 | int mIncallPowerBehavior; |
| 350 | |
Dianne Hackborn | 2973568 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 351 | int mLandscapeRotation = 0; // default landscape rotation |
| 352 | int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation |
| 353 | int mPortraitRotation = 0; // default portrait rotation |
| 354 | int mUpsideDownRotation = 0; // "other" portrait rotation |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 355 | |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 356 | // Nothing to see here, move along... |
| 357 | int mFancyRotationAnimation; |
Jim Miller | ee969aa | 2010-08-26 20:17:43 -0700 | [diff] [blame] | 358 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 359 | // What we do when the user long presses on home |
| 360 | private int mLongPressOnHomeBehavior = -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 361 | |
| 362 | ShortcutManager mShortcutManager; |
| 363 | PowerManager.WakeLock mBroadcastWakeLock; |
| 364 | |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 365 | final KeyCharacterMap.FallbackAction mFallbackAction = new KeyCharacterMap.FallbackAction(); |
| 366 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 367 | private UEventObserver mHDMIObserver = new UEventObserver() { |
| 368 | @Override |
| 369 | public void onUEvent(UEventObserver.UEvent event) { |
| 370 | setHdmiPlugged("1".equals(event.get("SWITCH_STATE"))); |
| 371 | } |
| 372 | }; |
| 373 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 374 | class SettingsObserver extends ContentObserver { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 375 | SettingsObserver(Handler handler) { |
| 376 | super(handler); |
| 377 | } |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 378 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 379 | void observe() { |
| 380 | ContentResolver resolver = mContext.getContentResolver(); |
| 381 | resolver.registerContentObserver(Settings.System.getUriFor( |
| 382 | Settings.System.END_BUTTON_BEHAVIOR), false, this); |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 383 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 384 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 385 | resolver.registerContentObserver(Settings.System.getUriFor( |
| 386 | Settings.System.ACCELEROMETER_ROTATION), false, this); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 387 | resolver.registerContentObserver(Settings.System.getUriFor( |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 388 | Settings.System.USER_ROTATION), false, this); |
| 389 | resolver.registerContentObserver(Settings.System.getUriFor( |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 390 | Settings.System.SCREEN_OFF_TIMEOUT), false, this); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 391 | resolver.registerContentObserver(Settings.System.getUriFor( |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 392 | Settings.System.WINDOW_ORIENTATION_LISTENER_LOG), false, this); |
| 393 | resolver.registerContentObserver(Settings.System.getUriFor( |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 394 | Settings.System.POINTER_LOCATION), false, this); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 395 | resolver.registerContentObserver(Settings.Secure.getUriFor( |
| 396 | Settings.Secure.DEFAULT_INPUT_METHOD), false, this); |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 397 | resolver.registerContentObserver(Settings.System.getUriFor( |
| 398 | "fancy_rotation_anim"), false, this); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 399 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | @Override public void onChange(boolean selfChange) { |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 403 | updateSettings(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 404 | try { |
Dianne Hackborn | 32bc91d | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 405 | mWindowManager.setRotation(USE_LAST_ROTATION, false, |
| 406 | mFancyRotationAnimation); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 407 | } catch (RemoteException e) { |
| 408 | // Ignore |
| 409 | } |
| 410 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | class MyOrientationListener extends WindowOrientationListener { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 414 | MyOrientationListener(Context context) { |
| 415 | super(context); |
| 416 | } |
| 417 | |
| 418 | @Override |
The Android Open Source Project | d06b097 | 2009-03-13 13:04:23 -0700 | [diff] [blame] | 419 | public void onOrientationChanged(int rotation) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 420 | // Send updates based on orientation value |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 421 | if (localLOGV) Log.v(TAG, "onOrientationChanged, rotation changed to " +rotation); |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 422 | try { |
Dianne Hackborn | 32bc91d | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 423 | mWindowManager.setRotation(rotation, false, |
| 424 | mFancyRotationAnimation); |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 425 | } catch (RemoteException e) { |
| 426 | // Ignore |
Wink Saville | 37c124c | 2009-04-02 01:37:02 -0700 | [diff] [blame] | 427 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | } |
| 431 | MyOrientationListener mOrientationListener; |
| 432 | |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 433 | boolean useSensorForOrientationLp(int appOrientation) { |
Joe Onorato | 1b58b3e | 2009-09-22 16:44:16 -0700 | [diff] [blame] | 434 | // The app says use the sensor. |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 435 | if (appOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 436 | || appOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 437 | || appOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE |
| 438 | || appOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 439 | return true; |
| 440 | } |
Joe Onorato | 1b58b3e | 2009-09-22 16:44:16 -0700 | [diff] [blame] | 441 | // The user preference says we can rotate, and the app is willing to rotate. |
| 442 | if (mAccelerometerDefault != 0 && |
| 443 | (appOrientation == ActivityInfo.SCREEN_ORIENTATION_USER |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 444 | || appOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 445 | return true; |
| 446 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 447 | // We're in a dock that has a rotation affinity, and the app is willing to rotate. |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 448 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) |
| 449 | || (mDeskDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_DESK)) { |
Joe Onorato | 1b58b3e | 2009-09-22 16:44:16 -0700 | [diff] [blame] | 450 | // Note we override the nosensor flag here. |
| 451 | if (appOrientation == ActivityInfo.SCREEN_ORIENTATION_USER |
| 452 | || appOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 453 | || appOrientation == ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) { |
Joe Onorato | 1b58b3e | 2009-09-22 16:44:16 -0700 | [diff] [blame] | 454 | return true; |
| 455 | } |
| 456 | } |
| 457 | // Else, don't use the sensor. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 458 | return false; |
| 459 | } |
| 460 | |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 461 | /* |
| 462 | * We always let the sensor be switched on by default except when |
| 463 | * the user has explicitly disabled sensor based rotation or when the |
| 464 | * screen is switched off. |
| 465 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 466 | boolean needSensorRunningLp() { |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 467 | if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR |
| 468 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR |
| 469 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT |
| 470 | || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 471 | // If the application has explicitly requested to follow the |
| 472 | // orientation, then we need to turn the sensor or. |
| 473 | return true; |
| 474 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 475 | if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || |
| 476 | (mDeskDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_DESK)) { |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 477 | // enable accelerometer if we are docked in a dock that enables accelerometer |
| 478 | // orientation management, |
| 479 | return true; |
| 480 | } |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 481 | if (mAccelerometerDefault == 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 482 | // If the setting for using the sensor by default is enabled, then |
| 483 | // we will always leave it on. Note that the user could go to |
| 484 | // a window that forces an orientation that does not use the |
| 485 | // sensor and in theory we could turn it off... however, when next |
| 486 | // turning it on we won't have a good value for the current |
| 487 | // orientation for a little bit, which can cause orientation |
| 488 | // changes to lag, so we'd like to keep it always on. (It will |
| 489 | // still be turned off when the screen is off.) |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 490 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 491 | } |
Suchi Amalapurapu | a9e1b16 | 2009-03-24 22:24:47 -0700 | [diff] [blame] | 492 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | /* |
| 496 | * Various use cases for invoking this function |
| 497 | * screen turning off, should always disable listeners if already enabled |
| 498 | * screen turned on and current app has sensor based orientation, enable listeners |
| 499 | * if not already enabled |
| 500 | * screen turned on and current app does not have sensor orientation, disable listeners if |
| 501 | * already enabled |
| 502 | * screen turning on and current app has sensor based orientation, enable listeners if needed |
| 503 | * screen turning on and current app has nosensor based orientation, do nothing |
| 504 | */ |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 505 | void updateOrientationListenerLp() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 506 | if (!mOrientationListener.canDetectOrientation()) { |
| 507 | // If sensor is turned off or nonexistent for some reason |
| 508 | return; |
| 509 | } |
| 510 | //Could have been invoked due to screen turning on or off or |
| 511 | //change of the currently visible window's orientation |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 512 | if (localLOGV) Log.v(TAG, "Screen status="+mScreenOn+ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 513 | ", current orientation="+mCurrentAppOrientation+ |
| 514 | ", SensorEnabled="+mOrientationSensorEnabled); |
| 515 | boolean disable = true; |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 516 | if (mScreenOn) { |
| 517 | if (needSensorRunningLp()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 518 | disable = false; |
| 519 | //enable listener if not already enabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 520 | if (!mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 521 | mOrientationListener.enable(); |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 522 | if(localLOGV) Log.v(TAG, "Enabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 523 | mOrientationSensorEnabled = true; |
| 524 | } |
| 525 | } |
| 526 | } |
| 527 | //check if sensors need to be disabled |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 528 | if (disable && mOrientationSensorEnabled) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 529 | mOrientationListener.disable(); |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 530 | if(localLOGV) Log.v(TAG, "Disabling listeners"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 531 | mOrientationSensorEnabled = false; |
| 532 | } |
| 533 | } |
| 534 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 535 | private void interceptPowerKeyDown(boolean handled) { |
| 536 | mPowerKeyHandled = handled; |
| 537 | if (!handled) { |
| 538 | mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout()); |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | private boolean interceptPowerKeyUp(boolean canceled) { |
| 543 | if (!mPowerKeyHandled) { |
| 544 | mHandler.removeCallbacks(mPowerLongPress); |
| 545 | return !canceled; |
| 546 | } else { |
| 547 | mPowerKeyHandled = true; |
| 548 | return false; |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | private final Runnable mPowerLongPress = new Runnable() { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 553 | public void run() { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 554 | if (!mPowerKeyHandled) { |
| 555 | // The context isn't read |
| 556 | if (mLongPressOnPowerBehavior < 0) { |
| 557 | mLongPressOnPowerBehavior = mContext.getResources().getInteger( |
| 558 | com.android.internal.R.integer.config_longPressOnPowerBehavior); |
| 559 | } |
| 560 | switch (mLongPressOnPowerBehavior) { |
| 561 | case LONG_PRESS_POWER_NOTHING: |
| 562 | break; |
| 563 | case LONG_PRESS_POWER_GLOBAL_ACTIONS: |
| 564 | mPowerKeyHandled = true; |
| 565 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 566 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 567 | showGlobalActionsDialog(); |
| 568 | break; |
| 569 | case LONG_PRESS_POWER_SHUT_OFF: |
| 570 | mPowerKeyHandled = true; |
| 571 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 572 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS); |
| 573 | ShutdownThread.shutdown(mContext, true); |
| 574 | break; |
| 575 | } |
Joe Onorato | d208e70 | 2010-10-08 16:22:43 -0400 | [diff] [blame] | 576 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 577 | } |
| 578 | }; |
| 579 | |
| 580 | void showGlobalActionsDialog() { |
| 581 | if (mGlobalActions == null) { |
| 582 | mGlobalActions = new GlobalActions(mContext); |
| 583 | } |
Dianne Hackborn | 9dc06cc | 2009-11-17 18:19:23 -0800 | [diff] [blame] | 584 | final boolean keyguardShowing = mKeyguardMediator.isShowingAndNotHidden(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 585 | mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned()); |
| 586 | if (keyguardShowing) { |
| 587 | // since it took two seconds of long press to bring this up, |
| 588 | // poke the wake lock so they have some time to see the dialog. |
| 589 | mKeyguardMediator.pokeWakelock(); |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | boolean isDeviceProvisioned() { |
| 594 | return Settings.Secure.getInt( |
| 595 | mContext.getContentResolver(), Settings.Secure.DEVICE_PROVISIONED, 0) != 0; |
| 596 | } |
| 597 | |
| 598 | /** |
| 599 | * When a home-key longpress expires, close other system windows and launch the recent apps |
| 600 | */ |
| 601 | Runnable mHomeLongPress = new Runnable() { |
| 602 | public void run() { |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 603 | handleLongPressOnHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 604 | } |
| 605 | }; |
| 606 | |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 607 | private void handleLongPressOnHome() { |
Jim Miller | ee969aa | 2010-08-26 20:17:43 -0700 | [diff] [blame] | 608 | // We can't initialize this in init() since the configuration hasn't been loaded yet. |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 609 | if (mLongPressOnHomeBehavior < 0) { |
| 610 | mLongPressOnHomeBehavior |
Joe Onorato | 50262e5 | 2010-11-26 14:04:54 -0800 | [diff] [blame] | 611 | = mContext.getResources().getInteger(R.integer.config_longPressOnHomeBehavior); |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 612 | if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING || |
| 613 | mLongPressOnHomeBehavior > LONG_PRESS_HOME_RECENT_ACTIVITY) { |
| 614 | mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING; |
| 615 | } |
| 616 | } |
| 617 | |
| 618 | if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) { |
| 619 | performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false); |
| 620 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 621 | |
| 622 | // Eat the longpress so it won't dismiss the recent apps dialog when |
| 623 | // the user lets go of the home key |
| 624 | mHomePressed = false; |
Jim Miller | ee969aa | 2010-08-26 20:17:43 -0700 | [diff] [blame] | 625 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 626 | |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 627 | if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_DIALOG) { |
Jeff Brown | d0132e8 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 628 | showOrHideRecentAppsDialog(0, true /*dismissIfShown*/); |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 629 | } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_ACTIVITY) { |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 630 | try { |
Jim Miller | ee969aa | 2010-08-26 20:17:43 -0700 | [diff] [blame] | 631 | Intent intent = new Intent(); |
| 632 | intent.setClassName("com.android.systemui", |
Joe Onorato | 46b0d68 | 2010-11-22 17:37:27 -0800 | [diff] [blame] | 633 | "com.android.systemui.recent.RecentApplicationsActivity"); |
Jim Miller | ee969aa | 2010-08-26 20:17:43 -0700 | [diff] [blame] | 634 | intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 635 | | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); |
| 636 | mContext.startActivity(intent); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 637 | return; |
| 638 | } catch (ActivityNotFoundException e) { |
| 639 | Log.e(TAG, "Failed to launch RecentAppsIntent", e); |
| 640 | } |
| 641 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 642 | } |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 643 | |
| 644 | /** |
Jeff Brown | d0132e8 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 645 | * Create (if necessary) and launch the recent apps dialog, or hide it if it is |
| 646 | * already shown. |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 647 | */ |
Jeff Brown | d0132e8 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 648 | void showOrHideRecentAppsDialog(final int heldModifiers, final boolean dismissIfShown) { |
Jeff Brown | 524ee64 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 649 | mHandler.post(new Runnable() { |
| 650 | @Override |
| 651 | public void run() { |
| 652 | if (mRecentAppsDialog == null) { |
Jeff Brown | d0132e8 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 653 | mRecentAppsDialog = new RecentApplicationsDialog(mContext); |
Jeff Brown | 524ee64 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 654 | } |
Jeff Brown | d0132e8 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 655 | if (mRecentAppsDialog.isShowing()) { |
| 656 | if (dismissIfShown) { |
| 657 | mRecentAppsDialog.dismiss(); |
| 658 | } |
| 659 | } else { |
| 660 | mRecentAppsDialog.setHeldModifiers(heldModifiers); |
| 661 | mRecentAppsDialog.show(); |
| 662 | } |
Jeff Brown | 524ee64 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 663 | } |
| 664 | }); |
Patrick Dubroy | ece9452 | 2011-02-23 18:35:01 -0800 | [diff] [blame] | 665 | } |
Jeff Brown | 524ee64 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 666 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 667 | /** {@inheritDoc} */ |
| 668 | public void init(Context context, IWindowManager windowManager, |
| 669 | LocalPowerManager powerManager) { |
| 670 | mContext = context; |
| 671 | mWindowManager = windowManager; |
| 672 | mPowerManager = powerManager; |
| 673 | mKeyguardMediator = new KeyguardViewMediator(context, this, powerManager); |
| 674 | mHandler = new Handler(); |
| 675 | mOrientationListener = new MyOrientationListener(mContext); |
| 676 | SettingsObserver settingsObserver = new SettingsObserver(mHandler); |
| 677 | settingsObserver.observe(); |
| 678 | mShortcutManager = new ShortcutManager(context, mHandler); |
| 679 | mShortcutManager.observe(); |
| 680 | mHomeIntent = new Intent(Intent.ACTION_MAIN, null); |
| 681 | mHomeIntent.addCategory(Intent.CATEGORY_HOME); |
| 682 | mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 683 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 684 | mCarDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 685 | mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK); |
| 686 | mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 687 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
| 688 | mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null); |
| 689 | mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK); |
| 690 | mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
| 691 | | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); |
Jim Miller | e6ad1a8 | 2010-08-20 19:25:39 -0700 | [diff] [blame] | 692 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 693 | PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); |
| 694 | mBroadcastWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, |
| 695 | "PhoneWindowManager.mBroadcastWakeLock"); |
| 696 | mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 697 | mLidOpenRotation = readRotation( |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 698 | com.android.internal.R.integer.config_lidOpenRotation); |
| 699 | mCarDockRotation = readRotation( |
| 700 | com.android.internal.R.integer.config_carDockRotation); |
| 701 | mDeskDockRotation = readRotation( |
| 702 | com.android.internal.R.integer.config_deskDockRotation); |
Dianne Hackborn | a111187 | 2010-11-23 20:55:11 -0800 | [diff] [blame] | 703 | mAllowAllRotations = mContext.getResources().getBoolean( |
| 704 | com.android.internal.R.bool.config_allowAllRotations); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 705 | mCarDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 706 | com.android.internal.R.bool.config_carDockEnablesAccelerometer); |
| 707 | mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean( |
| 708 | com.android.internal.R.bool.config_deskDockEnablesAccelerometer); |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 709 | mLidKeyboardAccessibility = mContext.getResources().getInteger( |
| 710 | com.android.internal.R.integer.config_lidKeyboardAccessibility); |
| 711 | mLidNavigationAccessibility = mContext.getResources().getInteger( |
| 712 | com.android.internal.R.integer.config_lidNavigationAccessibility); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 713 | // register for dock events |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 714 | IntentFilter filter = new IntentFilter(); |
| 715 | filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE); |
| 716 | filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE); |
| 717 | filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE); |
| 718 | filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 719 | filter.addAction(Intent.ACTION_DOCK_EVENT); |
| 720 | Intent intent = context.registerReceiver(mDockReceiver, filter); |
| 721 | if (intent != null) { |
| 722 | // Retrieve current sticky dock event broadcast. |
| 723 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 724 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 725 | } |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 726 | mVibrator = new Vibrator(); |
| 727 | mLongPressVibePattern = getLongIntArray(mContext.getResources(), |
| 728 | com.android.internal.R.array.config_longPressVibePattern); |
| 729 | mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(), |
| 730 | com.android.internal.R.array.config_virtualKeyVibePattern); |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 731 | mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(), |
| 732 | com.android.internal.R.array.config_keyboardTapVibePattern); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 733 | mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(), |
| 734 | com.android.internal.R.array.config_safeModeDisabledVibePattern); |
| 735 | mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(), |
| 736 | com.android.internal.R.array.config_safeModeEnabledVibePattern); |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 737 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 738 | // watch for HDMI plug messages if the hdmi switch exists |
| 739 | if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) { |
| 740 | mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi"); |
| 741 | } |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 742 | mHdmiPlugged = !readHdmiState(); |
| 743 | setHdmiPlugged(!mHdmiPlugged); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 744 | } |
| 745 | |
Dianne Hackborn | 2973568 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 746 | public void setInitialDisplaySize(int width, int height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 747 | int shortSize; |
Dianne Hackborn | 2973568 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 748 | if (width > height) { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 749 | shortSize = height; |
Dianne Hackborn | 2973568 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 750 | mLandscapeRotation = Surface.ROTATION_0; |
| 751 | mSeascapeRotation = Surface.ROTATION_180; |
| 752 | if (mContext.getResources().getBoolean( |
| 753 | com.android.internal.R.bool.config_reverseDefaultRotation)) { |
| 754 | mPortraitRotation = Surface.ROTATION_90; |
| 755 | mUpsideDownRotation = Surface.ROTATION_270; |
| 756 | } else { |
| 757 | mPortraitRotation = Surface.ROTATION_270; |
| 758 | mUpsideDownRotation = Surface.ROTATION_90; |
| 759 | } |
| 760 | } else { |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 761 | shortSize = width; |
Dianne Hackborn | 2973568 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 762 | mPortraitRotation = Surface.ROTATION_0; |
| 763 | mUpsideDownRotation = Surface.ROTATION_180; |
| 764 | if (mContext.getResources().getBoolean( |
| 765 | com.android.internal.R.bool.config_reverseDefaultRotation)) { |
| 766 | mLandscapeRotation = Surface.ROTATION_270; |
| 767 | mSeascapeRotation = Surface.ROTATION_90; |
| 768 | } else { |
| 769 | mLandscapeRotation = Surface.ROTATION_90; |
| 770 | mSeascapeRotation = Surface.ROTATION_270; |
| 771 | } |
| 772 | } |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 773 | |
| 774 | // Determine whether the status bar can hide based on the size |
| 775 | // of the screen. We assume sizes > 600dp are tablets where we |
| 776 | // will use the system bar. |
| 777 | int shortSizeDp = (shortSize*DisplayMetrics.DENSITY_DEVICE) |
| 778 | / DisplayMetrics.DENSITY_DEFAULT; |
| 779 | mStatusBarCanHide = shortSizeDp < 600; |
| 780 | mStatusBarHeight = mContext.getResources().getDimensionPixelSize( |
| 781 | mStatusBarCanHide |
| 782 | ? com.android.internal.R.dimen.status_bar_height |
| 783 | : com.android.internal.R.dimen.system_bar_height); |
Dianne Hackborn | 2973568 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 784 | } |
| 785 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 786 | public void updateSettings() { |
| 787 | ContentResolver resolver = mContext.getContentResolver(); |
| 788 | boolean updateRotation = false; |
| 789 | View addView = null; |
| 790 | View removeView = null; |
| 791 | synchronized (mLock) { |
| 792 | mEndcallBehavior = Settings.System.getInt(resolver, |
David Brown | baf8d09 | 2010-03-08 21:52:59 -0800 | [diff] [blame] | 793 | Settings.System.END_BUTTON_BEHAVIOR, |
| 794 | Settings.System.END_BUTTON_BEHAVIOR_DEFAULT); |
| 795 | mIncallPowerBehavior = Settings.Secure.getInt(resolver, |
| 796 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR, |
| 797 | Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 798 | mFancyRotationAnimation = Settings.System.getInt(resolver, |
| 799 | "fancy_rotation_anim", 0) != 0 ? 0x80 : 0; |
| 800 | int accelerometerDefault = Settings.System.getInt(resolver, |
| 801 | Settings.System.ACCELEROMETER_ROTATION, DEFAULT_ACCELEROMETER_ROTATION); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 802 | |
| 803 | // set up rotation lock state |
Daniel Sandler | 1b815d6 | 2010-11-05 10:24:27 -0400 | [diff] [blame] | 804 | mUserRotationMode = (accelerometerDefault == 0) |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 805 | ? WindowManagerPolicy.USER_ROTATION_LOCKED |
| 806 | : WindowManagerPolicy.USER_ROTATION_FREE; |
| 807 | mUserRotation = Settings.System.getInt(resolver, |
| 808 | Settings.System.USER_ROTATION, |
| 809 | Surface.ROTATION_0); |
| 810 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 811 | if (mAccelerometerDefault != accelerometerDefault) { |
| 812 | mAccelerometerDefault = accelerometerDefault; |
| 813 | updateOrientationListenerLp(); |
| 814 | } |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 815 | |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 816 | mOrientationListener.setLogEnabled( |
| 817 | Settings.System.getInt(resolver, |
| 818 | Settings.System.WINDOW_ORIENTATION_LISTENER_LOG, 0) != 0); |
| 819 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 820 | if (mSystemReady) { |
| 821 | int pointerLocation = Settings.System.getInt(resolver, |
| 822 | Settings.System.POINTER_LOCATION, 0); |
| 823 | if (mPointerLocationMode != pointerLocation) { |
| 824 | mPointerLocationMode = pointerLocation; |
| 825 | if (pointerLocation != 0) { |
| 826 | if (mPointerLocationView == null) { |
| 827 | mPointerLocationView = new PointerLocationView(mContext); |
| 828 | mPointerLocationView.setPrintCoords(false); |
| 829 | addView = mPointerLocationView; |
| 830 | } |
| 831 | } else { |
| 832 | removeView = mPointerLocationView; |
| 833 | mPointerLocationView = null; |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | // use screen off timeout setting as the timeout for the lockscreen |
| 838 | mLockScreenTimeout = Settings.System.getInt(resolver, |
| 839 | Settings.System.SCREEN_OFF_TIMEOUT, 0); |
| 840 | String imId = Settings.Secure.getString(resolver, |
| 841 | Settings.Secure.DEFAULT_INPUT_METHOD); |
| 842 | boolean hasSoftInput = imId != null && imId.length() > 0; |
| 843 | if (mHasSoftInput != hasSoftInput) { |
| 844 | mHasSoftInput = hasSoftInput; |
| 845 | updateRotation = true; |
| 846 | } |
| 847 | } |
| 848 | if (updateRotation) { |
| 849 | updateRotation(0); |
| 850 | } |
| 851 | if (addView != null) { |
| 852 | WindowManager.LayoutParams lp = new WindowManager.LayoutParams( |
| 853 | WindowManager.LayoutParams.MATCH_PARENT, |
| 854 | WindowManager.LayoutParams.MATCH_PARENT); |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 855 | lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY; |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 856 | lp.flags = |
| 857 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 858 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 859 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; |
| 860 | lp.format = PixelFormat.TRANSLUCENT; |
| 861 | lp.setTitle("PointerLocation"); |
| 862 | WindowManagerImpl wm = (WindowManagerImpl) |
| 863 | mContext.getSystemService(Context.WINDOW_SERVICE); |
| 864 | wm.addView(addView, lp); |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 865 | |
| 866 | if (mPointerLocationInputChannel == null) { |
| 867 | try { |
| 868 | mPointerLocationInputChannel = |
| 869 | mWindowManager.monitorInput("PointerLocationView"); |
| 870 | InputQueue.registerInputChannel(mPointerLocationInputChannel, |
| 871 | mPointerLocationInputHandler, mHandler.getLooper().getQueue()); |
| 872 | } catch (RemoteException ex) { |
| 873 | Slog.e(TAG, "Could not set up input monitoring channel for PointerLocation.", |
| 874 | ex); |
| 875 | } |
| 876 | } |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 877 | } |
| 878 | if (removeView != null) { |
Jeff Brown | a41ca77 | 2010-08-11 14:46:32 -0700 | [diff] [blame] | 879 | if (mPointerLocationInputChannel != null) { |
| 880 | InputQueue.unregisterInputChannel(mPointerLocationInputChannel); |
| 881 | mPointerLocationInputChannel.dispose(); |
| 882 | mPointerLocationInputChannel = null; |
| 883 | } |
| 884 | |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 885 | WindowManagerImpl wm = (WindowManagerImpl) |
| 886 | mContext.getSystemService(Context.WINDOW_SERVICE); |
| 887 | wm.removeView(removeView); |
| 888 | } |
| 889 | } |
| 890 | |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 891 | private int readRotation(int resID) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 892 | try { |
| 893 | int rotation = mContext.getResources().getInteger(resID); |
| 894 | switch (rotation) { |
| 895 | case 0: |
| 896 | return Surface.ROTATION_0; |
| 897 | case 90: |
| 898 | return Surface.ROTATION_90; |
| 899 | case 180: |
| 900 | return Surface.ROTATION_180; |
| 901 | case 270: |
| 902 | return Surface.ROTATION_270; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 903 | } |
| 904 | } catch (Resources.NotFoundException e) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 905 | // fall through |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 906 | } |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 907 | return -1; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | /** {@inheritDoc} */ |
| 911 | public int checkAddPermission(WindowManager.LayoutParams attrs) { |
| 912 | int type = attrs.type; |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 913 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 914 | if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW |
| 915 | || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) { |
| 916 | return WindowManagerImpl.ADD_OKAY; |
| 917 | } |
| 918 | String permission = null; |
| 919 | switch (type) { |
| 920 | case TYPE_TOAST: |
| 921 | // XXX right now the app process has complete control over |
| 922 | // this... should introduce a token to let the system |
| 923 | // monitor/control what they are doing. |
| 924 | break; |
| 925 | case TYPE_INPUT_METHOD: |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 926 | case TYPE_WALLPAPER: |
| 927 | // The window manager will check these. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 928 | break; |
| 929 | case TYPE_PHONE: |
| 930 | case TYPE_PRIORITY_PHONE: |
| 931 | case TYPE_SYSTEM_ALERT: |
| 932 | case TYPE_SYSTEM_ERROR: |
| 933 | case TYPE_SYSTEM_OVERLAY: |
| 934 | permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW; |
| 935 | break; |
| 936 | default: |
| 937 | permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW; |
| 938 | } |
| 939 | if (permission != null) { |
| 940 | if (mContext.checkCallingOrSelfPermission(permission) |
| 941 | != PackageManager.PERMISSION_GRANTED) { |
| 942 | return WindowManagerImpl.ADD_PERMISSION_DENIED; |
| 943 | } |
| 944 | } |
| 945 | return WindowManagerImpl.ADD_OKAY; |
| 946 | } |
| 947 | |
| 948 | public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) { |
| 949 | switch (attrs.type) { |
| 950 | case TYPE_SYSTEM_OVERLAY: |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 951 | case TYPE_SECURE_SYSTEM_OVERLAY: |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 952 | case TYPE_TOAST: |
| 953 | // These types of windows can't receive input events. |
| 954 | attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 955 | | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; |
| 956 | break; |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | void readLidState() { |
| 961 | try { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 962 | int sw = mWindowManager.getSwitchState(SW_LID); |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 963 | if (sw > 0) { |
| 964 | mLidOpen = LID_OPEN; |
| 965 | } else if (sw == 0) { |
| 966 | mLidOpen = LID_CLOSED; |
| 967 | } else { |
| 968 | mLidOpen = LID_ABSENT; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 969 | } |
| 970 | } catch (RemoteException e) { |
| 971 | // Ignore |
| 972 | } |
| 973 | } |
| 974 | |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 975 | private int determineHiddenState(int mode, int hiddenValue, int visibleValue) { |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 976 | if (mLidOpen != LID_ABSENT) { |
| 977 | switch (mode) { |
| 978 | case 1: |
| 979 | return mLidOpen == LID_OPEN ? visibleValue : hiddenValue; |
| 980 | case 2: |
| 981 | return mLidOpen == LID_OPEN ? hiddenValue : visibleValue; |
| 982 | } |
Dianne Hackborn | 2862fff | 2009-09-15 22:56:29 -0700 | [diff] [blame] | 983 | } |
| 984 | return visibleValue; |
| 985 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 986 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 987 | /** {@inheritDoc} */ |
| 988 | public void adjustConfigurationLw(Configuration config) { |
| 989 | readLidState(); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 990 | |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 991 | mPowerManager.setKeyboardVisibility(mLidOpen == LID_OPEN); |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 992 | |
| 993 | if (config.keyboard == Configuration.KEYBOARD_NOKEYS) { |
| 994 | config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES; |
| 995 | } else { |
| 996 | config.hardKeyboardHidden = determineHiddenState(mLidKeyboardAccessibility, |
| 997 | Configuration.HARDKEYBOARDHIDDEN_YES, Configuration.HARDKEYBOARDHIDDEN_NO); |
| 998 | } |
| 999 | |
| 1000 | if (config.navigation == Configuration.NAVIGATION_NONAV) { |
| 1001 | config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES; |
| 1002 | } else { |
| 1003 | config.navigationHidden = determineHiddenState(mLidNavigationAccessibility, |
| 1004 | Configuration.NAVIGATIONHIDDEN_YES, Configuration.NAVIGATIONHIDDEN_NO); |
| 1005 | } |
| 1006 | |
| 1007 | if (mHasSoftInput || config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) { |
| 1008 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_NO; |
| 1009 | } else { |
| 1010 | config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; |
| 1011 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1012 | } |
Jeff Brown | d04a88c | 2011-01-16 14:05:47 -0800 | [diff] [blame] | 1013 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1014 | /** {@inheritDoc} */ |
| 1015 | public int windowTypeToLayerLw(int type) { |
| 1016 | if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) { |
| 1017 | return APPLICATION_LAYER; |
| 1018 | } |
| 1019 | switch (type) { |
| 1020 | case TYPE_STATUS_BAR: |
| 1021 | return STATUS_BAR_LAYER; |
| 1022 | case TYPE_STATUS_BAR_PANEL: |
| 1023 | return STATUS_BAR_PANEL_LAYER; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1024 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1025 | return STATUS_BAR_SUB_PANEL_LAYER; |
Dianne Hackborn | 6a294ce | 2009-12-03 11:37:44 -0800 | [diff] [blame] | 1026 | case TYPE_SYSTEM_DIALOG: |
| 1027 | return SYSTEM_DIALOG_LAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1028 | case TYPE_SEARCH_BAR: |
| 1029 | return SEARCH_BAR_LAYER; |
| 1030 | case TYPE_PHONE: |
| 1031 | return PHONE_LAYER; |
| 1032 | case TYPE_KEYGUARD: |
| 1033 | return KEYGUARD_LAYER; |
| 1034 | case TYPE_KEYGUARD_DIALOG: |
| 1035 | return KEYGUARD_DIALOG_LAYER; |
| 1036 | case TYPE_SYSTEM_ALERT: |
| 1037 | return SYSTEM_ALERT_LAYER; |
| 1038 | case TYPE_SYSTEM_ERROR: |
| 1039 | return SYSTEM_ERROR_LAYER; |
| 1040 | case TYPE_INPUT_METHOD: |
| 1041 | return INPUT_METHOD_LAYER; |
| 1042 | case TYPE_INPUT_METHOD_DIALOG: |
| 1043 | return INPUT_METHOD_DIALOG_LAYER; |
| 1044 | case TYPE_SYSTEM_OVERLAY: |
| 1045 | return SYSTEM_OVERLAY_LAYER; |
Jeff Brown | 3b2b354 | 2010-10-15 00:54:27 -0700 | [diff] [blame] | 1046 | case TYPE_SECURE_SYSTEM_OVERLAY: |
| 1047 | return SECURE_SYSTEM_OVERLAY_LAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1048 | case TYPE_PRIORITY_PHONE: |
| 1049 | return PRIORITY_PHONE_LAYER; |
| 1050 | case TYPE_TOAST: |
| 1051 | return TOAST_LAYER; |
Dianne Hackborn | b7cd8b9 | 2009-08-08 20:53:03 -0700 | [diff] [blame] | 1052 | case TYPE_WALLPAPER: |
| 1053 | return WALLPAPER_LAYER; |
Christopher Tate | a53146c | 2010-09-07 11:57:52 -0700 | [diff] [blame] | 1054 | case TYPE_DRAG: |
| 1055 | return DRAG_LAYER; |
Jeff Brown | 83c0968 | 2010-12-23 17:50:18 -0800 | [diff] [blame] | 1056 | case TYPE_POINTER: |
| 1057 | return POINTER_LAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1058 | } |
| 1059 | Log.e(TAG, "Unknown window type: " + type); |
| 1060 | return APPLICATION_LAYER; |
| 1061 | } |
| 1062 | |
| 1063 | /** {@inheritDoc} */ |
| 1064 | public int subWindowTypeToLayerLw(int type) { |
| 1065 | switch (type) { |
| 1066 | case TYPE_APPLICATION_PANEL: |
| 1067 | case TYPE_APPLICATION_ATTACHED_DIALOG: |
| 1068 | return APPLICATION_PANEL_SUBLAYER; |
| 1069 | case TYPE_APPLICATION_MEDIA: |
| 1070 | return APPLICATION_MEDIA_SUBLAYER; |
Dianne Hackborn | 5cb8d79 | 2009-05-21 17:34:15 -0700 | [diff] [blame] | 1071 | case TYPE_APPLICATION_MEDIA_OVERLAY: |
| 1072 | return APPLICATION_MEDIA_OVERLAY_SUBLAYER; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1073 | case TYPE_APPLICATION_SUB_PANEL: |
| 1074 | return APPLICATION_SUB_PANEL_SUBLAYER; |
| 1075 | } |
| 1076 | Log.e(TAG, "Unknown sub-window type: " + type); |
| 1077 | return 0; |
| 1078 | } |
| 1079 | |
Dianne Hackborn | abe0da0 | 2009-09-18 01:55:39 -0700 | [diff] [blame] | 1080 | public int getMaxWallpaperLayer() { |
| 1081 | return STATUS_BAR_LAYER; |
| 1082 | } |
| 1083 | |
Dianne Hackborn | 81e56d5 | 2011-05-26 00:55:58 -0700 | [diff] [blame] | 1084 | public boolean canStatusBarHide() { |
| 1085 | return mStatusBarCanHide; |
| 1086 | } |
| 1087 | |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1088 | public int getNonDecorDisplayWidth(int rotation, int fullWidth) { |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1089 | return fullWidth; |
| 1090 | } |
| 1091 | |
Dianne Hackborn | 69cb875 | 2011-05-19 18:13:32 -0700 | [diff] [blame] | 1092 | public int getNonDecorDisplayHeight(int rotation, int fullHeight) { |
| 1093 | return mStatusBarCanHide ? fullHeight : (fullHeight - mStatusBarHeight); |
| 1094 | } |
| 1095 | |
| 1096 | public int getConfigDisplayWidth(int rotation, int fullWidth) { |
| 1097 | return fullWidth; |
| 1098 | } |
| 1099 | |
| 1100 | public int getConfigDisplayHeight(int rotation, int fullHeight) { |
| 1101 | return fullHeight - mStatusBarHeight; |
Dianne Hackborn | e2515ee | 2011-04-27 18:52:56 -0400 | [diff] [blame] | 1102 | } |
| 1103 | |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1104 | public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) { |
| 1105 | return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD; |
| 1106 | } |
| 1107 | |
| 1108 | public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) { |
| 1109 | return attrs.type != WindowManager.LayoutParams.TYPE_STATUS_BAR |
| 1110 | && attrs.type != WindowManager.LayoutParams.TYPE_WALLPAPER; |
| 1111 | } |
| 1112 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1113 | /** {@inheritDoc} */ |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1114 | public View addStartingWindow(IBinder appToken, String packageName, int theme, |
| 1115 | CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes, |
| 1116 | int icon, int windowFlags) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1117 | if (!SHOW_STARTING_ANIMATIONS) { |
| 1118 | return null; |
| 1119 | } |
| 1120 | if (packageName == null) { |
| 1121 | return null; |
| 1122 | } |
| 1123 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1124 | try { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1125 | Context context = mContext; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1126 | //Log.i(TAG, "addStartingWindow " + packageName + ": nonLocalizedLabel=" |
| 1127 | // + nonLocalizedLabel + " theme=" + Integer.toHexString(theme)); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1128 | if (theme != context.getThemeResId() || labelRes != 0) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1129 | try { |
| 1130 | context = context.createPackageContext(packageName, 0); |
Dianne Hackborn | 247fe74 | 2011-01-08 17:25:57 -0800 | [diff] [blame] | 1131 | context.setTheme(theme); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1132 | } catch (PackageManager.NameNotFoundException e) { |
| 1133 | // Ignore |
| 1134 | } |
| 1135 | } |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1136 | |
| 1137 | Window win = PolicyManager.makeNewWindow(context); |
| 1138 | if (win.getWindowStyle().getBoolean( |
| 1139 | com.android.internal.R.styleable.Window_windowDisablePreview, false)) { |
| 1140 | return null; |
| 1141 | } |
| 1142 | |
| 1143 | Resources r = context.getResources(); |
| 1144 | win.setTitle(r.getText(labelRes, nonLocalizedLabel)); |
| 1145 | |
| 1146 | win.setType( |
| 1147 | WindowManager.LayoutParams.TYPE_APPLICATION_STARTING); |
| 1148 | // Force the window flags: this is a fake window, so it is not really |
| 1149 | // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM |
| 1150 | // flag because we do know that the next window will take input |
| 1151 | // focus, so we want to get the IME window up on top of us right away. |
| 1152 | win.setFlags( |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1153 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1154 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 1155 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 1156 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, |
Dianne Hackborn | 7eec10e | 2010-11-12 18:03:47 -0800 | [diff] [blame] | 1157 | windowFlags| |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1158 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE| |
| 1159 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE| |
| 1160 | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); |
| 1161 | |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1162 | if (!compatInfo.supportsScreen()) { |
| 1163 | win.addFlags(WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW); |
| 1164 | } |
| 1165 | |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1166 | win.setLayout(WindowManager.LayoutParams.MATCH_PARENT, |
Dianne Hackborn | 2f0b175 | 2011-05-31 17:59:49 -0700 | [diff] [blame] | 1167 | WindowManager.LayoutParams.MATCH_PARENT); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1168 | |
| 1169 | final WindowManager.LayoutParams params = win.getAttributes(); |
| 1170 | params.token = appToken; |
| 1171 | params.packageName = packageName; |
| 1172 | params.windowAnimations = win.getWindowStyle().getResourceId( |
| 1173 | com.android.internal.R.styleable.Window_windowAnimationStyle, 0); |
| 1174 | params.setTitle("Starting " + packageName); |
| 1175 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1176 | WindowManagerImpl wm = (WindowManagerImpl) |
| 1177 | context.getSystemService(Context.WINDOW_SERVICE); |
| 1178 | View view = win.getDecorView(); |
| 1179 | |
| 1180 | if (win.isFloating()) { |
| 1181 | // Whoops, there is no way to display an animation/preview |
| 1182 | // of such a thing! After all that work... let's skip it. |
| 1183 | // (Note that we must do this here because it is in |
| 1184 | // getDecorView() where the theme is evaluated... maybe |
| 1185 | // we should peek the floating attribute from the theme |
| 1186 | // earlier.) |
| 1187 | return null; |
| 1188 | } |
| 1189 | |
| 1190 | if (localLOGV) Log.v( |
| 1191 | TAG, "Adding starting window for " + packageName |
| 1192 | + " / " + appToken + ": " |
| 1193 | + (view.getParent() != null ? view : null)); |
| 1194 | |
| 1195 | wm.addView(view, params); |
| 1196 | |
| 1197 | // Only return the view if it was successfully added to the |
| 1198 | // window manager... which we can tell by it having a parent. |
| 1199 | return view.getParent() != null ? view : null; |
| 1200 | } catch (WindowManagerImpl.BadTokenException e) { |
| 1201 | // ignore |
| 1202 | Log.w(TAG, appToken + " already running, starting window not displayed"); |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 1203 | } catch (RuntimeException e) { |
| 1204 | // don't crash if something else bad happens, for example a |
| 1205 | // failure loading resources because we are loading from an app |
| 1206 | // on external storage that has been unmounted. |
| 1207 | Log.w(TAG, appToken + " failed creating starting window", e); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | return null; |
| 1211 | } |
| 1212 | |
| 1213 | /** {@inheritDoc} */ |
| 1214 | public void removeStartingWindow(IBinder appToken, View window) { |
| 1215 | // RuntimeException e = new RuntimeException(); |
| 1216 | // Log.i(TAG, "remove " + appToken + " " + window, e); |
| 1217 | |
| 1218 | if (localLOGV) Log.v( |
| 1219 | TAG, "Removing starting window for " + appToken + ": " + window); |
| 1220 | |
| 1221 | if (window != null) { |
| 1222 | WindowManagerImpl wm = (WindowManagerImpl) mContext.getSystemService(Context.WINDOW_SERVICE); |
| 1223 | wm.removeView(window); |
| 1224 | } |
| 1225 | } |
| 1226 | |
| 1227 | /** |
| 1228 | * Preflight adding a window to the system. |
| 1229 | * |
| 1230 | * Currently enforces that three window types are singletons: |
| 1231 | * <ul> |
| 1232 | * <li>STATUS_BAR_TYPE</li> |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1233 | * <li>KEYGUARD_TYPE</li> |
| 1234 | * </ul> |
| 1235 | * |
| 1236 | * @param win The window to be added |
| 1237 | * @param attrs Information about the window to be added |
| 1238 | * |
| 1239 | * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons, WindowManagerImpl.ADD_MULTIPLE_SINGLETON |
| 1240 | */ |
| 1241 | public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) { |
| 1242 | switch (attrs.type) { |
| 1243 | case TYPE_STATUS_BAR: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 1244 | mContext.enforceCallingOrSelfPermission( |
| 1245 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1246 | "PhoneWindowManager"); |
| 1247 | // TODO: Need to handle the race condition of the status bar proc |
| 1248 | // dying and coming back before the removeWindowLw cleanup has happened. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1249 | if (mStatusBar != null) { |
| 1250 | return WindowManagerImpl.ADD_MULTIPLE_SINGLETON; |
| 1251 | } |
| 1252 | mStatusBar = win; |
| 1253 | break; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1254 | case TYPE_STATUS_BAR_PANEL: |
Joe Onorato | 8bc6c51 | 2010-06-04 16:21:12 -0400 | [diff] [blame] | 1255 | mContext.enforceCallingOrSelfPermission( |
| 1256 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1257 | "PhoneWindowManager"); |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1258 | mStatusBarPanels.add(win); |
| 1259 | break; |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1260 | case TYPE_STATUS_BAR_SUB_PANEL: |
| 1261 | mContext.enforceCallingOrSelfPermission( |
| 1262 | android.Manifest.permission.STATUS_BAR_SERVICE, |
| 1263 | "PhoneWindowManager"); |
| 1264 | mStatusBarPanels.add(win); |
| 1265 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1266 | case TYPE_KEYGUARD: |
| 1267 | if (mKeyguard != null) { |
| 1268 | return WindowManagerImpl.ADD_MULTIPLE_SINGLETON; |
| 1269 | } |
| 1270 | mKeyguard = win; |
| 1271 | break; |
| 1272 | } |
| 1273 | return WindowManagerImpl.ADD_OKAY; |
| 1274 | } |
| 1275 | |
| 1276 | /** {@inheritDoc} */ |
| 1277 | public void removeWindowLw(WindowState win) { |
| 1278 | if (mStatusBar == win) { |
| 1279 | mStatusBar = null; |
| 1280 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1281 | else if (mKeyguard == win) { |
| 1282 | mKeyguard = null; |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 1283 | } else { |
| 1284 | mStatusBarPanels.remove(win); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | static final boolean PRINT_ANIM = false; |
| 1289 | |
| 1290 | /** {@inheritDoc} */ |
| 1291 | public int selectAnimationLw(WindowState win, int transit) { |
| 1292 | if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win |
| 1293 | + ": transit=" + transit); |
| 1294 | if (transit == TRANSIT_PREVIEW_DONE) { |
| 1295 | if (win.hasAppShownWindows()) { |
| 1296 | if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT"); |
| 1297 | return com.android.internal.R.anim.app_starting_exit; |
| 1298 | } |
| 1299 | } |
| 1300 | |
| 1301 | return 0; |
| 1302 | } |
| 1303 | |
Dianne Hackborn | 01ad2f4 | 2009-09-24 19:24:56 -0700 | [diff] [blame] | 1304 | public Animation createForceHideEnterAnimation() { |
| 1305 | return AnimationUtils.loadAnimation(mContext, |
| 1306 | com.android.internal.R.anim.lock_screen_behind_enter); |
| 1307 | } |
| 1308 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1309 | static ITelephony getTelephonyService() { |
| 1310 | ITelephony telephonyService = ITelephony.Stub.asInterface( |
| 1311 | ServiceManager.checkService(Context.TELEPHONY_SERVICE)); |
| 1312 | if (telephonyService == null) { |
| 1313 | Log.w(TAG, "Unable to find ITelephony interface."); |
| 1314 | } |
| 1315 | return telephonyService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1316 | } |
| 1317 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 1318 | static IAudioService getAudioService() { |
| 1319 | IAudioService audioService = IAudioService.Stub.asInterface( |
| 1320 | ServiceManager.checkService(Context.AUDIO_SERVICE)); |
| 1321 | if (audioService == null) { |
| 1322 | Log.w(TAG, "Unable to find IAudioService interface."); |
| 1323 | } |
| 1324 | return audioService; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | boolean keyguardOn() { |
| 1328 | return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode(); |
| 1329 | } |
| 1330 | |
| 1331 | private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = { |
| 1332 | WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, |
| 1333 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, |
| 1334 | }; |
| 1335 | |
| 1336 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1337 | @Override |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1338 | public boolean interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1339 | final boolean keyguardOn = keyguardOn(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1340 | final int keyCode = event.getKeyCode(); |
| 1341 | final int repeatCount = event.getRepeatCount(); |
| 1342 | final int metaState = event.getMetaState(); |
| 1343 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 1344 | final boolean canceled = event.isCanceled(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1345 | |
| 1346 | if (false) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1347 | Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount=" |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1348 | + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed); |
| 1349 | } |
| 1350 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1351 | // First we always handle the home key here, so applications |
| 1352 | // can never break it, although if keyguard is on, we do let |
| 1353 | // it handle it, because that gives us the correct 5 second |
| 1354 | // timeout. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1355 | if (keyCode == KeyEvent.KEYCODE_HOME) { |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1356 | // Clear a pending HOME longpress if the user releases Home |
| 1357 | if (!down) { |
| 1358 | mHandler.removeCallbacks(mHomeLongPress); |
| 1359 | } |
| 1360 | |
| 1361 | // If we have released the home key, and didn't do anything else |
| 1362 | // while it was pressed, then it is time to go home! |
| 1363 | if (mHomePressed && !down) { |
| 1364 | mHomePressed = false; |
| 1365 | if (!canceled) { |
| 1366 | // If an incoming call is ringing, HOME is totally disabled. |
| 1367 | // (The user is already on the InCallScreen at this point, |
| 1368 | // and his ONLY options are to answer or reject the call.) |
| 1369 | boolean incomingRinging = false; |
| 1370 | try { |
| 1371 | ITelephony telephonyService = getTelephonyService(); |
| 1372 | if (telephonyService != null) { |
| 1373 | incomingRinging = telephonyService.isRinging(); |
| 1374 | } |
| 1375 | } catch (RemoteException ex) { |
| 1376 | Log.w(TAG, "RemoteException from getPhoneInterface()", ex); |
| 1377 | } |
| 1378 | |
| 1379 | if (incomingRinging) { |
| 1380 | Log.i(TAG, "Ignoring HOME; there's a ringing incoming call."); |
| 1381 | } else { |
| 1382 | launchHomeFromHotKey(); |
| 1383 | } |
| 1384 | } else { |
| 1385 | Log.i(TAG, "Ignoring HOME; event canceled."); |
| 1386 | } |
| 1387 | return true; |
| 1388 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1389 | |
| 1390 | // If a system window has focus, then it doesn't make sense |
| 1391 | // right now to interact with applications. |
| 1392 | WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null; |
| 1393 | if (attrs != null) { |
| 1394 | final int type = attrs.type; |
| 1395 | if (type == WindowManager.LayoutParams.TYPE_KEYGUARD |
| 1396 | || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) { |
| 1397 | // the "app" is keyguard, so give it the key |
| 1398 | return false; |
| 1399 | } |
| 1400 | final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length; |
| 1401 | for (int i=0; i<typeCount; i++) { |
| 1402 | if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) { |
| 1403 | // don't do anything, but also don't pass it to the app |
| 1404 | return true; |
| 1405 | } |
| 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | if (down && repeatCount == 0) { |
| 1410 | if (!keyguardOn) { |
| 1411 | mHandler.postDelayed(mHomeLongPress, ViewConfiguration.getGlobalActionKeyTimeout()); |
| 1412 | } |
| 1413 | mHomePressed = true; |
| 1414 | } |
| 1415 | return true; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1416 | } else if (keyCode == KeyEvent.KEYCODE_MENU) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1417 | // Hijack modified menu keys for debugging features |
| 1418 | final int chordBug = KeyEvent.META_SHIFT_ON; |
| 1419 | |
| 1420 | if (down && repeatCount == 0) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1421 | if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1422 | Intent intent = new Intent(Intent.ACTION_BUG_REPORT); |
| 1423 | mContext.sendOrderedBroadcast(intent, null); |
| 1424 | return true; |
| 1425 | } else if (SHOW_PROCESSES_ON_ALT_MENU && |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1426 | (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1427 | Intent service = new Intent(); |
| 1428 | service.setClassName(mContext, "com.android.server.LoadAverageService"); |
| 1429 | ContentResolver res = mContext.getContentResolver(); |
| 1430 | boolean shown = Settings.System.getInt( |
| 1431 | res, Settings.System.SHOW_PROCESSES, 0) != 0; |
| 1432 | if (!shown) { |
| 1433 | mContext.startService(service); |
| 1434 | } else { |
| 1435 | mContext.stopService(service); |
| 1436 | } |
| 1437 | Settings.System.putInt( |
| 1438 | res, Settings.System.SHOW_PROCESSES, shown ? 0 : 1); |
| 1439 | return true; |
| 1440 | } |
| 1441 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 1442 | } else if (keyCode == KeyEvent.KEYCODE_SEARCH) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1443 | if (down) { |
| 1444 | if (repeatCount == 0) { |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1445 | mShortcutKeyPressed = keyCode; |
| 1446 | mConsumeShortcutKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1447 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1448 | } else if (keyCode == mShortcutKeyPressed) { |
| 1449 | mShortcutKeyPressed = -1; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1450 | if (mConsumeShortcutKeyUp) { |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1451 | mConsumeShortcutKeyUp = false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1452 | return true; |
| 1453 | } |
| 1454 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 1455 | return false; |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1456 | } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) { |
Jeff Brown | 524ee64 | 2011-03-29 15:11:34 -0700 | [diff] [blame] | 1457 | if (down && repeatCount == 0) { |
Jeff Brown | d0132e8 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 1458 | showOrHideRecentAppsDialog(0, true /*dismissIfShown*/); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1459 | } |
| 1460 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1461 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 1462 | |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 1463 | // Shortcuts are invoked through Search+key, so intercept those here |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 1464 | // Any printing key that is chorded with Search should be consumed |
| 1465 | // even if no shortcut was invoked. This prevents text from being |
| 1466 | // inadvertently inserted when using a keyboard that has built-in macro |
| 1467 | // shortcut keys (that emit Search+x) and some of them are not registered. |
| 1468 | if (mShortcutKeyPressed != -1) { |
| 1469 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
| 1470 | if (kcm.isPrintingKey(keyCode)) { |
| 1471 | mConsumeShortcutKeyUp = true; |
| 1472 | if (down && repeatCount == 0 && !keyguardOn) { |
| 1473 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState); |
| 1474 | if (shortcutIntent != null) { |
| 1475 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Jeff Brown | f0a3cc5 | 2011-01-26 18:42:46 -0800 | [diff] [blame] | 1476 | try { |
| 1477 | mContext.startActivity(shortcutIntent); |
| 1478 | } catch (ActivityNotFoundException ex) { |
| 1479 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 1480 | + "the activity to which it is registered was not found: " |
| 1481 | + KeyEvent.keyCodeToString(mShortcutKeyPressed) |
| 1482 | + "+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 1483 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 1484 | } else { |
| 1485 | Slog.i(TAG, "Dropping unregistered shortcut key combination: " |
| 1486 | + KeyEvent.keyCodeToString(mShortcutKeyPressed) |
| 1487 | + "+" + KeyEvent.keyCodeToString(keyCode)); |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1488 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1489 | } |
Jeff Brown | caab4d0 | 2010-12-09 22:13:41 -0800 | [diff] [blame] | 1490 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1491 | } |
| 1492 | } |
| 1493 | |
| 1494 | return false; |
| 1495 | } |
| 1496 | |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 1497 | /** {@inheritDoc} */ |
| 1498 | @Override |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1499 | public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) { |
Jeff Brown | d0132e8 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 1500 | // Note: This method is only called if the initial down was unhandled. |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1501 | if (DEBUG_FALLBACK) { |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 1502 | Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction() |
| 1503 | + ", flags=" + event.getFlags() |
| 1504 | + ", keyCode=" + event.getKeyCode() |
| 1505 | + ", scanCode=" + event.getScanCode() |
| 1506 | + ", metaState=" + event.getMetaState() |
| 1507 | + ", repeatCount=" + event.getRepeatCount() |
| 1508 | + ", policyFlags=" + policyFlags); |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 1509 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1510 | |
| 1511 | if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) { |
| 1512 | final KeyCharacterMap kcm = event.getKeyCharacterMap(); |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 1513 | final int keyCode = event.getKeyCode(); |
| 1514 | final int metaState = event.getMetaState(); |
Jeff Brown | d0132e8 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 1515 | final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN |
| 1516 | && event.getRepeatCount() == 0; |
| 1517 | |
| 1518 | if (initialDown) { |
| 1519 | // Invoke shortcuts using Meta as a fallback. |
| 1520 | if ((metaState & KeyEvent.META_META_ON) != 0) { |
| 1521 | Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, |
| 1522 | metaState & ~(KeyEvent.META_META_ON |
| 1523 | | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON)); |
| 1524 | if (shortcutIntent != null) { |
| 1525 | shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 1526 | try { |
| 1527 | mContext.startActivity(shortcutIntent); |
| 1528 | } catch (ActivityNotFoundException ex) { |
| 1529 | Slog.w(TAG, "Dropping shortcut key combination because " |
| 1530 | + "the activity to which it is registered was not found: " |
| 1531 | + "META+" + KeyEvent.keyCodeToString(keyCode), ex); |
| 1532 | } |
| 1533 | return null; |
Jeff Brown | bfaf3b9 | 2011-02-22 15:00:50 -0800 | [diff] [blame] | 1534 | } |
Jeff Brown | d0132e8 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | // Display task switcher for ALT-TAB or Meta-TAB. |
| 1538 | if (keyCode == KeyEvent.KEYCODE_TAB) { |
| 1539 | final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK; |
| 1540 | if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON) |
| 1541 | || KeyEvent.metaStateHasModifiers( |
| 1542 | shiftlessModifiers, KeyEvent.META_META_ON)) { |
| 1543 | showOrHideRecentAppsDialog(shiftlessModifiers, false /*dismissIfShown*/); |
| 1544 | return null; |
| 1545 | } |
Jeff Brown | c1fb48d | 2010-12-08 16:52:09 -0800 | [diff] [blame] | 1546 | } |
| 1547 | } |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1548 | |
Jeff Brown | d0132e8 | 2011-04-06 15:33:01 -0700 | [diff] [blame] | 1549 | // Check for fallback actions specified by the key character map. |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1550 | if (getFallbackAction(kcm, keyCode, metaState, mFallbackAction)) { |
Jeff Brown | 49ed71d | 2010-12-06 17:13:33 -0800 | [diff] [blame] | 1551 | if (DEBUG_FALLBACK) { |
| 1552 | Slog.d(TAG, "Fallback: keyCode=" + mFallbackAction.keyCode |
| 1553 | + " metaState=" + Integer.toHexString(mFallbackAction.metaState)); |
| 1554 | } |
| 1555 | |
| 1556 | int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK; |
| 1557 | KeyEvent fallbackEvent = KeyEvent.obtain( |
| 1558 | event.getDownTime(), event.getEventTime(), |
| 1559 | event.getAction(), mFallbackAction.keyCode, |
| 1560 | event.getRepeatCount(), mFallbackAction.metaState, |
| 1561 | event.getDeviceId(), event.getScanCode(), |
| 1562 | flags, event.getSource(), null); |
| 1563 | int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true); |
| 1564 | if ((actions & ACTION_PASS_TO_USER) != 0) { |
| 1565 | if (!interceptKeyBeforeDispatching(win, fallbackEvent, policyFlags)) { |
| 1566 | if (DEBUG_FALLBACK) { |
| 1567 | Slog.d(TAG, "Performing fallback."); |
| 1568 | } |
| 1569 | return fallbackEvent; |
| 1570 | } |
| 1571 | } |
| 1572 | fallbackEvent.recycle(); |
| 1573 | } |
| 1574 | } |
| 1575 | |
| 1576 | if (DEBUG_FALLBACK) { |
| 1577 | Slog.d(TAG, "No fallback."); |
| 1578 | } |
| 1579 | return null; |
Jeff Brown | 3915bb8 | 2010-11-05 15:02:16 -0700 | [diff] [blame] | 1580 | } |
| 1581 | |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1582 | private boolean getFallbackAction(KeyCharacterMap kcm, int keyCode, int metaState, |
| 1583 | FallbackAction outFallbackAction) { |
| 1584 | // Consult the key character map for specific fallback actions. |
| 1585 | // For example, map NUMPAD_1 to MOVE_HOME when NUMLOCK is not pressed. |
Jeff Brown | cc0c159 | 2011-02-19 05:07:28 -0800 | [diff] [blame] | 1586 | return kcm.getFallbackAction(keyCode, metaState, outFallbackAction); |
Jeff Brown | 6f2fba4 | 2011-02-19 01:08:02 -0800 | [diff] [blame] | 1587 | } |
| 1588 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1589 | /** |
| 1590 | * A home key -> launch home action was detected. Take the appropriate action |
| 1591 | * given the situation with the keyguard. |
| 1592 | */ |
| 1593 | void launchHomeFromHotKey() { |
Dianne Hackborn | 9dc06cc | 2009-11-17 18:19:23 -0800 | [diff] [blame] | 1594 | if (mKeyguardMediator.isShowingAndNotHidden()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1595 | // don't launch home if keyguard showing |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1596 | } else if (!mHideLockScreen && mKeyguardMediator.isInputRestricted()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1597 | // when in keyguard restricted mode, must first verify unlock |
| 1598 | // before launching home |
| 1599 | mKeyguardMediator.verifyUnlock(new OnKeyguardExitResult() { |
| 1600 | public void onKeyguardExitResult(boolean success) { |
| 1601 | if (success) { |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 1602 | try { |
| 1603 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 1604 | } catch (RemoteException e) { |
| 1605 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 1606 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1607 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1608 | } |
| 1609 | } |
| 1610 | }); |
| 1611 | } else { |
| 1612 | // no keyguard stuff to worry about, just launch home! |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 1613 | try { |
| 1614 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 1615 | } catch (RemoteException e) { |
| 1616 | } |
Joe Onorato | f275f0c | 2009-11-24 16:11:13 -0500 | [diff] [blame] | 1617 | sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1618 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1619 | } |
| 1620 | } |
| 1621 | |
| 1622 | public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) { |
| 1623 | final int fl = attrs.flags; |
| 1624 | |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 1625 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_FULLSCREEN | FLAG_LAYOUT_INSET_DECOR)) |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1626 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 1627 | contentInset.set(mCurLeft, mCurTop, |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1628 | (mRestrictedScreenLeft+mRestrictedScreenWidth) - mCurRight, |
| 1629 | (mRestrictedScreenTop+mRestrictedScreenHeight) - mCurBottom); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1630 | } else { |
| 1631 | contentInset.setEmpty(); |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | /** {@inheritDoc} */ |
| 1636 | public void beginLayoutLw(int displayWidth, int displayHeight) { |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1637 | mUnrestrictedScreenLeft = mUnrestrictedScreenTop = 0; |
| 1638 | mUnrestrictedScreenWidth = displayWidth; |
| 1639 | mUnrestrictedScreenHeight = displayHeight; |
| 1640 | mRestrictedScreenLeft = mRestrictedScreenTop = 0; |
| 1641 | mRestrictedScreenWidth = displayWidth; |
| 1642 | mRestrictedScreenHeight = displayHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1643 | mDockLeft = mContentLeft = mCurLeft = 0; |
| 1644 | mDockTop = mContentTop = mCurTop = 0; |
| 1645 | mDockRight = mContentRight = mCurRight = displayWidth; |
| 1646 | mDockBottom = mContentBottom = mCurBottom = displayHeight; |
| 1647 | mDockLayer = 0x10000000; |
| 1648 | |
| 1649 | // decide where the status bar goes ahead of time |
| 1650 | if (mStatusBar != null) { |
| 1651 | final Rect pf = mTmpParentFrame; |
| 1652 | final Rect df = mTmpDisplayFrame; |
| 1653 | final Rect vf = mTmpVisibleFrame; |
| 1654 | pf.left = df.left = vf.left = 0; |
| 1655 | pf.top = df.top = vf.top = 0; |
| 1656 | pf.right = df.right = vf.right = displayWidth; |
| 1657 | pf.bottom = df.bottom = vf.bottom = displayHeight; |
| 1658 | |
| 1659 | mStatusBar.computeFrameLw(pf, df, vf, vf); |
| 1660 | if (mStatusBar.isVisibleLw()) { |
| 1661 | // If the status bar is hidden, we don't want to cause |
| 1662 | // windows behind it to scroll. |
Joe Onorato | 34bcebc | 2010-07-07 18:05:01 -0400 | [diff] [blame] | 1663 | final Rect r = mStatusBar.getFrameLw(); |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 1664 | if (mStatusBarCanHide) { |
| 1665 | // Status bar may go away, so the screen area it occupies |
| 1666 | // is available to apps but just covering them when the |
| 1667 | // status bar is visible. |
| 1668 | if (mDockTop == r.top) mDockTop = r.bottom; |
| 1669 | else if (mDockBottom == r.bottom) mDockBottom = r.top; |
| 1670 | mContentTop = mCurTop = mDockTop; |
| 1671 | mContentBottom = mCurBottom = mDockBottom; |
| 1672 | if (DEBUG_LAYOUT) Log.v(TAG, "Status bar: mDockTop=" + mDockTop |
| 1673 | + " mContentTop=" + mContentTop |
| 1674 | + " mCurTop=" + mCurTop |
| 1675 | + " mDockBottom=" + mDockBottom |
| 1676 | + " mContentBottom=" + mContentBottom |
| 1677 | + " mCurBottom=" + mCurBottom); |
| 1678 | } else { |
| 1679 | // Status bar can't go away; the part of the screen it |
| 1680 | // covers does not exist for anything behind it. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1681 | if (mRestrictedScreenTop == r.top) { |
| 1682 | mRestrictedScreenTop = r.bottom; |
| 1683 | mRestrictedScreenHeight -= (r.bottom-r.top); |
| 1684 | } else if ((mRestrictedScreenHeight-mRestrictedScreenTop) == r.bottom) { |
| 1685 | mRestrictedScreenHeight -= (r.bottom-r.top); |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 1686 | } |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1687 | mContentTop = mCurTop = mDockTop = mRestrictedScreenTop; |
| 1688 | mContentBottom = mCurBottom = mDockBottom |
| 1689 | = mRestrictedScreenTop + mRestrictedScreenHeight; |
| 1690 | if (DEBUG_LAYOUT) Log.v(TAG, "Status bar: mRestrictedScreenTop=" |
| 1691 | + mRestrictedScreenTop |
| 1692 | + " mRestrictedScreenHeight=" + mRestrictedScreenHeight); |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 1693 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1694 | } |
| 1695 | } |
| 1696 | } |
| 1697 | |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 1698 | void setAttachedWindowFrames(WindowState win, int fl, int adjust, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1699 | WindowState attached, boolean insetDecors, Rect pf, Rect df, Rect cf, Rect vf) { |
| 1700 | if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) { |
| 1701 | // Here's a special case: if this attached window is a panel that is |
| 1702 | // above the dock window, and the window it is attached to is below |
| 1703 | // the dock window, then the frames we computed for the window it is |
| 1704 | // attached to can not be used because the dock is effectively part |
| 1705 | // of the underlying window and the attached window is floating on top |
| 1706 | // of the whole thing. So, we ignore the attached window and explicitly |
| 1707 | // compute the frames that would be appropriate without the dock. |
| 1708 | df.left = cf.left = vf.left = mDockLeft; |
| 1709 | df.top = cf.top = vf.top = mDockTop; |
| 1710 | df.right = cf.right = vf.right = mDockRight; |
| 1711 | df.bottom = cf.bottom = vf.bottom = mDockBottom; |
| 1712 | } else { |
| 1713 | // The effective display frame of the attached window depends on |
| 1714 | // whether it is taking care of insetting its content. If not, |
| 1715 | // we need to use the parent's content frame so that the entire |
| 1716 | // window is positioned within that content. Otherwise we can use |
| 1717 | // the display frame and let the attached window take care of |
| 1718 | // positioning its content appropriately. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 1719 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1720 | cf.set(attached.getDisplayFrameLw()); |
| 1721 | } else { |
| 1722 | // If the window is resizing, then we want to base the content |
| 1723 | // frame on our attached content frame to resize... however, |
| 1724 | // things can be tricky if the attached window is NOT in resize |
| 1725 | // mode, in which case its content frame will be larger. |
| 1726 | // Ungh. So to deal with that, make sure the content frame |
| 1727 | // we end up using is not covering the IM dock. |
| 1728 | cf.set(attached.getContentFrameLw()); |
| 1729 | if (attached.getSurfaceLayer() < mDockLayer) { |
| 1730 | if (cf.left < mContentLeft) cf.left = mContentLeft; |
| 1731 | if (cf.top < mContentTop) cf.top = mContentTop; |
| 1732 | if (cf.right > mContentRight) cf.right = mContentRight; |
| 1733 | if (cf.bottom > mContentBottom) cf.bottom = mContentBottom; |
| 1734 | } |
| 1735 | } |
| 1736 | df.set(insetDecors ? attached.getDisplayFrameLw() : cf); |
| 1737 | vf.set(attached.getVisibleFrameLw()); |
| 1738 | } |
| 1739 | // The LAYOUT_IN_SCREEN flag is used to determine whether the attached |
| 1740 | // window should be positioned relative to its parent or the entire |
| 1741 | // screen. |
| 1742 | pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0 |
| 1743 | ? attached.getFrameLw() : df); |
| 1744 | } |
| 1745 | |
| 1746 | /** {@inheritDoc} */ |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 1747 | public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs, |
| 1748 | WindowState attached) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1749 | // we've already done the status bar |
| 1750 | if (win == mStatusBar) { |
| 1751 | return; |
| 1752 | } |
| 1753 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1754 | final int fl = attrs.flags; |
| 1755 | final int sim = attrs.softInputMode; |
| 1756 | |
| 1757 | final Rect pf = mTmpParentFrame; |
| 1758 | final Rect df = mTmpDisplayFrame; |
| 1759 | final Rect cf = mTmpContentFrame; |
| 1760 | final Rect vf = mTmpVisibleFrame; |
| 1761 | |
| 1762 | if (attrs.type == TYPE_INPUT_METHOD) { |
| 1763 | pf.left = df.left = cf.left = vf.left = mDockLeft; |
| 1764 | pf.top = df.top = cf.top = vf.top = mDockTop; |
| 1765 | pf.right = df.right = cf.right = vf.right = mDockRight; |
| 1766 | pf.bottom = df.bottom = cf.bottom = vf.bottom = mDockBottom; |
| 1767 | // IM dock windows always go to the bottom of the screen. |
| 1768 | attrs.gravity = Gravity.BOTTOM; |
| 1769 | mDockLayer = win.getSurfaceLayer(); |
| 1770 | } else { |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 1771 | final int adjust = sim & SOFT_INPUT_MASK_ADJUST; |
| 1772 | |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 1773 | if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_FULLSCREEN | FLAG_LAYOUT_INSET_DECOR)) |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1774 | == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) { |
| 1775 | // This is the case for a normal activity window: we want it |
| 1776 | // to cover all of the screen space, and it can take care of |
| 1777 | // moving its contents to account for screen decorations that |
| 1778 | // intrude into that space. |
| 1779 | if (attached != null) { |
| 1780 | // If this window is attached to another, our display |
| 1781 | // frame is the same as the one we are attached to. |
| 1782 | setAttachedWindowFrames(win, fl, sim, attached, true, pf, df, cf, vf); |
| 1783 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame^] | 1784 | pf.left = df.left = mRestrictedScreenLeft; |
| 1785 | pf.top = df.top = mRestrictedScreenTop; |
| 1786 | pf.right = df.right = mRestrictedScreenLeft+mRestrictedScreenWidth; |
| 1787 | pf.bottom = df.bottom = mRestrictedScreenTop+mRestrictedScreenHeight; |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 1788 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1789 | cf.left = mDockLeft; |
| 1790 | cf.top = mDockTop; |
| 1791 | cf.right = mDockRight; |
| 1792 | cf.bottom = mDockBottom; |
| 1793 | } else { |
| 1794 | cf.left = mContentLeft; |
| 1795 | cf.top = mContentTop; |
| 1796 | cf.right = mContentRight; |
| 1797 | cf.bottom = mContentBottom; |
| 1798 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 1799 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 1800 | vf.left = mCurLeft; |
| 1801 | vf.top = mCurTop; |
| 1802 | vf.right = mCurRight; |
| 1803 | vf.bottom = mCurBottom; |
| 1804 | } else { |
| 1805 | vf.set(cf); |
| 1806 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1807 | } |
Dianne Hackborn | 82de1ae | 2010-10-28 11:28:39 -0700 | [diff] [blame] | 1808 | } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1809 | // A window that has requested to fill the entire screen just |
| 1810 | // gets everything, period. |
Joe Onorato | 29fc2c9 | 2010-11-24 10:26:50 -0800 | [diff] [blame] | 1811 | if (attrs.type == TYPE_STATUS_BAR_PANEL) { |
| 1812 | pf.left = df.left = cf.left = mUnrestrictedScreenLeft; |
| 1813 | pf.top = df.top = cf.top = mUnrestrictedScreenTop; |
| 1814 | pf.right = df.right = cf.right |
| 1815 | = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth; |
| 1816 | pf.bottom = df.bottom = cf.bottom |
| 1817 | = mUnrestrictedScreenTop+mUnrestrictedScreenHeight; |
| 1818 | } else { |
| 1819 | pf.left = df.left = cf.left = mRestrictedScreenLeft; |
| 1820 | pf.top = df.top = cf.top = mRestrictedScreenTop; |
| 1821 | pf.right = df.right = cf.right = mRestrictedScreenLeft+mRestrictedScreenWidth; |
| 1822 | pf.bottom = df.bottom = cf.bottom |
| 1823 | = mRestrictedScreenTop+mRestrictedScreenHeight; |
| 1824 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 1825 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 1826 | vf.left = mCurLeft; |
| 1827 | vf.top = mCurTop; |
| 1828 | vf.right = mCurRight; |
| 1829 | vf.bottom = mCurBottom; |
| 1830 | } else { |
| 1831 | vf.set(cf); |
| 1832 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1833 | } else if (attached != null) { |
| 1834 | // A child window should be placed inside of the same visible |
| 1835 | // frame that its parent had. |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 1836 | setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, cf, vf); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1837 | } else { |
| 1838 | // Otherwise, a normal window must be placed inside the content |
| 1839 | // of all screen decorations. |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame^] | 1840 | if (attrs.type == TYPE_STATUS_BAR_PANEL) { |
| 1841 | // Status bar panels are the only windows who can go on top of |
| 1842 | // the status bar. They are protected by the STATUS_BAR_SERVICE |
| 1843 | // permission, so they have the same privileges as the status |
| 1844 | // bar itself. |
| 1845 | pf.left = df.left = cf.left = vf.left = mUnrestrictedScreenLeft; |
| 1846 | pf.top = df.top = cf.top = vf.top = mUnrestrictedScreenTop; |
| 1847 | pf.right = df.right = cf.right = vf.right |
| 1848 | = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth; |
| 1849 | pf.bottom = df.bottom = cf.bottom = vf.bottom |
| 1850 | = mUnrestrictedScreenTop+mUnrestrictedScreenHeight; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1851 | } else { |
Dianne Hackborn | a239c84 | 2011-06-01 12:28:20 -0700 | [diff] [blame^] | 1852 | pf.left = mContentLeft; |
| 1853 | pf.top = mContentTop; |
| 1854 | pf.right = mContentRight; |
| 1855 | pf.bottom = mContentBottom; |
| 1856 | if (adjust != SOFT_INPUT_ADJUST_RESIZE) { |
| 1857 | df.left = cf.left = mDockLeft; |
| 1858 | df.top = cf.top = mDockTop; |
| 1859 | df.right = cf.right = mDockRight; |
| 1860 | df.bottom = cf.bottom = mDockBottom; |
| 1861 | } else { |
| 1862 | df.left = cf.left = mContentLeft; |
| 1863 | df.top = cf.top = mContentTop; |
| 1864 | df.right = cf.right = mContentRight; |
| 1865 | df.bottom = cf.bottom = mContentBottom; |
| 1866 | } |
| 1867 | if (adjust != SOFT_INPUT_ADJUST_NOTHING) { |
| 1868 | vf.left = mCurLeft; |
| 1869 | vf.top = mCurTop; |
| 1870 | vf.right = mCurRight; |
| 1871 | vf.bottom = mCurBottom; |
| 1872 | } else { |
| 1873 | vf.set(cf); |
| 1874 | } |
Dianne Hackborn | dea3ef7 | 2010-10-28 14:24:22 -0700 | [diff] [blame] | 1875 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0) { |
| 1880 | df.left = df.top = cf.left = cf.top = vf.left = vf.top = -10000; |
| 1881 | df.right = df.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000; |
| 1882 | } |
| 1883 | |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 1884 | if (DEBUG_LAYOUT) Log.v(TAG, "Compute frame " + attrs.getTitle() |
| 1885 | + ": sim=#" + Integer.toHexString(sim) |
| 1886 | + " pf=" + pf.toShortString() + " df=" + df.toShortString() |
| 1887 | + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()); |
| 1888 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1889 | win.computeFrameLw(pf, df, cf, vf); |
| 1890 | |
| 1891 | // Dock windows carve out the bottom of the screen, so normal windows |
| 1892 | // can't appear underneath them. |
| 1893 | if (attrs.type == TYPE_INPUT_METHOD && !win.getGivenInsetsPendingLw()) { |
| 1894 | int top = win.getContentFrameLw().top; |
| 1895 | top += win.getGivenContentInsetsLw().top; |
| 1896 | if (mContentBottom > top) { |
| 1897 | mContentBottom = top; |
| 1898 | } |
| 1899 | top = win.getVisibleFrameLw().top; |
| 1900 | top += win.getGivenVisibleInsetsLw().top; |
| 1901 | if (mCurBottom > top) { |
| 1902 | mCurBottom = top; |
| 1903 | } |
The Android Open Source Project | 1126766 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 1904 | if (DEBUG_LAYOUT) Log.v(TAG, "Input method: mDockBottom=" |
| 1905 | + mDockBottom + " mContentBottom=" |
| 1906 | + mContentBottom + " mCurBottom=" + mCurBottom); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1907 | } |
| 1908 | } |
| 1909 | |
| 1910 | /** {@inheritDoc} */ |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1911 | public int finishLayoutLw() { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 1912 | return 0; |
| 1913 | } |
| 1914 | |
| 1915 | /** {@inheritDoc} */ |
| 1916 | public void beginAnimationLw(int displayWidth, int displayHeight) { |
| 1917 | mTopFullscreenOpaqueWindowState = null; |
| 1918 | mForceStatusBar = false; |
| 1919 | |
| 1920 | mHideLockScreen = false; |
| 1921 | mAllowLockscreenWhenOn = false; |
| 1922 | mDismissKeyguard = false; |
| 1923 | } |
| 1924 | |
| 1925 | /** {@inheritDoc} */ |
| 1926 | public void animatingWindowLw(WindowState win, |
| 1927 | WindowManager.LayoutParams attrs) { |
| 1928 | if (mTopFullscreenOpaqueWindowState == null && |
| 1929 | win.isVisibleOrBehindKeyguardLw()) { |
| 1930 | if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) { |
| 1931 | mForceStatusBar = true; |
| 1932 | } |
| 1933 | if (attrs.type >= FIRST_APPLICATION_WINDOW |
| 1934 | && attrs.type <= LAST_APPLICATION_WINDOW |
Dianne Hackborn | 6493e64 | 2010-10-01 13:06:30 -0700 | [diff] [blame] | 1935 | && attrs.x == 0 && attrs.y == 0 |
| 1936 | && attrs.width == WindowManager.LayoutParams.MATCH_PARENT |
| 1937 | && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) { |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 1938 | if (DEBUG_LAYOUT) Log.v(TAG, "Fullscreen window: " + win); |
| 1939 | mTopFullscreenOpaqueWindowState = win; |
| 1940 | if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) { |
| 1941 | if (localLOGV) Log.v(TAG, "Setting mHideLockScreen to true by win " + win); |
| 1942 | mHideLockScreen = true; |
| 1943 | } |
| 1944 | if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0) { |
| 1945 | if (localLOGV) Log.v(TAG, "Setting mDismissKeyguard to true by win " + win); |
| 1946 | mDismissKeyguard = true; |
| 1947 | } |
| 1948 | if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) { |
| 1949 | mAllowLockscreenWhenOn = true; |
| 1950 | } |
| 1951 | } |
| 1952 | } |
| 1953 | } |
| 1954 | |
| 1955 | /** {@inheritDoc} */ |
| 1956 | public int finishAnimationLw() { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1957 | int changes = 0; |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 1958 | boolean topIsFullscreen = false; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 1959 | |
| 1960 | final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null) |
| 1961 | ? mTopFullscreenOpaqueWindowState.getAttrs() |
| 1962 | : null; |
| 1963 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1964 | if (mStatusBar != null) { |
Dianne Hackborn | d70bc2f | 2009-10-06 23:25:51 -0700 | [diff] [blame] | 1965 | if (localLOGV) Log.i(TAG, "force=" + mForceStatusBar |
| 1966 | + " top=" + mTopFullscreenOpaqueWindowState); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1967 | if (mForceStatusBar) { |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 1968 | if (DEBUG_LAYOUT) Log.v(TAG, "Showing status bar"); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1969 | if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1970 | } else if (mTopFullscreenOpaqueWindowState != null) { |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 1971 | if (localLOGV) { |
| 1972 | Log.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw() |
| 1973 | + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw()); |
| 1974 | Log.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs() |
| 1975 | + " lp.flags=0x" + Integer.toHexString(lp.flags)); |
| 1976 | } |
| 1977 | topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0; |
| 1978 | // The subtle difference between the window for mTopFullscreenOpaqueWindowState |
| 1979 | // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window |
| 1980 | // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the |
| 1981 | // case though. |
| 1982 | if (topIsFullscreen) { |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 1983 | if (mStatusBarCanHide) { |
| 1984 | if (DEBUG_LAYOUT) Log.v(TAG, "Hiding status bar"); |
| 1985 | if (mStatusBar.hideLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT; |
Daniel Sandler | 4042744 | 2010-07-16 11:44:52 -0400 | [diff] [blame] | 1986 | } else if (localLOGV) { |
| 1987 | Log.v(TAG, "Preventing status bar from hiding by policy"); |
| 1988 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1989 | } else { |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 1990 | if (DEBUG_LAYOUT) Log.v(TAG, "Showing status bar"); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 1991 | if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 1992 | } |
| 1993 | } |
| 1994 | } |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 1995 | |
| 1996 | boolean topNeedsMenu = mShowMenuKey; |
| 1997 | if (lp != null) { |
| 1998 | topNeedsMenu = (lp.flags & WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0; |
| 1999 | } |
| 2000 | |
| 2001 | if (DEBUG_LAYOUT) Log.v(TAG, "Top window " |
| 2002 | + (topNeedsMenu ? "needs" : "does not need") |
| 2003 | + " the MENU key"); |
| 2004 | |
Joe Onorato | 644f9c3 | 2011-01-25 12:06:23 -0800 | [diff] [blame] | 2005 | mTopIsFullscreen = topIsFullscreen; |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 2006 | final boolean changedMenu = (topNeedsMenu != mShowMenuKey); |
| 2007 | |
Joe Onorato | 644f9c3 | 2011-01-25 12:06:23 -0800 | [diff] [blame] | 2008 | if (changedMenu) { |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 2009 | final boolean topNeedsMenuF = topNeedsMenu; |
| 2010 | |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 2011 | mShowMenuKey = topNeedsMenu; |
| 2012 | |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 2013 | mHandler.post(new Runnable() { |
| 2014 | public void run() { |
| 2015 | if (mStatusBarService == null) { |
| 2016 | // This is the one that can not go away, but it doesn't come up |
| 2017 | // before the window manager does, so don't fail if it doesn't |
| 2018 | // exist. This works as long as no fullscreen windows come up |
| 2019 | // before the status bar service does. |
| 2020 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 2021 | ServiceManager.getService("statusbar")); |
| 2022 | } |
| 2023 | final IStatusBarService sbs = mStatusBarService; |
| 2024 | if (mStatusBarService != null) { |
| 2025 | try { |
Daniel Sandler | e02d808 | 2010-10-08 15:13:22 -0400 | [diff] [blame] | 2026 | if (changedMenu) { |
| 2027 | sbs.setMenuKeyVisible(topNeedsMenuF); |
| 2028 | } |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 2029 | } catch (RemoteException e) { |
| 2030 | // This should be impossible because we're in the same process. |
| 2031 | mStatusBarService = null; |
| 2032 | } |
| 2033 | } |
| 2034 | } |
| 2035 | }); |
Dianne Hackborn | 5f3063e | 2010-03-10 16:01:58 -0800 | [diff] [blame] | 2036 | } |
| 2037 | |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 2038 | // Hide the key guard if a visible window explicitly specifies that it wants to be displayed |
| 2039 | // when the screen is locked |
| 2040 | if (mKeyguard != null) { |
Joe Onorato | 9305647 | 2010-09-10 10:30:46 -0400 | [diff] [blame] | 2041 | if (localLOGV) Log.v(TAG, "finishAnimationLw::mHideKeyguard="+mHideLockScreen); |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 2042 | if (mDismissKeyguard && !mKeyguardMediator.isSecure()) { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2043 | if (mKeyguard.hideLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2044 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 2045 | | FINISH_LAYOUT_REDO_CONFIG |
| 2046 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 2047 | } |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 2048 | if (mKeyguardMediator.isShowing()) { |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 2049 | mHandler.post(new Runnable() { |
| 2050 | public void run() { |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 2051 | mKeyguardMediator.keyguardDone(false, false); |
Dianne Hackborn | b446e97 | 2009-09-20 15:23:25 -0700 | [diff] [blame] | 2052 | } |
| 2053 | }); |
| 2054 | } |
Dianne Hackborn | 0572658 | 2009-09-22 17:28:24 -0700 | [diff] [blame] | 2055 | } else if (mHideLockScreen) { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2056 | if (mKeyguard.hideLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2057 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 2058 | | FINISH_LAYOUT_REDO_CONFIG |
| 2059 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 2060 | } |
Mike Lockwood | f3bfed5 | 2010-01-21 16:38:44 -0500 | [diff] [blame] | 2061 | mKeyguardMediator.setHidden(true); |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 2062 | } else { |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2063 | if (mKeyguard.showLw(true)) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2064 | changes |= FINISH_LAYOUT_REDO_LAYOUT |
| 2065 | | FINISH_LAYOUT_REDO_CONFIG |
| 2066 | | FINISH_LAYOUT_REDO_WALLPAPER; |
| 2067 | } |
Mike Lockwood | f3bfed5 | 2010-01-21 16:38:44 -0500 | [diff] [blame] | 2068 | mKeyguardMediator.setHidden(false); |
Suchi Amalapurapu | 9cdc903 | 2009-05-14 18:01:07 -0700 | [diff] [blame] | 2069 | } |
| 2070 | } |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2071 | |
| 2072 | updateSystemUiVisibility(); |
| 2073 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 2074 | // update since mAllowLockscreenWhenOn might have changed |
| 2075 | updateLockScreenTimeout(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2076 | return changes; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2077 | } |
| 2078 | |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2079 | public boolean allowAppAnimationsLw() { |
| 2080 | if (mKeyguard != null && mKeyguard.isVisibleLw()) { |
| 2081 | // If keyguard is currently visible, no reason to animate |
| 2082 | // behind it. |
| 2083 | return false; |
| 2084 | } |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 2085 | if (false) { |
| 2086 | // Don't do this on the tablet, since the system bar never completely |
| 2087 | // covers the screen, and with all its transparency this will |
| 2088 | // incorrectly think it does cover it when it doesn't. We'll revisit |
| 2089 | // this later when we re-do the phone status bar. |
| 2090 | if (mStatusBar != null && mStatusBar.isVisibleLw()) { |
| 2091 | Rect rect = new Rect(mStatusBar.getShownFrameLw()); |
| 2092 | for (int i=mStatusBarPanels.size()-1; i>=0; i--) { |
| 2093 | WindowState w = mStatusBarPanels.get(i); |
| 2094 | if (w.isVisibleLw()) { |
| 2095 | rect.union(w.getShownFrameLw()); |
| 2096 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2097 | } |
Dianne Hackborn | 08121bc | 2011-01-17 17:54:31 -0800 | [diff] [blame] | 2098 | final int insetw = mRestrictedScreenWidth/10; |
| 2099 | final int inseth = mRestrictedScreenHeight/10; |
| 2100 | if (rect.contains(insetw, inseth, mRestrictedScreenWidth-insetw, |
| 2101 | mRestrictedScreenHeight-inseth)) { |
| 2102 | // All of the status bar windows put together cover the |
| 2103 | // screen, so the app can't be seen. (Note this test doesn't |
| 2104 | // work if the rects of these windows are at off offsets or |
| 2105 | // sizes, causing gaps in the rect union we have computed.) |
| 2106 | return false; |
| 2107 | } |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2108 | } |
| 2109 | } |
| 2110 | return true; |
| 2111 | } |
| 2112 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 2113 | public void focusChanged(WindowState lastFocus, WindowState newFocus) { |
| 2114 | mFocusedWindow = newFocus; |
| 2115 | updateSystemUiVisibility(); |
| 2116 | } |
| 2117 | |
Dianne Hackborn | 0ecadf7 | 2009-03-31 18:00:37 -0700 | [diff] [blame] | 2118 | /** {@inheritDoc} */ |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2119 | public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) { |
| 2120 | // lid changed state |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 2121 | mLidOpen = lidOpen ? LID_OPEN : LID_CLOSED; |
| 2122 | boolean awakeNow = mKeyguardMediator.doLidChangeTq(lidOpen); |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2123 | updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| 2124 | if (awakeNow) { |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 2125 | // If the lid is opening and we don't have to keep the |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2126 | // keyguard up, then we can turn on the screen |
| 2127 | // immediately. |
| 2128 | mKeyguardMediator.pokeWakelock(); |
| 2129 | } else if (keyguardIsShowingTq()) { |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 2130 | if (lidOpen) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2131 | // If we are opening the lid and not hiding the |
| 2132 | // keyguard, then we need to have it turn on the |
| 2133 | // screen once it is shown. |
| 2134 | mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq( |
| 2135 | KeyEvent.KEYCODE_POWER); |
| 2136 | } |
| 2137 | } else { |
| 2138 | // Light up the keyboard if we are sliding up. |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 2139 | if (lidOpen) { |
Jeff Brown | 46b9ac0 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 2140 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 2141 | LocalPowerManager.BUTTON_EVENT); |
| 2142 | } else { |
| 2143 | mPowerManager.userActivity(SystemClock.uptimeMillis(), false, |
| 2144 | LocalPowerManager.OTHER_EVENT); |
| 2145 | } |
| 2146 | } |
| 2147 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2148 | |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 2149 | void setHdmiPlugged(boolean plugged) { |
| 2150 | if (mHdmiPlugged != plugged) { |
| 2151 | mHdmiPlugged = plugged; |
| 2152 | updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
| 2153 | Intent intent = new Intent(ACTION_HDMI_PLUGGED); |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 2154 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 2155 | intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged); |
| 2156 | mContext.sendStickyBroadcast(intent); |
| 2157 | } |
| 2158 | } |
| 2159 | |
Joe Onorato | dc10030 | 2011-01-11 17:07:41 -0800 | [diff] [blame] | 2160 | boolean readHdmiState() { |
| 2161 | final String filename = "/sys/class/switch/hdmi/state"; |
| 2162 | FileReader reader = null; |
| 2163 | try { |
| 2164 | reader = new FileReader(filename); |
| 2165 | char[] buf = new char[15]; |
| 2166 | int n = reader.read(buf); |
| 2167 | if (n > 1) { |
| 2168 | return 0 != Integer.parseInt(new String(buf, 0, n-1)); |
| 2169 | } else { |
| 2170 | return false; |
| 2171 | } |
| 2172 | } catch (IOException ex) { |
| 2173 | Slog.d(TAG, "couldn't read hdmi state from " + filename + ": " + ex); |
| 2174 | return false; |
| 2175 | } catch (NumberFormatException ex) { |
| 2176 | Slog.d(TAG, "couldn't read hdmi state from " + filename + ": " + ex); |
| 2177 | return false; |
| 2178 | } finally { |
| 2179 | if (reader != null) { |
| 2180 | try { |
| 2181 | reader.close(); |
| 2182 | } catch (IOException ex) { |
| 2183 | } |
| 2184 | } |
| 2185 | } |
| 2186 | } |
| 2187 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2188 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2189 | * @return Whether music is being played right now. |
| 2190 | */ |
| 2191 | boolean isMusicActive() { |
Eric Laurent | 413cb9d | 2009-07-17 11:52:43 -0700 | [diff] [blame] | 2192 | final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE); |
| 2193 | if (am == null) { |
| 2194 | Log.w(TAG, "isMusicActive: couldn't get AudioManager reference"); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2195 | return false; |
| 2196 | } |
Eric Laurent | 413cb9d | 2009-07-17 11:52:43 -0700 | [diff] [blame] | 2197 | return am.isMusicActive(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | /** |
| 2201 | * Tell the audio service to adjust the volume appropriate to the event. |
| 2202 | * @param keycode |
| 2203 | */ |
Mike Lockwood | a53e381 | 2009-09-25 10:51:39 -0400 | [diff] [blame] | 2204 | void handleVolumeKey(int stream, int keycode) { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2205 | IAudioService audioService = getAudioService(); |
| 2206 | if (audioService == null) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2207 | return; |
| 2208 | } |
| 2209 | try { |
| 2210 | // since audio is playing, we shouldn't have to hold a wake lock |
| 2211 | // during the call, but we do it as a precaution for the rare possibility |
| 2212 | // that the music stops right before we call this |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 2213 | // TODO: Actually handle MUTE. |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2214 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2215 | audioService.adjustStreamVolume(stream, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2216 | keycode == KeyEvent.KEYCODE_VOLUME_UP |
| 2217 | ? AudioManager.ADJUST_RAISE |
| 2218 | : AudioManager.ADJUST_LOWER, |
| 2219 | 0); |
| 2220 | } catch (RemoteException e) { |
| 2221 | Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e); |
| 2222 | } finally { |
| 2223 | mBroadcastWakeLock.release(); |
| 2224 | } |
| 2225 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2226 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2227 | /** {@inheritDoc} */ |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2228 | @Override |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2229 | public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) { |
| 2230 | final boolean down = event.getAction() == KeyEvent.ACTION_DOWN; |
| 2231 | final boolean canceled = event.isCanceled(); |
| 2232 | final int keyCode = event.getKeyCode(); |
Jeff Brown | e20c9e0 | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 2233 | |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 2234 | final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0; |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 2235 | |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 2236 | // If screen is off then we treat the case where the keyguard is open but hidden |
| 2237 | // the same as if it were open and in front. |
| 2238 | // This will prevent any keys other than the power button from waking the screen |
| 2239 | // when the keyguard is hidden by another activity. |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2240 | final boolean keyguardActive = (isScreenOn ? |
Mike Lockwood | c72b15f | 2009-11-28 20:58:22 -0500 | [diff] [blame] | 2241 | mKeyguardMediator.isShowingAndNotHidden() : |
| 2242 | mKeyguardMediator.isShowing()); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2243 | |
| 2244 | if (false) { |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2245 | Log.d(TAG, "interceptKeyTq keycode=" + keyCode |
| 2246 | + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2247 | } |
| 2248 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2249 | if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0) { |
| 2250 | performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false); |
| 2251 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2252 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2253 | // Basic policy based on screen state and keyguard. |
| 2254 | // FIXME: This policy isn't quite correct. We shouldn't care whether the screen |
| 2255 | // is on or off, really. We should care about whether the device is in an |
| 2256 | // interactive state or is in suspend pretending to be "off". |
| 2257 | // The primary screen might be turned off due to proximity sensor or |
| 2258 | // because we are presenting media on an auxiliary screen or remotely controlling |
| 2259 | // the device some other way (which is why we have an exemption here for injected |
| 2260 | // events). |
| 2261 | int result; |
| 2262 | if (isScreenOn || isInjected) { |
| 2263 | // When the screen is on or if the key is injected pass the key to the application. |
| 2264 | result = ACTION_PASS_TO_USER; |
| 2265 | } else { |
| 2266 | // When the screen is off and the key is not injected, determine whether |
| 2267 | // to wake the device but don't pass the key to the application. |
| 2268 | result = 0; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2269 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2270 | final boolean isWakeKey = (policyFlags |
| 2271 | & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0; |
| 2272 | if (down && isWakeKey) { |
| 2273 | if (keyguardActive) { |
| 2274 | // If the keyguard is showing, let it decide what to do with the wake key. |
| 2275 | mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode); |
| 2276 | } else { |
| 2277 | // Otherwise, wake the device ourselves. |
| 2278 | result |= ACTION_POKE_USER_ACTIVITY; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2279 | } |
| 2280 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2281 | } |
| 2282 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2283 | // Handle special keys. |
| 2284 | switch (keyCode) { |
| 2285 | case KeyEvent.KEYCODE_VOLUME_DOWN: |
Jeff Brown | b0418da | 2010-11-01 15:24:01 -0700 | [diff] [blame] | 2286 | case KeyEvent.KEYCODE_VOLUME_UP: |
| 2287 | case KeyEvent.KEYCODE_VOLUME_MUTE: { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2288 | if (down) { |
| 2289 | ITelephony telephonyService = getTelephonyService(); |
| 2290 | if (telephonyService != null) { |
| 2291 | try { |
| 2292 | if (telephonyService.isRinging()) { |
| 2293 | // If an incoming call is ringing, either VOLUME key means |
| 2294 | // "silence ringer". We handle these keys here, rather than |
| 2295 | // in the InCallScreen, to make sure we'll respond to them |
| 2296 | // even if the InCallScreen hasn't come to the foreground yet. |
| 2297 | // Look for the DOWN event here, to agree with the "fallback" |
| 2298 | // behavior in the InCallScreen. |
| 2299 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 2300 | + " VOLUME key-down while ringing: Silence ringer!"); |
| 2301 | |
| 2302 | // Silence the ringer. (It's safe to call this |
| 2303 | // even if the ringer has already been silenced.) |
| 2304 | telephonyService.silenceRinger(); |
| 2305 | |
| 2306 | // And *don't* pass this key thru to the current activity |
| 2307 | // (which is probably the InCallScreen.) |
| 2308 | result &= ~ACTION_PASS_TO_USER; |
| 2309 | break; |
| 2310 | } |
| 2311 | if (telephonyService.isOffhook() |
| 2312 | && (result & ACTION_PASS_TO_USER) == 0) { |
| 2313 | // If we are in call but we decided not to pass the key to |
| 2314 | // the application, handle the volume change here. |
| 2315 | handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode); |
| 2316 | break; |
| 2317 | } |
| 2318 | } catch (RemoteException ex) { |
| 2319 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 2320 | } |
| 2321 | } |
| 2322 | |
| 2323 | if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) { |
| 2324 | // If music is playing but we decided not to pass the key to the |
| 2325 | // application, handle the volume change here. |
| 2326 | handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode); |
| 2327 | break; |
| 2328 | } |
| 2329 | } |
| 2330 | break; |
| 2331 | } |
| 2332 | |
| 2333 | case KeyEvent.KEYCODE_ENDCALL: { |
| 2334 | result &= ~ACTION_PASS_TO_USER; |
| 2335 | if (down) { |
| 2336 | ITelephony telephonyService = getTelephonyService(); |
| 2337 | boolean hungUp = false; |
| 2338 | if (telephonyService != null) { |
| 2339 | try { |
| 2340 | hungUp = telephonyService.endCall(); |
| 2341 | } catch (RemoteException ex) { |
| 2342 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 2343 | } |
| 2344 | } |
| 2345 | interceptPowerKeyDown(!isScreenOn || hungUp); |
| 2346 | } else { |
| 2347 | if (interceptPowerKeyUp(canceled)) { |
| 2348 | if ((mEndcallBehavior |
| 2349 | & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) { |
| 2350 | if (goHome()) { |
| 2351 | break; |
Dianne Hackborn | 0041e97 | 2009-07-24 17:14:43 -0700 | [diff] [blame] | 2352 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2353 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2354 | if ((mEndcallBehavior |
| 2355 | & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) { |
| 2356 | result = (result & ~ACTION_POKE_USER_ACTIVITY) | ACTION_GO_TO_SLEEP; |
| 2357 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2358 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2359 | } |
| 2360 | break; |
| 2361 | } |
| 2362 | |
| 2363 | case KeyEvent.KEYCODE_POWER: { |
| 2364 | result &= ~ACTION_PASS_TO_USER; |
| 2365 | if (down) { |
| 2366 | ITelephony telephonyService = getTelephonyService(); |
| 2367 | boolean hungUp = false; |
| 2368 | if (telephonyService != null) { |
| 2369 | try { |
| 2370 | if (telephonyService.isRinging()) { |
| 2371 | // Pressing Power while there's a ringing incoming |
| 2372 | // call should silence the ringer. |
| 2373 | telephonyService.silenceRinger(); |
| 2374 | } else if ((mIncallPowerBehavior |
| 2375 | & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0 |
| 2376 | && telephonyService.isOffhook()) { |
| 2377 | // Otherwise, if "Power button ends call" is enabled, |
| 2378 | // the Power button will hang up any current active call. |
| 2379 | hungUp = telephonyService.endCall(); |
| 2380 | } |
| 2381 | } catch (RemoteException ex) { |
| 2382 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
| 2383 | } |
| 2384 | } |
| 2385 | interceptPowerKeyDown(!isScreenOn || hungUp); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2386 | } else { |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2387 | if (interceptPowerKeyUp(canceled)) { |
| 2388 | result = (result & ~ACTION_POKE_USER_ACTIVITY) | ACTION_GO_TO_SLEEP; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2389 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2390 | } |
| 2391 | break; |
| 2392 | } |
| 2393 | |
| 2394 | case KeyEvent.KEYCODE_MEDIA_PLAY: |
| 2395 | case KeyEvent.KEYCODE_MEDIA_PAUSE: |
| 2396 | case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: |
| 2397 | if (down) { |
| 2398 | ITelephony telephonyService = getTelephonyService(); |
| 2399 | if (telephonyService != null) { |
| 2400 | try { |
| 2401 | if (!telephonyService.isIdle()) { |
| 2402 | // Suppress PLAY/PAUSE toggle when phone is ringing or in-call |
| 2403 | // to avoid music playback. |
| 2404 | break; |
| 2405 | } |
| 2406 | } catch (RemoteException ex) { |
| 2407 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
Jeff Brown | 3122e44 | 2010-10-11 23:32:49 -0700 | [diff] [blame] | 2408 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2409 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2410 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2411 | case KeyEvent.KEYCODE_HEADSETHOOK: |
| 2412 | case KeyEvent.KEYCODE_MUTE: |
| 2413 | case KeyEvent.KEYCODE_MEDIA_STOP: |
| 2414 | case KeyEvent.KEYCODE_MEDIA_NEXT: |
| 2415 | case KeyEvent.KEYCODE_MEDIA_PREVIOUS: |
| 2416 | case KeyEvent.KEYCODE_MEDIA_REWIND: |
| 2417 | case KeyEvent.KEYCODE_MEDIA_RECORD: |
| 2418 | case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: { |
| 2419 | if ((result & ACTION_PASS_TO_USER) == 0) { |
| 2420 | // Only do this if we would otherwise not pass it to the user. In that |
| 2421 | // case, the PhoneWindow class will do the same thing, except it will |
| 2422 | // only do it if the showing app doesn't process the key on its own. |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2423 | mBroadcastWakeLock.acquire(); |
Jeff Brown | 1f24510 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 2424 | mHandler.post(new PassHeadsetKey(new KeyEvent(event))); |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2425 | } |
| 2426 | break; |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2427 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2428 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2429 | case KeyEvent.KEYCODE_CALL: { |
| 2430 | if (down) { |
| 2431 | ITelephony telephonyService = getTelephonyService(); |
| 2432 | if (telephonyService != null) { |
| 2433 | try { |
| 2434 | if (telephonyService.isRinging()) { |
| 2435 | Log.i(TAG, "interceptKeyBeforeQueueing:" |
| 2436 | + " CALL key-down while ringing: Answer the call!"); |
| 2437 | telephonyService.answerRingingCall(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2438 | |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2439 | // And *don't* pass this key thru to the current activity |
| 2440 | // (which is presumably the InCallScreen.) |
| 2441 | result &= ~ACTION_PASS_TO_USER; |
| 2442 | } |
| 2443 | } catch (RemoteException ex) { |
| 2444 | Log.w(TAG, "ITelephony threw RemoteException", ex); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2445 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2446 | } |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2447 | } |
Jeff Brown | 4d39605 | 2010-10-29 21:50:21 -0700 | [diff] [blame] | 2448 | break; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2449 | } |
| 2450 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2451 | return result; |
| 2452 | } |
| 2453 | |
Jeff Brown | 56194eb | 2011-03-02 19:23:13 -0800 | [diff] [blame] | 2454 | /** {@inheritDoc} */ |
| 2455 | @Override |
| 2456 | public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) { |
| 2457 | int result = 0; |
| 2458 | |
| 2459 | final boolean isWakeMotion = (policyFlags |
| 2460 | & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0; |
| 2461 | if (isWakeMotion) { |
| 2462 | if (mKeyguardMediator.isShowing()) { |
| 2463 | // If the keyguard is showing, let it decide what to do with the wake motion. |
| 2464 | mKeyguardMediator.onWakeMotionWhenKeyguardShowingTq(); |
| 2465 | } else { |
| 2466 | // Otherwise, wake the device ourselves. |
| 2467 | result |= ACTION_POKE_USER_ACTIVITY; |
| 2468 | } |
| 2469 | } |
| 2470 | return result; |
| 2471 | } |
| 2472 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2473 | class PassHeadsetKey implements Runnable { |
| 2474 | KeyEvent mKeyEvent; |
| 2475 | |
| 2476 | PassHeadsetKey(KeyEvent keyEvent) { |
| 2477 | mKeyEvent = keyEvent; |
| 2478 | } |
| 2479 | |
| 2480 | public void run() { |
| 2481 | if (ActivityManagerNative.isSystemReady()) { |
| 2482 | Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON, null); |
| 2483 | intent.putExtra(Intent.EXTRA_KEY_EVENT, mKeyEvent); |
| 2484 | mContext.sendOrderedBroadcast(intent, null, mBroadcastDone, |
| 2485 | mHandler, Activity.RESULT_OK, null, null); |
| 2486 | } |
| 2487 | } |
| 2488 | } |
| 2489 | |
| 2490 | BroadcastReceiver mBroadcastDone = new BroadcastReceiver() { |
| 2491 | public void onReceive(Context context, Intent intent) { |
| 2492 | mBroadcastWakeLock.release(); |
| 2493 | } |
| 2494 | }; |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2495 | |
| 2496 | BroadcastReceiver mDockReceiver = new BroadcastReceiver() { |
| 2497 | public void onReceive(Context context, Intent intent) { |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2498 | if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) { |
| 2499 | mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, |
| 2500 | Intent.EXTRA_DOCK_STATE_UNDOCKED); |
| 2501 | } else { |
| 2502 | try { |
| 2503 | IUiModeManager uiModeService = IUiModeManager.Stub.asInterface( |
| 2504 | ServiceManager.getService(Context.UI_MODE_SERVICE)); |
| 2505 | mUiMode = uiModeService.getCurrentModeType(); |
| 2506 | } catch (RemoteException e) { |
| 2507 | } |
Dianne Hackborn | 80fa166 | 2009-10-07 14:02:10 -0700 | [diff] [blame] | 2508 | } |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2509 | updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
Mike Lockwood | e9867d2 | 2009-09-20 01:59:02 -0400 | [diff] [blame] | 2510 | updateOrientationListenerLp(); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2511 | } |
| 2512 | }; |
| 2513 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2514 | /** {@inheritDoc} */ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2515 | public void screenTurnedOff(int why) { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 2516 | EventLog.writeEvent(70000, 0); |
| 2517 | mKeyguardMediator.onScreenTurnedOff(why); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2518 | synchronized (mLock) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2519 | mScreenOn = false; |
| 2520 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 2521 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2522 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2523 | } |
| 2524 | |
| 2525 | /** {@inheritDoc} */ |
| 2526 | public void screenTurnedOn() { |
Dianne Hackborn | 7448901 | 2009-03-24 20:50:09 -0700 | [diff] [blame] | 2527 | EventLog.writeEvent(70000, 1); |
| 2528 | mKeyguardMediator.onScreenTurnedOn(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2529 | synchronized (mLock) { |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2530 | mScreenOn = true; |
| 2531 | updateOrientationListenerLp(); |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 2532 | updateLockScreenTimeout(); |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2533 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | /** {@inheritDoc} */ |
Dianne Hackborn | 0874372 | 2009-12-21 12:16:51 -0800 | [diff] [blame] | 2537 | public boolean isScreenOn() { |
| 2538 | return mScreenOn; |
| 2539 | } |
| 2540 | |
| 2541 | /** {@inheritDoc} */ |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2542 | public void enableKeyguard(boolean enabled) { |
| 2543 | mKeyguardMediator.setKeyguardEnabled(enabled); |
| 2544 | } |
| 2545 | |
| 2546 | /** {@inheritDoc} */ |
| 2547 | public void exitKeyguardSecurely(OnKeyguardExitResult callback) { |
| 2548 | mKeyguardMediator.verifyUnlock(callback); |
| 2549 | } |
| 2550 | |
Mike Lockwood | f791330 | 2009-11-28 22:27:10 -0500 | [diff] [blame] | 2551 | private boolean keyguardIsShowingTq() { |
Dianne Hackborn | 9dc06cc | 2009-11-17 18:19:23 -0800 | [diff] [blame] | 2552 | return mKeyguardMediator.isShowingAndNotHidden(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2553 | } |
| 2554 | |
Mike Lockwood | 520d8bc | 2011-02-18 13:23:13 -0500 | [diff] [blame] | 2555 | |
| 2556 | /** {@inheritDoc} */ |
| 2557 | public boolean isKeyguardLocked() { |
| 2558 | return keyguardOn(); |
| 2559 | } |
| 2560 | |
| 2561 | /** {@inheritDoc} */ |
| 2562 | public boolean isKeyguardSecure() { |
| 2563 | return mKeyguardMediator.isSecure(); |
| 2564 | } |
| 2565 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2566 | /** {@inheritDoc} */ |
| 2567 | public boolean inKeyguardRestrictedKeyInputMode() { |
| 2568 | return mKeyguardMediator.isInputRestricted(); |
| 2569 | } |
| 2570 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2571 | void sendCloseSystemWindows() { |
| 2572 | sendCloseSystemWindows(mContext, null); |
| 2573 | } |
| 2574 | |
| 2575 | void sendCloseSystemWindows(String reason) { |
| 2576 | sendCloseSystemWindows(mContext, reason); |
| 2577 | } |
| 2578 | |
| 2579 | static void sendCloseSystemWindows(Context context, String reason) { |
| 2580 | if (ActivityManagerNative.isSystemReady()) { |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 2581 | try { |
| 2582 | ActivityManagerNative.getDefault().closeSystemDialogs(reason); |
| 2583 | } catch (RemoteException e) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2584 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2585 | } |
| 2586 | } |
Dianne Hackborn | 2973568 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2587 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2588 | public int rotationForOrientationLw(int orientation, int lastRotation, |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2589 | boolean displayEnabled) { |
Mitsuru Oshima | 831d0d9 | 2009-06-16 18:27:18 -0700 | [diff] [blame] | 2590 | |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 2591 | if (false) { |
| 2592 | Slog.v(TAG, "rotationForOrientationLw(orient=" |
| 2593 | + orientation + ", last=" + lastRotation |
| 2594 | + "); user=" + mUserRotation + " " |
| 2595 | + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) |
| 2596 | ? "USER_ROTATION_LOCKED" : "") |
| 2597 | ); |
| 2598 | } |
| 2599 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2600 | synchronized (mLock) { |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 2601 | switch (orientation) { |
| 2602 | case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT: |
| 2603 | //always return portrait if orientation set to portrait |
| 2604 | return mPortraitRotation; |
| 2605 | case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE: |
| 2606 | //always return landscape if orientation set to landscape |
| 2607 | return mLandscapeRotation; |
| 2608 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT: |
| 2609 | //always return portrait if orientation set to portrait |
| 2610 | return mUpsideDownRotation; |
| 2611 | case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE: |
| 2612 | //always return seascape if orientation set to reverse landscape |
| 2613 | return mSeascapeRotation; |
| 2614 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE: |
| 2615 | //return either landscape rotation based on the sensor |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 2616 | return getCurrentLandscapeRotation(lastRotation); |
| 2617 | case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT: |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 2618 | return getCurrentPortraitRotation(lastRotation); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2619 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 2620 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2621 | // case for nosensor meaning ignore sensor and consider only lid |
| 2622 | // or orientation sensor disabled |
| 2623 | //or case.unspecified |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 2624 | if (mHdmiPlugged) { |
| 2625 | return Surface.ROTATION_0; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 2626 | } else if (mLidOpen == LID_OPEN) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2627 | return mLidOpenRotation; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2628 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2629 | return mCarDockRotation; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2630 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2631 | return mDeskDockRotation; |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 2632 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
| 2633 | return mUserRotation; |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2634 | } else { |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 2635 | if (useSensorForOrientationLp(orientation)) { |
Jeff Brown | 4519f07 | 2011-01-23 13:16:01 -0800 | [diff] [blame] | 2636 | // Disable 180 degree rotation unless allowed by default for the device |
| 2637 | // or explicitly requested by the application. |
| 2638 | int rotation = mOrientationListener.getCurrentRotation(lastRotation); |
| 2639 | if (rotation == Surface.ROTATION_180 |
| 2640 | && !mAllowAllRotations |
| 2641 | && orientation != ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR) { |
| 2642 | return lastRotation; |
| 2643 | } |
| 2644 | return rotation; |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2645 | } |
| 2646 | return Surface.ROTATION_0; |
| 2647 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2648 | } |
| 2649 | } |
| 2650 | |
Dianne Hackborn | 68066c2 | 2011-04-21 17:26:39 -0700 | [diff] [blame] | 2651 | public int getLockedRotationLw() { |
| 2652 | synchronized (mLock) { |
| 2653 | if (false) { |
| 2654 | // Not yet working. |
| 2655 | if (mHdmiPlugged) { |
| 2656 | return Surface.ROTATION_0; |
| 2657 | } else if (mLidOpen == LID_OPEN) { |
| 2658 | return mLidOpenRotation; |
| 2659 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) { |
| 2660 | return mCarDockRotation; |
| 2661 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) { |
| 2662 | return mDeskDockRotation; |
| 2663 | } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
| 2664 | return mUserRotation; |
| 2665 | } |
| 2666 | } |
| 2667 | return -1; |
| 2668 | } |
| 2669 | } |
| 2670 | |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 2671 | private int getCurrentLandscapeRotation(int lastRotation) { |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 2672 | // if the user has locked rotation, we ignore the sensor |
| 2673 | if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
| 2674 | if (isLandscapeOrSeascape(mUserRotation)) { |
| 2675 | return mUserRotation; |
| 2676 | } else { |
| 2677 | // it seems odd to obey the sensor at all if rotation lock is enabled |
| 2678 | return mLandscapeRotation; |
| 2679 | } |
| 2680 | } |
| 2681 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 2682 | int sensorRotation = mOrientationListener.getCurrentRotation(lastRotation); |
| 2683 | if (isLandscapeOrSeascape(sensorRotation)) { |
| 2684 | return sensorRotation; |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 2685 | } |
| 2686 | // try to preserve the old rotation if it was landscape |
| 2687 | if (isLandscapeOrSeascape(lastRotation)) { |
| 2688 | return lastRotation; |
| 2689 | } |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 2690 | // default to one of the primary landscape rotation |
Steve Howard | a7bfe6a | 2010-09-23 16:47:49 -0700 | [diff] [blame] | 2691 | return mLandscapeRotation; |
| 2692 | } |
| 2693 | |
| 2694 | private boolean isLandscapeOrSeascape(int sensorRotation) { |
| 2695 | return sensorRotation == mLandscapeRotation || sensorRotation == mSeascapeRotation; |
| 2696 | } |
| 2697 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 2698 | private int getCurrentPortraitRotation(int lastRotation) { |
Daniel Sandler | e7e5ac2 | 2011-02-22 16:10:21 -0500 | [diff] [blame] | 2699 | // if the user has locked rotation, we ignore the sensor |
| 2700 | if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
| 2701 | if (isAnyPortrait(mUserRotation)) { |
| 2702 | return mUserRotation; |
| 2703 | } else { |
| 2704 | // it seems odd to obey the sensor at all if rotation lock is enabled |
| 2705 | return mPortraitRotation; |
| 2706 | } |
| 2707 | } |
| 2708 | |
Dianne Hackborn | e5439f2 | 2010-10-02 16:53:50 -0700 | [diff] [blame] | 2709 | int sensorRotation = mOrientationListener.getCurrentRotation(lastRotation); |
| 2710 | if (isAnyPortrait(sensorRotation)) { |
| 2711 | return sensorRotation; |
| 2712 | } |
| 2713 | // try to preserve the old rotation if it was portrait |
| 2714 | if (isAnyPortrait(lastRotation)) { |
| 2715 | return lastRotation; |
| 2716 | } |
| 2717 | // default to one of the primary portrait rotations |
| 2718 | return mPortraitRotation; |
| 2719 | } |
| 2720 | |
| 2721 | private boolean isAnyPortrait(int sensorRotation) { |
| 2722 | return sensorRotation == mPortraitRotation || sensorRotation == mUpsideDownRotation; |
| 2723 | } |
| 2724 | |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 2725 | |
| 2726 | // User rotation: to be used when all else fails in assigning an orientation to the device |
| 2727 | public void setUserRotationMode(int mode, int rot) { |
| 2728 | ContentResolver res = mContext.getContentResolver(); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 2729 | |
| 2730 | // mUserRotationMode and mUserRotation will be assigned by the content observer |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 2731 | if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) { |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 2732 | Settings.System.putInt(res, |
| 2733 | Settings.System.USER_ROTATION, |
| 2734 | rot); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 2735 | Settings.System.putInt(res, |
| 2736 | Settings.System.ACCELEROMETER_ROTATION, |
| 2737 | 0); |
Daniel Sandler | b73617d | 2010-08-17 00:41:00 -0400 | [diff] [blame] | 2738 | } else { |
| 2739 | Settings.System.putInt(res, |
| 2740 | Settings.System.ACCELEROMETER_ROTATION, |
| 2741 | 1); |
| 2742 | } |
| 2743 | } |
| 2744 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2745 | public boolean detectSafeMode() { |
| 2746 | try { |
| 2747 | int menuState = mWindowManager.getKeycodeState(KeyEvent.KEYCODE_MENU); |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2748 | int sState = mWindowManager.getKeycodeState(KeyEvent.KEYCODE_S); |
Dianne Hackborn | a8730f9 | 2009-11-17 15:53:36 -0800 | [diff] [blame] | 2749 | int dpadState = mWindowManager.getDPadKeycodeState(KeyEvent.KEYCODE_DPAD_CENTER); |
Jeff Brown | 00fa7bd | 2010-07-02 15:37:36 -0700 | [diff] [blame] | 2750 | int trackballState = mWindowManager.getTrackballScancodeState(BTN_MOUSE); |
Jeff Brown | b09abc1 | 2011-01-13 21:08:27 -0800 | [diff] [blame] | 2751 | int volumeDownState = mWindowManager.getKeycodeState(KeyEvent.KEYCODE_VOLUME_DOWN); |
| 2752 | mSafeMode = menuState > 0 || sState > 0 || dpadState > 0 || trackballState > 0 |
| 2753 | || volumeDownState > 0; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2754 | performHapticFeedbackLw(null, mSafeMode |
| 2755 | ? HapticFeedbackConstants.SAFE_MODE_ENABLED |
| 2756 | : HapticFeedbackConstants.SAFE_MODE_DISABLED, true); |
Dianne Hackborn | 73b1ec8 | 2009-10-04 13:33:00 -0700 | [diff] [blame] | 2757 | if (mSafeMode) { |
| 2758 | Log.i(TAG, "SAFE MODE ENABLED (menu=" + menuState + " s=" + sState |
| 2759 | + " dpad=" + dpadState + " trackball=" + trackballState + ")"); |
| 2760 | } else { |
| 2761 | Log.i(TAG, "SAFE MODE not enabled"); |
| 2762 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2763 | return mSafeMode; |
| 2764 | } catch (RemoteException e) { |
| 2765 | // Doom! (it's also local) |
| 2766 | throw new RuntimeException("window manager dead"); |
| 2767 | } |
| 2768 | } |
| 2769 | |
Dianne Hackborn | 181ceb5 | 2009-08-27 22:16:40 -0700 | [diff] [blame] | 2770 | static long[] getLongIntArray(Resources r, int resid) { |
| 2771 | int[] ar = r.getIntArray(resid); |
| 2772 | if (ar == null) { |
| 2773 | return null; |
| 2774 | } |
| 2775 | long[] out = new long[ar.length]; |
| 2776 | for (int i=0; i<ar.length; i++) { |
| 2777 | out[i] = ar[i]; |
| 2778 | } |
| 2779 | return out; |
| 2780 | } |
| 2781 | |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2782 | /** {@inheritDoc} */ |
| 2783 | public void systemReady() { |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2784 | // tell the keyguard |
| 2785 | mKeyguardMediator.onSystemReady(); |
| 2786 | android.os.SystemProperties.set("dev.bootcomplete", "1"); |
| 2787 | synchronized (mLock) { |
| 2788 | updateOrientationListenerLp(); |
Dianne Hackborn | c777e07 | 2010-02-12 13:07:59 -0800 | [diff] [blame] | 2789 | mSystemReady = true; |
| 2790 | mHandler.post(new Runnable() { |
| 2791 | public void run() { |
| 2792 | updateSettings(); |
| 2793 | } |
| 2794 | }); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2795 | } |
| 2796 | } |
| 2797 | |
Mike Lockwood | 2856930 | 2010-01-28 11:54:40 -0500 | [diff] [blame] | 2798 | /** {@inheritDoc} */ |
| 2799 | public void userActivity() { |
| 2800 | synchronized (mScreenLockTimeout) { |
| 2801 | if (mLockScreenTimerActive) { |
| 2802 | // reset the timer |
| 2803 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 2804 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 2805 | } |
| 2806 | } |
| 2807 | } |
| 2808 | |
| 2809 | Runnable mScreenLockTimeout = new Runnable() { |
| 2810 | public void run() { |
| 2811 | synchronized (this) { |
| 2812 | if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard"); |
| 2813 | mKeyguardMediator.doKeyguardTimeout(); |
| 2814 | mLockScreenTimerActive = false; |
| 2815 | } |
| 2816 | } |
| 2817 | }; |
| 2818 | |
| 2819 | private void updateLockScreenTimeout() { |
| 2820 | synchronized (mScreenLockTimeout) { |
| 2821 | boolean enable = (mAllowLockscreenWhenOn && mScreenOn && mKeyguardMediator.isSecure()); |
| 2822 | if (mLockScreenTimerActive != enable) { |
| 2823 | if (enable) { |
| 2824 | if (localLOGV) Log.v(TAG, "setting lockscreen timer"); |
| 2825 | mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout); |
| 2826 | } else { |
| 2827 | if (localLOGV) Log.v(TAG, "clearing lockscreen timer"); |
| 2828 | mHandler.removeCallbacks(mScreenLockTimeout); |
| 2829 | } |
| 2830 | mLockScreenTimerActive = enable; |
| 2831 | } |
| 2832 | } |
| 2833 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2834 | |
| 2835 | /** {@inheritDoc} */ |
| 2836 | public void enableScreenAfterBoot() { |
| 2837 | readLidState(); |
Dianne Hackborn | 32bc91d | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 2838 | updateRotation(Surface.FLAGS_ORIENTATION_ANIMATION_DISABLE); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2839 | } |
Dianne Hackborn | f54c8f9 | 2009-09-19 14:03:57 -0700 | [diff] [blame] | 2840 | |
Dianne Hackborn | 03759ed | 2009-03-27 16:04:08 -0700 | [diff] [blame] | 2841 | void updateRotation(int animFlags) { |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 2842 | mPowerManager.setKeyboardVisibility(mLidOpen == LID_OPEN); |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2843 | int rotation = Surface.ROTATION_0; |
Dianne Hackborn | ad7fa7f | 2011-01-07 14:06:50 -0800 | [diff] [blame] | 2844 | if (mHdmiPlugged) { |
| 2845 | rotation = Surface.ROTATION_0; |
Jeff Brown | 4aed78b | 2011-01-14 17:36:55 -0800 | [diff] [blame] | 2846 | } else if (mLidOpen == LID_OPEN) { |
Mike Lockwood | 1753f7f | 2009-08-24 14:49:07 -0700 | [diff] [blame] | 2847 | rotation = mLidOpenRotation; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2848 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR && mCarDockRotation >= 0) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2849 | rotation = mCarDockRotation; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2850 | } else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK && mDeskDockRotation >= 0) { |
Mike Lockwood | 2d1efbd | 2009-09-16 12:15:53 -0400 | [diff] [blame] | 2851 | rotation = mDeskDockRotation; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2852 | } |
| 2853 | //if lid is closed orientation will be portrait |
| 2854 | try { |
| 2855 | //set orientation on WindowManager |
Dianne Hackborn | 32bc91d | 2009-03-27 16:16:03 -0700 | [diff] [blame] | 2856 | mWindowManager.setRotation(rotation, true, |
| 2857 | mFancyRotationAnimation | animFlags); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2858 | } catch (RemoteException e) { |
| 2859 | // Ignore |
| 2860 | } |
| 2861 | } |
| 2862 | |
| 2863 | /** |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2864 | * Return an Intent to launch the currently active dock as home. Returns |
| 2865 | * null if the standard home should be launched. |
| 2866 | * @return |
| 2867 | */ |
| 2868 | Intent createHomeDockIntent() { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2869 | Intent intent; |
Dianne Hackborn | 867ab647 | 2010-04-29 13:28:56 -0700 | [diff] [blame] | 2870 | |
| 2871 | // What home does is based on the mode, not the dock state. That |
| 2872 | // is, when in car mode you should be taken to car home regardless |
| 2873 | // of whether we are actually in a car dock. |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 2874 | if (mUiMode == Configuration.UI_MODE_TYPE_CAR) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2875 | intent = mCarDockIntent; |
Dianne Hackborn | 7896839 | 2010-03-04 20:47:56 -0800 | [diff] [blame] | 2876 | } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2877 | intent = mDeskDockIntent; |
| 2878 | } else { |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2879 | return null; |
| 2880 | } |
| 2881 | |
| 2882 | ActivityInfo ai = intent.resolveActivityInfo( |
| 2883 | mContext.getPackageManager(), PackageManager.GET_META_DATA); |
| 2884 | if (ai == null) { |
| 2885 | return null; |
| 2886 | } |
| 2887 | |
| 2888 | if (ai.metaData != null && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) { |
| 2889 | intent = new Intent(intent); |
| 2890 | intent.setClassName(ai.packageName, ai.name); |
| 2891 | return intent; |
| 2892 | } |
| 2893 | |
| 2894 | return null; |
| 2895 | } |
| 2896 | |
| 2897 | void startDockOrHome() { |
| 2898 | Intent dock = createHomeDockIntent(); |
| 2899 | if (dock != null) { |
| 2900 | try { |
| 2901 | mContext.startActivity(dock); |
| 2902 | return; |
| 2903 | } catch (ActivityNotFoundException e) { |
| 2904 | } |
| 2905 | } |
| 2906 | mContext.startActivity(mHomeIntent); |
| 2907 | } |
| 2908 | |
| 2909 | /** |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2910 | * goes to the home screen |
| 2911 | * @return whether it did anything |
| 2912 | */ |
| 2913 | boolean goHome() { |
| 2914 | if (false) { |
| 2915 | // This code always brings home to the front. |
Dianne Hackborn | 256dd3b | 2009-05-19 18:51:21 -0700 | [diff] [blame] | 2916 | try { |
| 2917 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2918 | } catch (RemoteException e) { |
| 2919 | } |
Dianne Hackborn | 94a679d | 2009-07-28 17:51:07 -0700 | [diff] [blame] | 2920 | sendCloseSystemWindows(); |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2921 | startDockOrHome(); |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2922 | } else { |
| 2923 | // This code brings home to the front or, if it is already |
| 2924 | // at the front, puts the device to sleep. |
| 2925 | try { |
Wink Saville | d2e6a33 | 2010-02-12 12:12:06 -0800 | [diff] [blame] | 2926 | if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) { |
| 2927 | /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry. |
| 2928 | Log.d(TAG, "UTS-TEST-MODE"); |
| 2929 | } else { |
| 2930 | ActivityManagerNative.getDefault().stopAppSwitches(); |
| 2931 | sendCloseSystemWindows(); |
| 2932 | Intent dock = createHomeDockIntent(); |
| 2933 | if (dock != null) { |
| 2934 | int result = ActivityManagerNative.getDefault() |
| 2935 | .startActivity(null, dock, |
| 2936 | dock.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 2937 | null, 0, null, null, 0, true /* onlyIfNeeded*/, false); |
| 2938 | if (result == IActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 2939 | return false; |
| 2940 | } |
Dianne Hackborn | 39c2d71 | 2009-09-22 11:41:31 -0700 | [diff] [blame] | 2941 | } |
| 2942 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2943 | int result = ActivityManagerNative.getDefault() |
| 2944 | .startActivity(null, mHomeIntent, |
| 2945 | mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()), |
| 2946 | null, 0, null, null, 0, true /* onlyIfNeeded*/, false); |
| 2947 | if (result == IActivityManager.START_RETURN_INTENT_TO_CALLER) { |
| 2948 | return false; |
| 2949 | } |
| 2950 | } catch (RemoteException ex) { |
| 2951 | // bummer, the activity manager, which is in this process, is dead |
| 2952 | } |
| 2953 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2954 | return true; |
| 2955 | } |
| 2956 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2957 | public void setCurrentOrientationLw(int newOrientation) { |
| 2958 | synchronized (mLock) { |
| 2959 | if (newOrientation != mCurrentAppOrientation) { |
| 2960 | mCurrentAppOrientation = newOrientation; |
| 2961 | updateOrientationListenerLp(); |
| 2962 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2963 | } |
| 2964 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 2965 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 2966 | public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) { |
Jim Miller | 89b1722 | 2009-10-27 14:54:09 -0700 | [diff] [blame] | 2967 | final boolean hapticsDisabled = Settings.System.getInt(mContext.getContentResolver(), |
| 2968 | Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) == 0; |
Dianne Hackborn | 9dc06cc | 2009-11-17 18:19:23 -0800 | [diff] [blame] | 2969 | if (!always && (hapticsDisabled || mKeyguardMediator.isShowingAndNotHidden())) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2970 | return false; |
| 2971 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 2972 | long[] pattern = null; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2973 | switch (effectId) { |
| 2974 | case HapticFeedbackConstants.LONG_PRESS: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 2975 | pattern = mLongPressVibePattern; |
| 2976 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2977 | case HapticFeedbackConstants.VIRTUAL_KEY: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 2978 | pattern = mVirtualKeyVibePattern; |
| 2979 | break; |
| 2980 | case HapticFeedbackConstants.KEYBOARD_TAP: |
| 2981 | pattern = mKeyboardTapVibePattern; |
| 2982 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2983 | case HapticFeedbackConstants.SAFE_MODE_DISABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 2984 | pattern = mSafeModeDisabledVibePattern; |
| 2985 | break; |
Dianne Hackborn | b1a7980 | 2009-09-29 15:18:31 -0700 | [diff] [blame] | 2986 | case HapticFeedbackConstants.SAFE_MODE_ENABLED: |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 2987 | pattern = mSafeModeEnabledVibePattern; |
| 2988 | break; |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 2989 | default: |
| 2990 | return false; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 2991 | } |
Amith Yamasani | c33cb71 | 2010-02-10 15:21:49 -0800 | [diff] [blame] | 2992 | if (pattern.length == 1) { |
| 2993 | // One-shot vibration |
| 2994 | mVibrator.vibrate(pattern[0]); |
| 2995 | } else { |
| 2996 | // Pattern vibration |
| 2997 | mVibrator.vibrate(pattern, -1); |
| 2998 | } |
| 2999 | return true; |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3000 | } |
| 3001 | |
The Android Open Source Project | 0727d22 | 2009-03-11 12:11:58 -0700 | [diff] [blame] | 3002 | public void screenOnStoppedLw() { |
Dianne Hackborn | 9dc06cc | 2009-11-17 18:19:23 -0800 | [diff] [blame] | 3003 | if (!mKeyguardMediator.isShowingAndNotHidden() && mPowerManager.isScreenOn()) { |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3004 | long curTime = SystemClock.uptimeMillis(); |
| 3005 | mPowerManager.userActivity(curTime, false, LocalPowerManager.OTHER_EVENT); |
| 3006 | } |
| 3007 | } |
Mike Lockwood | fcb3924 | 2009-10-21 23:01:07 -0400 | [diff] [blame] | 3008 | |
| 3009 | public boolean allowKeyRepeat() { |
| 3010 | // disable key repeat when screen is off |
| 3011 | return mScreenOn; |
| 3012 | } |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3013 | |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3014 | private void updateSystemUiVisibility() { |
| 3015 | // If there is no window focused, there will be nobody to handle the events |
| 3016 | // anyway, so just hang on in whatever state we're in until things settle down. |
| 3017 | if (mFocusedWindow != null) { |
Joe Onorato | 14782f7 | 2011-01-25 19:53:17 -0800 | [diff] [blame] | 3018 | final WindowManager.LayoutParams params = mFocusedWindow.getAttrs(); |
| 3019 | final int visibility = params.systemUiVisibility | params.subtreeSystemUiVisibility; |
Joe Onorato | 664644d | 2011-01-23 17:53:23 -0800 | [diff] [blame] | 3020 | mHandler.post(new Runnable() { |
| 3021 | public void run() { |
| 3022 | if (mStatusBarService == null) { |
| 3023 | mStatusBarService = IStatusBarService.Stub.asInterface( |
| 3024 | ServiceManager.getService("statusbar")); |
| 3025 | } |
| 3026 | if (mStatusBarService != null) { |
| 3027 | // need to assume status bar privileges to invoke lights on |
| 3028 | long origId = Binder.clearCallingIdentity(); |
| 3029 | try { |
| 3030 | mStatusBarService.setSystemUiVisibility(visibility); |
| 3031 | } catch (RemoteException e) { |
| 3032 | // not much to be done |
| 3033 | mStatusBarService = null; |
| 3034 | } finally { |
| 3035 | Binder.restoreCallingIdentity(origId); |
| 3036 | } |
| 3037 | } |
| 3038 | } |
| 3039 | }); |
| 3040 | } |
| 3041 | } |
| 3042 | |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3043 | public void dump(String prefix, FileDescriptor fd, PrintWriter pw, String[] args) { |
| 3044 | pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode); |
| 3045 | pw.print(" mSystemRead="); pw.println(mSystemReady); |
| 3046 | pw.print(prefix); pw.print("mLidOpen="); pw.print(mLidOpen); |
| 3047 | pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation); |
| 3048 | pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged); |
| 3049 | pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); |
| 3050 | pw.print(" mDockMode="); pw.print(mDockMode); |
| 3051 | pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); |
| 3052 | pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation); |
| 3053 | pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode); |
| 3054 | pw.print(" mUserRotation="); pw.print(mUserRotation); |
Daniel Sandler | 2ed6ad6 | 2011-02-22 14:54:17 -0500 | [diff] [blame] | 3055 | pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations); |
Dianne Hackborn | f99f9c5 | 2011-01-12 15:49:25 -0800 | [diff] [blame] | 3056 | pw.print(prefix); pw.print("mAccelerometerDefault="); pw.print(mAccelerometerDefault); |
| 3057 | pw.print(" mCurrentAppOrientation="); pw.println(mCurrentAppOrientation); |
| 3058 | pw.print(prefix); pw.print("mCarDockEnablesAccelerometer="); |
| 3059 | pw.print(mCarDockEnablesAccelerometer); |
| 3060 | pw.print(" mDeskDockEnablesAccelerometer="); |
| 3061 | pw.println(mDeskDockEnablesAccelerometer); |
| 3062 | pw.print(prefix); pw.print("mLidKeyboardAccessibility="); |
| 3063 | pw.print(mLidKeyboardAccessibility); |
| 3064 | pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility); |
| 3065 | pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); |
| 3066 | pw.print(prefix); pw.print("mScreenOn="); pw.print(mScreenOn); |
| 3067 | pw.print(" mOrientationSensorEnabled="); pw.print(mOrientationSensorEnabled); |
| 3068 | pw.print(" mHasSoftInput="); pw.println(mHasSoftInput); |
| 3069 | pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft); |
| 3070 | pw.print(","); pw.print(mUnrestrictedScreenTop); |
| 3071 | pw.print(") "); pw.print(mUnrestrictedScreenWidth); |
| 3072 | pw.print("x"); pw.println(mUnrestrictedScreenHeight); |
| 3073 | pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft); |
| 3074 | pw.print(","); pw.print(mRestrictedScreenTop); |
| 3075 | pw.print(") "); pw.print(mRestrictedScreenWidth); |
| 3076 | pw.print("x"); pw.println(mRestrictedScreenHeight); |
| 3077 | pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft); |
| 3078 | pw.print(","); pw.print(mCurTop); |
| 3079 | pw.print(")-("); pw.print(mCurRight); |
| 3080 | pw.print(","); pw.print(mCurBottom); pw.println(")"); |
| 3081 | pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft); |
| 3082 | pw.print(","); pw.print(mContentTop); |
| 3083 | pw.print(")-("); pw.print(mContentRight); |
| 3084 | pw.print(","); pw.print(mContentBottom); pw.println(")"); |
| 3085 | pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft); |
| 3086 | pw.print(","); pw.print(mDockTop); |
| 3087 | pw.print(")-("); pw.print(mDockRight); |
| 3088 | pw.print(","); pw.print(mDockBottom); pw.println(")"); |
| 3089 | pw.print(prefix); pw.print("mDockLayer="); pw.println(mDockLayer); |
| 3090 | pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState="); |
| 3091 | pw.println(mTopFullscreenOpaqueWindowState); |
| 3092 | pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen); |
| 3093 | pw.print(" mForceStatusBar="); pw.print(mForceStatusBar); |
| 3094 | pw.print(" mHideLockScreen="); pw.println(mHideLockScreen); |
| 3095 | pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard); |
| 3096 | pw.print(" mHomePressed="); pw.println(mHomePressed); |
| 3097 | pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn); |
| 3098 | pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout); |
| 3099 | pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive); |
| 3100 | pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior); |
| 3101 | pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior); |
| 3102 | pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior); |
| 3103 | pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation); |
| 3104 | pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation); |
| 3105 | pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation); |
| 3106 | pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation); |
| 3107 | } |
The Android Open Source Project | 1f838aa | 2009-03-03 19:32:13 -0800 | [diff] [blame] | 3108 | } |