blob: 71e80831d70c26dc2a70d4e4551a47163b1550ab [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16package com.android.internal.policy.impl;
17
Dianne Hackborna4972e92012-03-14 10:38:05 -070018import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080019import android.app.ActivityManagerNative;
Dianne Hackborn661cd522011-08-22 00:26:20 -070020import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070021import android.app.SearchManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080022import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070023import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080024import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040025import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080026import android.content.ContentResolver;
27import android.content.Context;
28import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070029import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070030import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080031import android.content.pm.ActivityInfo;
32import android.content.pm.PackageManager;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070033import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080034import android.content.res.Configuration;
35import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070036import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080037import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080038import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080039import android.graphics.Rect;
Michael Jurka7a348952012-02-27 13:07:58 -080040import android.media.AudioManager;
41import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070042import android.media.Ringtone;
43import android.media.RingtoneManager;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070044import android.os.Bundle;
Jeff Brown9a538ee2012-08-20 14:56:57 -070045import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080046import android.os.Handler;
47import android.os.IBinder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070048import android.os.IRemoteCallback;
Jeff Brown32cbc38552011-12-01 14:01:49 -080049import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070050import android.os.Message;
51import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080052import android.os.PowerManager;
53import android.os.RemoteException;
54import android.os.ServiceManager;
55import android.os.SystemClock;
56import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080057import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070058import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080059import android.os.Vibrator;
60import android.provider.Settings;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070061import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080062import android.util.EventLog;
63import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070064import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080065import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070066import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080067import android.view.Gravity;
68import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080069import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080070import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070071import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070072import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080073import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080074import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080075import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080076import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080077import android.view.KeyEvent;
78import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080079import android.view.Surface;
80import android.view.View;
81import android.view.ViewConfiguration;
82import android.view.Window;
83import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080084import android.view.WindowManagerGlobal;
85import android.view.WindowManagerPolicy;
86import android.view.WindowOrientationListener;
87import android.view.accessibility.AccessibilityEvent;
88import android.view.animation.Animation;
89import android.view.animation.AnimationUtils;
90
91import com.android.internal.R;
92import com.android.internal.policy.PolicyManager;
93import com.android.internal.policy.impl.keyguard.KeyguardViewManager;
94import com.android.internal.policy.impl.keyguard.KeyguardViewMediator;
95import com.android.internal.statusbar.IStatusBarService;
96import com.android.internal.telephony.ITelephony;
97import com.android.internal.widget.PointerLocationView;
98
99import java.io.File;
100import java.io.FileReader;
101import java.io.IOException;
102import java.io.PrintWriter;
103
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800104import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
Craig Mautnerae446592012-12-06 19:05:05 -0800105import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
106import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800107import static android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN;
108import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
109import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
110import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
111import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -0700112import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Craig Mautnerae446592012-12-06 19:05:05 -0800113import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
Craig Mautner88400d32012-09-30 12:35:45 -0700114import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800115import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
116import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Dianne Hackborndea3ef72010-10-28 14:24:22 -0700117import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
Craig Mautnerae446592012-12-06 19:05:05 -0800118import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800119import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700120import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800121import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
Craig Mautner88400d32012-09-30 12:35:45 -0700122import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800123import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
Craig Mautnerae446592012-12-06 19:05:05 -0800124import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700125import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700126import static android.view.WindowManager.LayoutParams.TYPE_DRAG;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500127import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700128import static android.view.WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER;
Craig Mautnerae446592012-12-06 19:05:05 -0800129import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
130import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800131import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD;
132import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700133import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
Craig Mautnerae446592012-12-06 19:05:05 -0800134import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
135import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800136import static android.view.WindowManager.LayoutParams.TYPE_PHONE;
Craig Mautnerae446592012-12-06 19:05:05 -0800137import static android.view.WindowManager.LayoutParams.TYPE_POINTER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800138import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
Craig Mautner88400d32012-09-30 12:35:45 -0700139import static android.view.WindowManager.LayoutParams.TYPE_RECENTS_OVERLAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800140import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR;
Jeff Brown3b2b3542010-10-15 00:54:27 -0700141import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800142import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
143import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL;
Joe Onorato29fc2c92010-11-24 10:26:50 -0800144import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800145import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
Craig Mautnerae446592012-12-06 19:05:05 -0800146import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800147import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800148import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
149import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700150import static android.view.WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND;
Dianne Hackborne8ecde12011-08-03 18:55:19 -0700151import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY;
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -0700152import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Jeff Brownac143512012-04-05 18:57:33 -0700153import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
154import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
155import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800156
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800157/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700158 * WindowManagerPolicy implementation for the Android phone UI. This
159 * introduces a new method suffix, Lp, for an internal lock of the
160 * PhoneWindowManager. This is used to protect some internal state, and
161 * can be acquired with either thw Lw and Li lock held, so has the restrictions
162 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800163 */
164public class PhoneWindowManager implements WindowManagerPolicy {
165 static final String TAG = "WindowManager";
166 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700167 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700168 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700169 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700170 static final boolean DEBUG_STARTING_WINDOW = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800171 static final boolean SHOW_STARTING_ANIMATIONS = true;
172 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400173
174 static final int LONG_PRESS_POWER_NOTHING = 0;
175 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
176 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700177 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700178
179 // These need to match the documentation/constant in
180 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800181 static final int LONG_PRESS_HOME_NOTHING = 0;
182 static final int LONG_PRESS_HOME_RECENT_DIALOG = 1;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700183 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 2;
Joe Onorato46b0d682010-11-22 17:37:27 -0800184
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700185 static final int APPLICATION_MEDIA_SUBLAYER = -2;
186 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800187 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800188 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700189
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800190 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
191 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
192 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500193 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700194 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800195
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700196 /**
197 * These are the system UI flags that, when changing, can cause the layout
198 * of the screen to change.
199 */
200 static final int SYSTEM_UI_CHANGING_LAYOUT =
201 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
202
Jeff Brown6651a632011-11-28 12:59:11 -0800203 /* Table of Application Launch keys. Maps from key codes to intent categories.
204 *
205 * These are special keys that are used to launch particular kinds of applications,
206 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
207 * usage page. We don't support quite that many yet...
208 */
209 static SparseArray<String> sApplicationLaunchKeyCategories;
210 static {
211 sApplicationLaunchKeyCategories = new SparseArray<String>();
212 sApplicationLaunchKeyCategories.append(
213 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
214 sApplicationLaunchKeyCategories.append(
215 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
216 sApplicationLaunchKeyCategories.append(
217 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
218 sApplicationLaunchKeyCategories.append(
219 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
220 sApplicationLaunchKeyCategories.append(
221 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
222 sApplicationLaunchKeyCategories.append(
223 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
224 }
225
Dianne Hackborndf89e652011-10-06 22:35:11 -0700226 /**
227 * Lock protecting internal state. Must not call out into window
228 * manager with lock held. (This lock will be acquired in places
229 * where the window manager is calling in with its own lock held.)
230 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800231 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700232
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800233 Context mContext;
234 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700235 WindowManagerFuncs mWindowManagerFuncs;
Jeff Brown96307042012-07-27 15:51:34 -0700236 PowerManager mPowerManager;
Joe Onorato93056472010-09-10 10:30:46 -0400237 IStatusBarService mStatusBarService;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700238 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800239 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700240 SearchManager mSearchManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800241
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700242 // Vibrator pattern for haptic feedback of a long press.
243 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700244
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700245 // Vibrator pattern for haptic feedback of virtual key press.
246 long[] mVirtualKeyVibePattern;
247
Amith Yamasanic33cb712010-02-10 15:21:49 -0800248 // Vibrator pattern for a short vibration.
249 long[] mKeyboardTapVibePattern;
250
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700251 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
252 long[] mSafeModeDisabledVibePattern;
253
254 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
255 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700256
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800257 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
258 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400259
260 boolean mHeadless;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800261 boolean mSafeMode;
262 WindowState mStatusBar = null;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700263 boolean mHasSystemNavBar;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700264 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400265 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400266 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700267 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400268 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
269 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
270 int[] mNavigationBarHeightForRotation = new int[4];
271 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400272
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800273 WindowState mKeyguard = null;
274 KeyguardViewMediator mKeyguardMediator;
275 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700276 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
277 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800278 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900279 WindowState mLastInputMethodWindow = null;
280 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800281
Jeff Brown68b909d2011-12-07 16:36:01 -0800282 static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0;
283 static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1;
Jeff Brown602ab322012-05-16 13:33:47 -0700284 static final int RECENT_APPS_BEHAVIOR_DISMISS = 2;
285 static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 3;
Jeff Brown68b909d2011-12-07 16:36:01 -0800286
287 RecentApplicationsDialog mRecentAppsDialog;
288 int mRecentAppsDialogHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700289 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800290
Jeff Brown2e7760e2012-04-11 15:14:55 -0700291 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700292 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800293
Dianne Hackbornc777e072010-02-12 13:07:59 -0800294 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700295 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800296 boolean mHdmiPlugged;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700297 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700298 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400299 int mCarDockRotation;
300 int mDeskDockRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -0700301 int mHdmiRotation;
Jeff Brown27f1d672012-10-17 18:32:34 -0700302 boolean mHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400303
304 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
305 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700306 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400307
Jeff Brownd3187e32011-09-21 19:26:44 -0700308 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400309 boolean mCarDockEnablesAccelerometer;
310 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700311 int mLidKeyboardAccessibility;
312 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700313 boolean mLidControlsSleep;
Joe Onoratod208e702010-10-08 16:22:43 -0400314 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700315 boolean mScreenOnEarly = false;
316 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800317 boolean mOrientationSensorEnabled = false;
318 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800319 boolean mHasSoftInput = false;
320
Jeff Brown70825162012-03-28 17:27:48 -0700321 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800322
323 // The last window we were told about in focusChanged.
324 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800325 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800326
Jeff Brown70825162012-03-28 17:27:48 -0700327 private static final class PointerLocationInputEventReceiver extends InputEventReceiver {
328 private final PointerLocationView mView;
329
330 public PointerLocationInputEventReceiver(InputChannel inputChannel, Looper looper,
331 PointerLocationView view) {
Jeff Brown32cbc38552011-12-01 14:01:49 -0800332 super(inputChannel, looper);
Jeff Brown70825162012-03-28 17:27:48 -0700333 mView = view;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800334 }
335
Jeff Browna41ca772010-08-11 14:46:32 -0700336 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -0800337 public void onInputEvent(InputEvent event) {
Jeff Brown3915bb82010-11-05 15:02:16 -0700338 boolean handled = false;
339 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -0800340 if (event instanceof MotionEvent
341 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
342 final MotionEvent motionEvent = (MotionEvent)event;
Jeff Brown70825162012-03-28 17:27:48 -0700343 mView.addPointerEvent(motionEvent);
344 handled = true;
Jeff Brown93ed4e32010-09-23 13:51:48 -0700345 }
Jeff Brown3915bb82010-11-05 15:02:16 -0700346 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -0800347 finishInputEvent(event, handled);
Jeff Browna41ca772010-08-11 14:46:32 -0700348 }
349 }
Jeff Brown32cbc38552011-12-01 14:01:49 -0800350 }
Jeff Brown70825162012-03-28 17:27:48 -0700351
352 // Pointer location view state, only modified on the mHandler Looper.
Jeff Brown32cbc38552011-12-01 14:01:49 -0800353 PointerLocationInputEventReceiver mPointerLocationInputEventReceiver;
Jeff Brown70825162012-03-28 17:27:48 -0700354 PointerLocationView mPointerLocationView;
355 InputChannel mPointerLocationInputChannel;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800356
Joe Onorato29fc2c92010-11-24 10:26:50 -0800357 // The current size of the screen; really; (ir)regardless of whether the status
358 // bar can be hidden or not
359 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
360 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700361 // The current size of the screen; these may be different than (0,0)-(dw,dh)
362 // if the status bar can't be hidden; in that case it effectively carves out
363 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800364 int mRestrictedScreenLeft, mRestrictedScreenTop;
365 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700366 // During layout, the current screen borders accounting for any currently
367 // visible system UI elements.
368 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700369 // For applications requesting stable content insets, these are them.
370 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700371 // For applications requesting stable content insets but have also set the
372 // fullscreen window flag, these are the stable dimensions without the status bar.
373 int mStableFullscreenLeft, mStableFullscreenTop;
374 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800375 // During layout, the current screen borders with all outer decoration
376 // (status bar, input method dock) accounted for.
377 int mCurLeft, mCurTop, mCurRight, mCurBottom;
378 // During layout, the frame in which content should be displayed
379 // to the user, accounting for all screen decoration except for any
380 // space they deem as available for other content. This is usually
381 // the same as mCur*, but may be larger if the screen decor has supplied
382 // content insets.
383 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800384 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800385 // windows are placed.
386 int mDockLeft, mDockTop, mDockRight, mDockBottom;
387 // During layout, the layer at which the doc window is placed.
388 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700389 // During layout, this is the layer of the status bar.
390 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700391 int mLastSystemUiFlags;
392 // Bits that we are in the process of clearing, so we want to prevent
393 // them from being set by applications until everything has been updated
394 // to have them clear.
395 int mResettingSystemUiFlags = 0;
396 // Bits that we are currently always keeping cleared.
397 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800398 // What we last reported to system UI about whether the compatibility
399 // menu needs to be displayed.
400 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700401
402 FakeWindow mHideNavFakeWindow = null;
403
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800404 static final Rect mTmpParentFrame = new Rect();
405 static final Rect mTmpDisplayFrame = new Rect();
406 static final Rect mTmpContentFrame = new Rect();
407 static final Rect mTmpVisibleFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700408 static final Rect mTmpNavigationFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800409
410 WindowState mTopFullscreenOpaqueWindowState;
Joe Onorato93056472010-09-10 10:30:46 -0400411 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800412 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700413 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700414 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800415 boolean mForcingShowNavBar;
416 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700417
418 // States of keyguard dismiss.
419 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
420 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
421 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
422 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
423
424 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
425 * be done once per window. */
426 private WindowState mWinDismissingKeyguard;
427
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700428 boolean mShowingLockscreen;
429 boolean mShowingDream;
430 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800431 boolean mHomePressed;
Michael Jurka7f2668c2012-03-27 07:49:52 -0700432 boolean mHomeLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800433 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700434 Intent mCarDockIntent;
435 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700436 boolean mSearchKeyShortcutPending;
437 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700438 boolean mAssistKeyLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800439
Mike Lockwood28569302010-01-28 11:54:40 -0500440 // support for activating the lock screen while the screen is on
441 boolean mAllowLockscreenWhenOn;
442 int mLockScreenTimeout;
443 boolean mLockScreenTimerActive;
444
David Brownbaf8d092010-03-08 21:52:59 -0800445 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800446 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800447
448 // Behavior of POWER button while in-call and screen on.
449 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
450 int mIncallPowerBehavior;
451
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700452 Display mDisplay;
453
Dianne Hackborn9d132642011-04-21 17:26:39 -0700454 int mLandscapeRotation = 0; // default landscape rotation
455 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
456 int mPortraitRotation = 0; // default portrait rotation
457 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700458
Joe Onorato46b0d682010-11-22 17:37:27 -0800459 // What we do when the user long presses on home
460 private int mLongPressOnHomeBehavior = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800461
Winson Chung9112ec32011-06-27 13:15:32 -0700462 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700463 // Time to volume and power must be pressed within this interval of each other.
464 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700465 // Increase the chord delay when taking a screenshot from the keyguard
466 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800467 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700468 private boolean mVolumeDownKeyTriggered;
469 private long mVolumeDownKeyTime;
470 private boolean mVolumeDownKeyConsumedByScreenshotChord;
471 private boolean mVolumeUpKeyTriggered;
472 private boolean mPowerKeyTriggered;
473 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700474
Christopher Tate5e08af02012-09-21 17:17:22 -0700475 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800476 ShortcutManager mShortcutManager;
477 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700478 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800479
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700480 // Fallback actions by key code.
481 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
482 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800483
Jeff Brown70825162012-03-28 17:27:48 -0700484 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
485 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700486 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
487 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Jeff Brown70825162012-03-28 17:27:48 -0700488
489 private class PolicyHandler extends Handler {
490 @Override
491 public void handleMessage(Message msg) {
492 switch (msg.what) {
493 case MSG_ENABLE_POINTER_LOCATION:
494 enablePointerLocation();
495 break;
496 case MSG_DISABLE_POINTER_LOCATION:
497 disablePointerLocation();
498 break;
Jeff Brown40013652012-05-16 21:22:36 -0700499 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
500 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
501 break;
502 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
503 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
504 break;
Jeff Brown70825162012-03-28 17:27:48 -0700505 }
506 }
507 }
508
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800509 private UEventObserver mHDMIObserver = new UEventObserver() {
510 @Override
511 public void onUEvent(UEventObserver.UEvent event) {
512 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
513 }
514 };
515
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800516 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800517 SettingsObserver(Handler handler) {
518 super(handler);
519 }
David Brownbaf8d092010-03-08 21:52:59 -0800520
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800521 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700522 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800523 ContentResolver resolver = mContext.getContentResolver();
524 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700525 Settings.System.END_BUTTON_BEHAVIOR), false, this,
526 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800527 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700528 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
529 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800530 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700531 Settings.System.ACCELEROMETER_ROTATION), false, this,
532 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500533 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700534 Settings.System.USER_ROTATION), false, this,
535 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400536 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700537 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
538 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800539 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700540 Settings.System.POINTER_LOCATION), false, this,
541 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800542 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700543 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
544 UserHandle.USER_ALL);
Dianne Hackborn03759ed2009-03-27 16:04:08 -0700545 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700546 "fancy_rotation_anim"), false, this,
547 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800548 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800549 }
550
551 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800552 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700553 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800554 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800555 }
556
557 class MyOrientationListener extends WindowOrientationListener {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800558 MyOrientationListener(Context context) {
559 super(context);
560 }
561
562 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700563 public void onProposedRotationChanged(int rotation) {
564 if (localLOGV) Log.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700565 updateRotation(false);
566 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800567 }
568 MyOrientationListener mOrientationListener;
569
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700570 IStatusBarService getStatusBarService() {
571 synchronized (mServiceAquireLock) {
572 if (mStatusBarService == null) {
573 mStatusBarService = IStatusBarService.Stub.asInterface(
574 ServiceManager.getService("statusbar"));
575 }
576 return mStatusBarService;
577 }
578 }
579
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700580 /*
581 * We always let the sensor be switched on by default except when
582 * the user has explicitly disabled sensor based rotation or when the
583 * screen is switched off.
584 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700585 boolean needSensorRunningLp() {
Dianne Hackborne5439f22010-10-02 16:53:50 -0700586 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
587 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
588 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
589 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800590 // If the application has explicitly requested to follow the
591 // orientation, then we need to turn the sensor or.
592 return true;
593 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700594 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800595 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
596 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
597 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400598 // enable accelerometer if we are docked in a dock that enables accelerometer
599 // orientation management,
600 return true;
601 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700602 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800603 // If the setting for using the sensor by default is enabled, then
604 // we will always leave it on. Note that the user could go to
605 // a window that forces an orientation that does not use the
606 // sensor and in theory we could turn it off... however, when next
607 // turning it on we won't have a good value for the current
608 // orientation for a little bit, which can cause orientation
609 // changes to lag, so we'd like to keep it always on. (It will
610 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700611 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800612 }
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700613 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800614 }
615
616 /*
617 * Various use cases for invoking this function
618 * screen turning off, should always disable listeners if already enabled
619 * screen turned on and current app has sensor based orientation, enable listeners
620 * if not already enabled
621 * screen turned on and current app does not have sensor orientation, disable listeners if
622 * already enabled
623 * screen turning on and current app has sensor based orientation, enable listeners if needed
624 * screen turning on and current app has nosensor based orientation, do nothing
625 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700626 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800627 if (!mOrientationListener.canDetectOrientation()) {
628 // If sensor is turned off or nonexistent for some reason
629 return;
630 }
631 //Could have been invoked due to screen turning on or off or
632 //change of the currently visible window's orientation
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700633 if (localLOGV) Log.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800634 ", current orientation="+mCurrentAppOrientation+
635 ", SensorEnabled="+mOrientationSensorEnabled);
636 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700637 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700638 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800639 disable = false;
640 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700641 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800642 mOrientationListener.enable();
Dianne Hackborn05726582009-09-22 17:28:24 -0700643 if(localLOGV) Log.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800644 mOrientationSensorEnabled = true;
645 }
646 }
647 }
648 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700649 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800650 mOrientationListener.disable();
Dianne Hackborn05726582009-09-22 17:28:24 -0700651 if(localLOGV) Log.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800652 mOrientationSensorEnabled = false;
653 }
654 }
655
Jeff Brown4d396052010-10-29 21:50:21 -0700656 private void interceptPowerKeyDown(boolean handled) {
657 mPowerKeyHandled = handled;
658 if (!handled) {
659 mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
660 }
661 }
662
663 private boolean interceptPowerKeyUp(boolean canceled) {
664 if (!mPowerKeyHandled) {
665 mHandler.removeCallbacks(mPowerLongPress);
666 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700667 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700668 return false;
669 }
670
671 private void cancelPendingPowerKeyAction() {
672 if (!mPowerKeyHandled) {
673 mHandler.removeCallbacks(mPowerLongPress);
674 }
Jeff Brownff204712011-10-25 21:27:54 -0700675 if (mPowerKeyTriggered) {
676 mPendingPowerKeyUpCanceled = true;
677 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700678 }
679
680 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800681 if (mScreenshotChordEnabled
682 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700683 final long now = SystemClock.uptimeMillis();
684 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
685 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
686 mVolumeDownKeyConsumedByScreenshotChord = true;
687 cancelPendingPowerKeyAction();
688
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800689 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700690 }
691 }
692 }
693
Winson Chung1cea2f32012-10-08 20:42:01 -0700694 private long getScreenshotChordLongPressDelay() {
695 if (mKeyguardMediator.isShowing()) {
696 // Double the time it takes to take a screenshot from the keyguard
697 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
698 ViewConfiguration.getGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700699 }
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800700 return ViewConfiguration.getGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700701 }
702
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700703 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800704 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700705 }
706
707 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700708 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800709 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700710 // The context isn't read
711 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700712 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
713 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400714 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700715 int resolvedBehavior = mLongPressOnPowerBehavior;
716 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
717 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
718 }
719
720 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700721 case LONG_PRESS_POWER_NOTHING:
722 break;
723 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
724 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700725 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
726 performAuditoryFeedbackForAccessibilityIfNeed();
727 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700728 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
729 showGlobalActionsDialog();
730 break;
731 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700732 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700733 mPowerKeyHandled = true;
734 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
735 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700736 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700737 break;
738 }
739 }
740 };
741
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800742 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800743 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700744 public void run() {
745 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800746 }
747 };
748
749 void showGlobalActionsDialog() {
750 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700751 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800752 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700753 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800754 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
755 if (keyguardShowing) {
756 // since it took two seconds of long press to bring this up,
757 // poke the wake lock so they have some time to see the dialog.
Jeff Brown3dc524b2012-09-30 19:49:11 -0700758 mKeyguardMediator.userActivity();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800759 }
760 }
761
762 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700763 return Settings.Global.getInt(
764 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800765 }
766
Patrick Dubroyece94522011-02-23 18:35:01 -0800767 private void handleLongPressOnHome() {
Jim Milleree969aa2010-08-26 20:17:43 -0700768 // We can't initialize this in init() since the configuration hasn't been loaded yet.
Joe Onorato46b0d682010-11-22 17:37:27 -0800769 if (mLongPressOnHomeBehavior < 0) {
770 mLongPressOnHomeBehavior
Joe Onorato50262e52010-11-26 14:04:54 -0800771 = mContext.getResources().getInteger(R.integer.config_longPressOnHomeBehavior);
Joe Onorato46b0d682010-11-22 17:37:27 -0800772 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Michael Jurka3b1fc472011-06-13 10:54:40 -0700773 mLongPressOnHomeBehavior > LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
Joe Onorato46b0d682010-11-22 17:37:27 -0800774 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
775 }
776 }
777
778 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
779 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
780 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
Patrick Dubroyece94522011-02-23 18:35:01 -0800781
782 // Eat the longpress so it won't dismiss the recent apps dialog when
783 // the user lets go of the home key
Michael Jurka7f2668c2012-03-27 07:49:52 -0700784 mHomeLongPressed = true;
Jim Milleree969aa2010-08-26 20:17:43 -0700785 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800786
Joe Onorato46b0d682010-11-22 17:37:27 -0800787 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_DIALOG) {
Jeff Brown68b909d2011-12-07 16:36:01 -0800788 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS);
Michael Jurka3b1fc472011-06-13 10:54:40 -0700789 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
Jim Millere6ad1a82010-08-20 19:25:39 -0700790 try {
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700791 IStatusBarService statusbar = getStatusBarService();
792 if (statusbar != null) {
793 statusbar.toggleRecentApps();
794 }
Michael Jurka3b1fc472011-06-13 10:54:40 -0700795 } catch (RemoteException e) {
796 Slog.e(TAG, "RemoteException when showing recent apps", e);
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700797 // re-acquire status bar service next time it is needed.
798 mStatusBarService = null;
Jim Millere6ad1a82010-08-20 19:25:39 -0700799 }
800 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800801 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800802
803 /**
Jeff Brown68b909d2011-12-07 16:36:01 -0800804 * Create (if necessary) and show or dismiss the recent apps dialog according
805 * according to the requested behavior.
Patrick Dubroyece94522011-02-23 18:35:01 -0800806 */
Jeff Brown68b909d2011-12-07 16:36:01 -0800807 void showOrHideRecentAppsDialog(final int behavior) {
Jeff Brownda3d5a92011-03-29 15:11:34 -0700808 mHandler.post(new Runnable() {
809 @Override
810 public void run() {
811 if (mRecentAppsDialog == null) {
Jeff Brown54875002011-04-06 15:33:01 -0700812 mRecentAppsDialog = new RecentApplicationsDialog(mContext);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700813 }
Jeff Brown54875002011-04-06 15:33:01 -0700814 if (mRecentAppsDialog.isShowing()) {
Jeff Brown68b909d2011-12-07 16:36:01 -0800815 switch (behavior) {
816 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
Jeff Brown602ab322012-05-16 13:33:47 -0700817 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800818 mRecentAppsDialog.dismiss();
819 break;
820 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
821 mRecentAppsDialog.dismissAndSwitch();
822 break;
823 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
824 default:
825 break;
Jeff Brown54875002011-04-06 15:33:01 -0700826 }
827 } else {
Jeff Brown68b909d2011-12-07 16:36:01 -0800828 switch (behavior) {
829 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
830 mRecentAppsDialog.show();
831 break;
832 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
833 try {
834 mWindowManager.setInTouchMode(false);
835 } catch (RemoteException e) {
836 }
837 mRecentAppsDialog.show();
838 break;
Jeff Brown602ab322012-05-16 13:33:47 -0700839 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800840 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
841 default:
842 break;
843 }
Jeff Brown54875002011-04-06 15:33:01 -0700844 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700845 }
846 });
Patrick Dubroyece94522011-02-23 18:35:01 -0800847 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700848
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800849 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800850 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800851 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700852 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800853 mContext = context;
854 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700855 mWindowManagerFuncs = windowManagerFuncs;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400856 mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
857 if (!mHeadless) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700858 // don't create KeyguardViewMediator if headless
Jim Miller9c7e6302012-08-29 13:48:34 -0700859 mKeyguardMediator = new KeyguardViewMediator(context, null);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700860 }
Jeff Brown70825162012-03-28 17:27:48 -0700861 mHandler = new PolicyHandler();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800862 mOrientationListener = new MyOrientationListener(mContext);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700863 try {
864 mOrientationListener.setCurrentRotation(windowManager.getRotation());
865 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700866 mSettingsObserver = new SettingsObserver(mHandler);
867 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800868 mShortcutManager = new ShortcutManager(context, mHandler);
869 mShortcutManager.observe();
870 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
871 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
872 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
873 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700874 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
875 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
876 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
877 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
878 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
879 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
880 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
881 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700882
Jeff Brown96307042012-07-27 15:51:34 -0700883 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
884 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800885 "PhoneWindowManager.mBroadcastWakeLock");
886 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700887 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400888 com.android.internal.R.integer.config_lidOpenRotation);
889 mCarDockRotation = readRotation(
890 com.android.internal.R.integer.config_carDockRotation);
891 mDeskDockRotation = readRotation(
892 com.android.internal.R.integer.config_deskDockRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400893 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
894 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
895 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
896 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700897 mLidKeyboardAccessibility = mContext.getResources().getInteger(
898 com.android.internal.R.integer.config_lidKeyboardAccessibility);
899 mLidNavigationAccessibility = mContext.getResources().getInteger(
900 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -0700901 mLidControlsSleep = mContext.getResources().getBoolean(
902 com.android.internal.R.bool.config_lidControlsSleep);
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700903 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800904 IntentFilter filter = new IntentFilter();
905 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
906 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
907 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
908 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700909 filter.addAction(Intent.ACTION_DOCK_EVENT);
910 Intent intent = context.registerReceiver(mDockReceiver, filter);
911 if (intent != null) {
912 // Retrieve current sticky dock event broadcast.
913 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
914 Intent.EXTRA_DOCK_STATE_UNDOCKED);
915 }
Daniel Sandler7e37df52011-11-16 22:08:23 -0800916
Jeff Brown6aaf2952012-10-05 16:01:08 -0700917 // register for dream-related broadcasts
918 filter = new IntentFilter();
919 filter.addAction(Intent.ACTION_DREAMING_STARTED);
920 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
921 context.registerReceiver(mDreamReceiver, filter);
922
Christopher Tate5e08af02012-09-21 17:17:22 -0700923 // register for multiuser-relevant broadcasts
924 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
925 context.registerReceiver(mMultiuserReceiver, filter);
926
Jeff Brownc2346132012-04-13 01:55:38 -0700927 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700928 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
929 com.android.internal.R.array.config_longPressVibePattern);
930 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
931 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -0800932 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
933 com.android.internal.R.array.config_keyboardTapVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700934 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
935 com.android.internal.R.array.config_safeModeDisabledVibePattern);
936 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
937 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -0400938
Christopher Tatee90585f2012-03-05 18:56:25 -0800939 mScreenshotChordEnabled = mContext.getResources().getBoolean(
940 com.android.internal.R.bool.config_enableScreenshotChord);
941
Joe Onoratoea495d42011-04-06 11:41:11 -0700942 // Controls rotation and the like.
943 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -0700944
945 // Match current screen state.
946 if (mPowerManager.isScreenOn()) {
947 screenTurningOn(null);
948 } else {
949 screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
950 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700951 }
952
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800953 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -0700954 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700955 mDisplay = display;
956
957 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700958 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700959 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700960 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700961 mLandscapeRotation = Surface.ROTATION_0;
962 mSeascapeRotation = Surface.ROTATION_180;
963 if (mContext.getResources().getBoolean(
964 com.android.internal.R.bool.config_reverseDefaultRotation)) {
965 mPortraitRotation = Surface.ROTATION_90;
966 mUpsideDownRotation = Surface.ROTATION_270;
967 } else {
968 mPortraitRotation = Surface.ROTATION_270;
969 mUpsideDownRotation = Surface.ROTATION_90;
970 }
971 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700972 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700973 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700974 mPortraitRotation = Surface.ROTATION_0;
975 mUpsideDownRotation = Surface.ROTATION_180;
976 if (mContext.getResources().getBoolean(
977 com.android.internal.R.bool.config_reverseDefaultRotation)) {
978 mLandscapeRotation = Surface.ROTATION_270;
979 mSeascapeRotation = Surface.ROTATION_90;
980 } else {
981 mLandscapeRotation = Surface.ROTATION_90;
982 mSeascapeRotation = Surface.ROTATION_270;
983 }
984 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700985
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700986 mStatusBarHeight = mContext.getResources().getDimensionPixelSize(
987 com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700988
Daniel Sandler9f65c4c2012-04-26 01:35:35 -0400989 // Height of the navigation bar when presented horizontally at bottom
990 mNavigationBarHeightForRotation[mPortraitRotation] =
991 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Daniel Sandler4a066c52012-04-20 14:49:13 -0400992 mContext.getResources().getDimensionPixelSize(
993 com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -0400994 mNavigationBarHeightForRotation[mLandscapeRotation] =
995 mNavigationBarHeightForRotation[mSeascapeRotation] =
996 mContext.getResources().getDimensionPixelSize(
997 com.android.internal.R.dimen.navigation_bar_height_landscape);
998
999 // Width of the navigation bar when presented vertically along one side
1000 mNavigationBarWidthForRotation[mPortraitRotation] =
1001 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1002 mNavigationBarWidthForRotation[mLandscapeRotation] =
1003 mNavigationBarWidthForRotation[mSeascapeRotation] =
Daniel Sandler4a066c52012-04-20 14:49:13 -04001004 mContext.getResources().getDimensionPixelSize(
1005 com.android.internal.R.dimen.navigation_bar_width);
1006
1007 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001008 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001009
1010 if (shortSizeDp < 600) {
1011 // 0-599dp: "phone" UI with a separate status & navigation bar
1012 mHasSystemNavBar = false;
1013 mNavigationBarCanMove = true;
1014 } else if (shortSizeDp < 720) {
Daniel Sandleref863702012-07-11 10:03:34 -04001015 // 600+dp: "phone" UI with modifications for larger screens
Daniel Sandler4a066c52012-04-20 14:49:13 -04001016 mHasSystemNavBar = false;
1017 mNavigationBarCanMove = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001018 }
Daniel Sandler36412a72011-08-04 09:35:13 -04001019
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001020 if (!mHasSystemNavBar) {
1021 mHasNavigationBar = mContext.getResources().getBoolean(
1022 com.android.internal.R.bool.config_showNavigationBar);
1023 // Allow a system property to override this. Used by the emulator.
1024 // See also hasNavigationBar().
1025 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1026 if (! "".equals(navBarOverride)) {
1027 if (navBarOverride.equals("1")) mHasNavigationBar = false;
1028 else if (navBarOverride.equals("0")) mHasNavigationBar = true;
1029 }
1030 } else {
1031 mHasNavigationBar = false;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001032 }
1033
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001034 if (mHasSystemNavBar) {
1035 // The system bar is always at the bottom. If you are watching
1036 // a video in landscape, we don't need to hide it if we can still
1037 // show a 16:9 aspect ratio with it.
Dianne Hackborndde331c2012-08-03 14:01:57 -07001038 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001039 int barHeightDp = mNavigationBarHeightForRotation[mLandscapeRotation]
Dianne Hackborndde331c2012-08-03 14:01:57 -07001040 * DisplayMetrics.DENSITY_DEFAULT / density;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001041 int aspect = ((shortSizeDp-barHeightDp) * 16) / longSizeDp;
1042 // We have computed the aspect ratio with the bar height taken
1043 // out to be 16:aspect. If this is less than 9, then hiding
1044 // the navigation bar will provide more useful space for wide
1045 // screen movies.
1046 mCanHideNavigationBar = aspect < 9;
1047 } else if (mHasNavigationBar) {
1048 // The navigation bar is at the right in landscape; it seems always
1049 // useful to hide it for showing a video.
1050 mCanHideNavigationBar = true;
1051 } else {
1052 mCanHideNavigationBar = false;
1053 }
Erik Gilling9a41ef82011-09-26 19:21:03 -07001054
Jeff Brown27f1d672012-10-17 18:32:34 -07001055 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1056 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001057 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
1058 mHdmiRotation = mPortraitRotation;
1059 } else {
1060 mHdmiRotation = mLandscapeRotation;
1061 }
Jeff Brown74bea062012-10-25 12:16:10 -07001062 mHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Dianne Hackborn9d132642011-04-21 17:26:39 -07001063 }
1064
Dianne Hackbornc777e072010-02-12 13:07:59 -08001065 public void updateSettings() {
1066 ContentResolver resolver = mContext.getContentResolver();
1067 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001068 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001069 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001070 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001071 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1072 UserHandle.USER_CURRENT);
1073 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001074 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001075 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1076 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001077
Jeff Brown207673cd2012-06-05 17:47:11 -07001078 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001079 int userRotation = Settings.System.getIntForUser(resolver,
1080 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1081 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001082 if (mUserRotation != userRotation) {
1083 mUserRotation = userRotation;
1084 updateRotation = true;
1085 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001086 int userRotationMode = Settings.System.getIntForUser(resolver,
1087 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001088 WindowManagerPolicy.USER_ROTATION_FREE :
1089 WindowManagerPolicy.USER_ROTATION_LOCKED;
1090 if (mUserRotationMode != userRotationMode) {
1091 mUserRotationMode = userRotationMode;
1092 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001093 updateOrientationListenerLp();
1094 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001095
Dianne Hackbornc777e072010-02-12 13:07:59 -08001096 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001097 int pointerLocation = Settings.System.getIntForUser(resolver,
1098 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001099 if (mPointerLocationMode != pointerLocation) {
1100 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001101 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1102 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001103 }
1104 }
1105 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001106 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1107 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1108 String imId = Settings.Secure.getStringForUser(resolver,
1109 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001110 boolean hasSoftInput = imId != null && imId.length() > 0;
1111 if (mHasSoftInput != hasSoftInput) {
1112 mHasSoftInput = hasSoftInput;
1113 updateRotation = true;
1114 }
1115 }
1116 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001117 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001118 }
Jeff Brown70825162012-03-28 17:27:48 -07001119 }
1120
1121 private void enablePointerLocation() {
1122 if (mPointerLocationView == null) {
1123 mPointerLocationView = new PointerLocationView(mContext);
1124 mPointerLocationView.setPrintCoords(false);
1125
Dianne Hackbornc777e072010-02-12 13:07:59 -08001126 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1127 WindowManager.LayoutParams.MATCH_PARENT,
1128 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001129 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001130 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1131 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1132 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1133 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001134 if (ActivityManager.isHighEndGfx()) {
1135 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1136 lp.privateFlags |=
1137 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1138 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001139 lp.format = PixelFormat.TRANSLUCENT;
1140 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001141 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001142 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001143 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001144 wm.addView(mPointerLocationView, lp);
1145
Jeff Brownac143512012-04-05 18:57:33 -07001146 mPointerLocationInputChannel =
1147 mWindowManagerFuncs.monitorInput("PointerLocationView");
1148 mPointerLocationInputEventReceiver =
1149 new PointerLocationInputEventReceiver(mPointerLocationInputChannel,
1150 Looper.myLooper(), mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001151 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001152 }
Jeff Brown70825162012-03-28 17:27:48 -07001153
1154 private void disablePointerLocation() {
1155 if (mPointerLocationInputEventReceiver != null) {
1156 mPointerLocationInputEventReceiver.dispose();
1157 mPointerLocationInputEventReceiver = null;
1158 }
1159
1160 if (mPointerLocationInputChannel != null) {
1161 mPointerLocationInputChannel.dispose();
1162 mPointerLocationInputChannel = null;
1163 }
1164
1165 if (mPointerLocationView != null) {
1166 WindowManager wm = (WindowManager)
1167 mContext.getSystemService(Context.WINDOW_SERVICE);
1168 wm.removeView(mPointerLocationView);
1169 mPointerLocationView = null;
1170 }
1171 }
1172
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001173 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001174 try {
1175 int rotation = mContext.getResources().getInteger(resID);
1176 switch (rotation) {
1177 case 0:
1178 return Surface.ROTATION_0;
1179 case 90:
1180 return Surface.ROTATION_90;
1181 case 180:
1182 return Surface.ROTATION_180;
1183 case 270:
1184 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001185 }
1186 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001187 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001188 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001189 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001190 }
1191
1192 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001193 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001194 public int checkAddPermission(WindowManager.LayoutParams attrs) {
1195 int type = attrs.type;
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07001196
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001197 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1198 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001199 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001200 }
1201 String permission = null;
1202 switch (type) {
1203 case TYPE_TOAST:
1204 // XXX right now the app process has complete control over
1205 // this... should introduce a token to let the system
1206 // monitor/control what they are doing.
1207 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001208 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001209 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001210 case TYPE_WALLPAPER:
1211 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001212 break;
1213 case TYPE_PHONE:
1214 case TYPE_PRIORITY_PHONE:
1215 case TYPE_SYSTEM_ALERT:
1216 case TYPE_SYSTEM_ERROR:
1217 case TYPE_SYSTEM_OVERLAY:
1218 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
1219 break;
1220 default:
1221 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1222 }
1223 if (permission != null) {
1224 if (mContext.checkCallingOrSelfPermission(permission)
1225 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001226 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001227 }
1228 }
Jeff Brown98365d72012-08-19 20:30:52 -07001229 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001230 }
Craig Mautner88400d32012-09-30 12:35:45 -07001231
1232 @Override
1233 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1234
1235 // If this switch statement is modified, modify the comment in the declarations of
1236 // the type in {@link WindowManager.LayoutParams} as well.
1237 switch (attrs.type) {
1238 default:
1239 // These are the windows that by default are shown only to the user that created
1240 // them. If this needs to be overridden, set
1241 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1242 // {@link WindowManager.LayoutParams}. Note that permission
1243 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1244 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1245 return true;
1246 }
1247 break;
1248
1249 // These are the windows that by default are shown to all users. However, to
1250 // protect against spoofing, check permissions below.
1251 case TYPE_APPLICATION_STARTING:
1252 case TYPE_BOOT_PROGRESS:
1253 case TYPE_DISPLAY_OVERLAY:
1254 case TYPE_HIDDEN_NAV_CONSUMER:
1255 case TYPE_KEYGUARD:
1256 case TYPE_KEYGUARD_DIALOG:
1257 case TYPE_MAGNIFICATION_OVERLAY:
1258 case TYPE_NAVIGATION_BAR:
1259 case TYPE_NAVIGATION_BAR_PANEL:
1260 case TYPE_PHONE:
1261 case TYPE_POINTER:
1262 case TYPE_PRIORITY_PHONE:
1263 case TYPE_RECENTS_OVERLAY:
1264 case TYPE_SEARCH_BAR:
1265 case TYPE_STATUS_BAR:
1266 case TYPE_STATUS_BAR_PANEL:
1267 case TYPE_STATUS_BAR_SUB_PANEL:
1268 case TYPE_SYSTEM_DIALOG:
1269 case TYPE_UNIVERSE_BACKGROUND:
1270 case TYPE_VOLUME_OVERLAY:
1271 break;
1272 }
1273
1274 // Check if third party app has set window to system window type.
1275 return mContext.checkCallingOrSelfPermission(
1276 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1277 != PackageManager.PERMISSION_GRANTED;
1278 }
1279
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001280 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1281 switch (attrs.type) {
1282 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001283 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001284 case TYPE_TOAST:
1285 // These types of windows can't receive input events.
1286 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1287 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001288 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001289 break;
1290 }
1291 }
1292
1293 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001294 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001295 }
1296
Jeff Browndaa37532012-05-01 15:54:03 -07001297 private boolean isHidden(int accessibilityMode) {
1298 switch (accessibilityMode) {
1299 case 1:
1300 return mLidState == LID_CLOSED;
1301 case 2:
1302 return mLidState == LID_OPEN;
1303 default:
1304 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001305 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001306 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001307
Jeff Browndaa37532012-05-01 15:54:03 -07001308 private boolean isBuiltInKeyboardVisible() {
1309 return mHaveBuiltInKeyboard && !isHidden(mLidKeyboardAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001310 }
1311
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001312 /** {@inheritDoc} */
Jeff Browndaa37532012-05-01 15:54:03 -07001313 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1314 int navigationPresence) {
1315 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1316
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001317 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001318 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001319
Jeff Browndaa37532012-05-01 15:54:03 -07001320 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1321 || (keyboardPresence == PRESENCE_INTERNAL
1322 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001323 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001324 if (!mHasSoftInput) {
1325 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1326 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001327 }
1328
Jeff Browndaa37532012-05-01 15:54:03 -07001329 if (config.navigation == Configuration.NAVIGATION_NONAV
1330 || (navigationPresence == PRESENCE_INTERNAL
1331 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001332 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001333 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001334 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001335
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001336 /** {@inheritDoc} */
1337 public int windowTypeToLayerLw(int type) {
1338 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001339 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001340 }
1341 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001342 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001343 return 1;
1344 case TYPE_WALLPAPER:
1345 // wallpaper is at the bottom, though the window manager may move it.
1346 return 2;
1347 case TYPE_PHONE:
1348 return 3;
1349 case TYPE_SEARCH_BAR:
1350 return 4;
Craig Mautner88400d32012-09-30 12:35:45 -07001351 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001352 case TYPE_SYSTEM_DIALOG:
1353 return 5;
1354 case TYPE_TOAST:
1355 // toasts and the plugged-in battery thing
1356 return 6;
1357 case TYPE_PRIORITY_PHONE:
1358 // SIM errors and unlock. Not sure if this really should be in a high layer.
1359 return 7;
1360 case TYPE_DREAM:
1361 // used for Dreams (screensavers with TYPE_DREAM windows)
1362 return 8;
1363 case TYPE_SYSTEM_ALERT:
1364 // like the ANR / app crashed dialogs
1365 return 9;
1366 case TYPE_INPUT_METHOD:
1367 // on-screen keyboards and other such input method user interfaces go here.
1368 return 10;
1369 case TYPE_INPUT_METHOD_DIALOG:
1370 // on-screen keyboards and other such input method user interfaces go here.
1371 return 11;
1372 case TYPE_KEYGUARD:
1373 // the keyguard; nothing on top of these can take focus, since they are
1374 // responsible for power management when displayed.
1375 return 12;
1376 case TYPE_KEYGUARD_DIALOG:
1377 return 13;
1378 case TYPE_STATUS_BAR_SUB_PANEL:
1379 return 14;
1380 case TYPE_STATUS_BAR:
1381 return 15;
1382 case TYPE_STATUS_BAR_PANEL:
1383 return 16;
1384 case TYPE_VOLUME_OVERLAY:
1385 // the on-screen volume indicator and controller shown when the user
1386 // changes the device volume
1387 return 17;
1388 case TYPE_SYSTEM_OVERLAY:
1389 // the on-screen volume indicator and controller shown when the user
1390 // changes the device volume
1391 return 18;
1392 case TYPE_NAVIGATION_BAR:
1393 // the navigation bar, if available, shows atop most things
1394 return 19;
1395 case TYPE_NAVIGATION_BAR_PANEL:
1396 // some panels (e.g. search) need to show on top of the navigation bar
1397 return 20;
1398 case TYPE_SYSTEM_ERROR:
1399 // system-level error dialogs
1400 return 21;
1401 case TYPE_MAGNIFICATION_OVERLAY:
1402 // used to highlight the magnified portion of a display
1403 return 22;
1404 case TYPE_DISPLAY_OVERLAY:
1405 // used to simulate secondary display devices
1406 return 23;
1407 case TYPE_DRAG:
1408 // the drag layer: input for drag-and-drop is associated with this window,
1409 // which sits above all other focusable windows
1410 return 24;
1411 case TYPE_SECURE_SYSTEM_OVERLAY:
1412 return 25;
1413 case TYPE_BOOT_PROGRESS:
1414 return 26;
1415 case TYPE_POINTER:
1416 // the (mouse) pointer layer
1417 return 27;
1418 case TYPE_HIDDEN_NAV_CONSUMER:
1419 return 28;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001420 }
1421 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001422 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001423 }
1424
1425 /** {@inheritDoc} */
1426 public int subWindowTypeToLayerLw(int type) {
1427 switch (type) {
1428 case TYPE_APPLICATION_PANEL:
1429 case TYPE_APPLICATION_ATTACHED_DIALOG:
1430 return APPLICATION_PANEL_SUBLAYER;
1431 case TYPE_APPLICATION_MEDIA:
1432 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001433 case TYPE_APPLICATION_MEDIA_OVERLAY:
1434 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001435 case TYPE_APPLICATION_SUB_PANEL:
1436 return APPLICATION_SUB_PANEL_SUBLAYER;
1437 }
1438 Log.e(TAG, "Unknown sub-window type: " + type);
1439 return 0;
1440 }
1441
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001442 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001443 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001444 }
1445
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001446 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001447 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001448 }
1449
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001450 public boolean hasSystemNavBar() {
1451 return mHasSystemNavBar;
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001452 }
1453
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001454 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001455 if (mHasNavigationBar) {
1456 // For a basic navigation bar, when we are in landscape mode we place
1457 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001458 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1459 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001460 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001461 }
1462 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001463 }
1464
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001465 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001466 if (mHasSystemNavBar) {
1467 // For the system navigation bar, we always place it at the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001468 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001469 }
1470 if (mHasNavigationBar) {
1471 // For a basic navigation bar, when we are in portrait mode we place
1472 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001473 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1474 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001475 }
1476 }
1477 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001478 }
1479
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001480 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1481 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001482 }
1483
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001484 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001485 // If we don't have a system nav bar, then there is a separate status
1486 // bar at the top of the display. We don't count that as part of the
1487 // fixed decor, since it can hide; however, for purposes of configurations,
1488 // we do want to exclude it since applications can't generally use that part
1489 // of the screen.
1490 if (!mHasSystemNavBar) {
1491 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
1492 }
1493 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001494 }
1495
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001496 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001497 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) {
1498 return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD;
1499 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001500
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001501 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001502 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001503 switch (attrs.type) {
1504 case TYPE_STATUS_BAR:
1505 case TYPE_NAVIGATION_BAR:
1506 case TYPE_WALLPAPER:
1507 case TYPE_DREAM:
1508 case TYPE_UNIVERSE_BACKGROUND:
1509 case TYPE_KEYGUARD:
1510 return false;
1511 default:
1512 return true;
1513 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001514 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001515
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001516 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001517 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001518 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1519 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
1520 int icon, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001521 if (!SHOW_STARTING_ANIMATIONS) {
1522 return null;
1523 }
1524 if (packageName == null) {
1525 return null;
1526 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001527
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001528 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001529 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001530 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1531 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1532 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001533 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001534 try {
1535 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001536 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001537 } catch (PackageManager.NameNotFoundException e) {
1538 // Ignore
1539 }
1540 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001541
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001542 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001543 final TypedArray ta = win.getWindowStyle();
1544 if (ta.getBoolean(
1545 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1546 || ta.getBoolean(
1547 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001548 return null;
1549 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001550
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001551 Resources r = context.getResources();
1552 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001553
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001554 win.setType(
1555 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1556 // Force the window flags: this is a fake window, so it is not really
1557 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1558 // flag because we do know that the next window will take input
1559 // focus, so we want to get the IME window up on top of us right away.
1560 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001561 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001562 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1563 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1564 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001565 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001566 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1567 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1568 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001569
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001570 if (!compatInfo.supportsScreen()) {
1571 win.addFlags(WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW);
1572 }
1573
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001574 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001575 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001576
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001577 final WindowManager.LayoutParams params = win.getAttributes();
1578 params.token = appToken;
1579 params.packageName = packageName;
1580 params.windowAnimations = win.getWindowStyle().getResourceId(
1581 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001582 params.privateFlags |=
1583 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001584 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001585 params.setTitle("Starting " + packageName);
1586
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001587 WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001588 View view = win.getDecorView();
1589
1590 if (win.isFloating()) {
1591 // Whoops, there is no way to display an animation/preview
1592 // of such a thing! After all that work... let's skip it.
1593 // (Note that we must do this here because it is in
1594 // getDecorView() where the theme is evaluated... maybe
1595 // we should peek the floating attribute from the theme
1596 // earlier.)
1597 return null;
1598 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001599
Craig Mautner6fbda632012-07-03 09:26:39 -07001600 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001601 TAG, "Adding starting window for " + packageName
1602 + " / " + appToken + ": "
1603 + (view.getParent() != null ? view : null));
1604
1605 wm.addView(view, params);
1606
1607 // Only return the view if it was successfully added to the
1608 // window manager... which we can tell by it having a parent.
1609 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001610 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001611 // ignore
1612 Log.w(TAG, appToken + " already running, starting window not displayed");
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001613 } catch (RuntimeException e) {
1614 // don't crash if something else bad happens, for example a
1615 // failure loading resources because we are loading from an app
1616 // on external storage that has been unmounted.
1617 Log.w(TAG, appToken + " failed creating starting window", e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001618 }
1619
1620 return null;
1621 }
1622
1623 /** {@inheritDoc} */
1624 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001625 if (DEBUG_STARTING_WINDOW) {
1626 RuntimeException e = new RuntimeException("here");
1627 e.fillInStackTrace();
1628 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1629 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001630
1631 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001632 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001633 wm.removeView(window);
1634 }
1635 }
1636
1637 /**
1638 * Preflight adding a window to the system.
1639 *
1640 * Currently enforces that three window types are singletons:
1641 * <ul>
1642 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001643 * <li>KEYGUARD_TYPE</li>
1644 * </ul>
1645 *
1646 * @param win The window to be added
1647 * @param attrs Information about the window to be added
1648 *
Jeff Brown98365d72012-08-19 20:30:52 -07001649 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1650 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001651 */
1652 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1653 switch (attrs.type) {
1654 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001655 mContext.enforceCallingOrSelfPermission(
1656 android.Manifest.permission.STATUS_BAR_SERVICE,
1657 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001658 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001659 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001660 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001661 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001662 }
1663 mStatusBar = win;
1664 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001665 case TYPE_NAVIGATION_BAR:
1666 mContext.enforceCallingOrSelfPermission(
1667 android.Manifest.permission.STATUS_BAR_SERVICE,
1668 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001669 if (mNavigationBar != null) {
1670 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001671 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001672 }
1673 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001674 mNavigationBar = win;
1675 if (DEBUG_LAYOUT) Log.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
1676 break;
Jim Millere898ac52012-04-06 17:10:57 -07001677 case TYPE_NAVIGATION_BAR_PANEL:
1678 mContext.enforceCallingOrSelfPermission(
1679 android.Manifest.permission.STATUS_BAR_SERVICE,
1680 "PhoneWindowManager");
1681 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001682 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001683 mContext.enforceCallingOrSelfPermission(
1684 android.Manifest.permission.STATUS_BAR_SERVICE,
1685 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001686 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001687 case TYPE_STATUS_BAR_SUB_PANEL:
1688 mContext.enforceCallingOrSelfPermission(
1689 android.Manifest.permission.STATUS_BAR_SERVICE,
1690 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001691 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001692 case TYPE_KEYGUARD:
1693 if (mKeyguard != null) {
Jeff Brown98365d72012-08-19 20:30:52 -07001694 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001695 }
1696 mKeyguard = win;
1697 break;
1698 }
Jeff Brown98365d72012-08-19 20:30:52 -07001699 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001700 }
1701
1702 /** {@inheritDoc} */
1703 public void removeWindowLw(WindowState win) {
1704 if (mStatusBar == win) {
1705 mStatusBar = null;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001706 } else if (mKeyguard == win) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001707 mKeyguard = null;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001708 } else if (mNavigationBar == win) {
1709 mNavigationBar = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001710 }
1711 }
1712
1713 static final boolean PRINT_ANIM = false;
1714
1715 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001716 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001717 public int selectAnimationLw(WindowState win, int transit) {
1718 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1719 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001720 if (win == mStatusBar) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001721 if (transit == TRANSIT_EXIT
1722 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001723 return R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001724 } else if (transit == TRANSIT_ENTER
1725 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001726 return R.anim.dock_top_enter;
1727 }
1728 } else if (win == mNavigationBar) {
1729 // This can be on either the bottom or the right.
1730 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001731 if (transit == TRANSIT_EXIT
1732 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001733 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001734 } else if (transit == TRANSIT_ENTER
1735 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001736 return R.anim.dock_bottom_enter;
1737 }
1738 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001739 if (transit == TRANSIT_EXIT
1740 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001741 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001742 } else if (transit == TRANSIT_ENTER
1743 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001744 return R.anim.dock_right_enter;
1745 }
1746 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001747 }
1748
1749 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001750 if (win.hasAppShownWindows()) {
1751 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1752 return com.android.internal.R.anim.app_starting_exit;
1753 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001754 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001755 && transit == TRANSIT_ENTER) {
1756 // Special case: we are animating in a dream, while the keyguard
1757 // is shown. We don't want an animation on the dream, because
1758 // we need it shown immediately with the keyguard animating away
1759 // to reveal it.
1760 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001761 }
1762
1763 return 0;
1764 }
1765
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07001766 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
1767 return AnimationUtils.loadAnimation(mContext, onWallpaper
1768 ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter
1769 : com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001770 }
1771
Jeff Brown4d396052010-10-29 21:50:21 -07001772 static ITelephony getTelephonyService() {
Mike Lockwoodf5f4ec92011-11-08 14:05:31 -08001773 return ITelephony.Stub.asInterface(
Jeff Brown4d396052010-10-29 21:50:21 -07001774 ServiceManager.checkService(Context.TELEPHONY_SERVICE));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001775 }
1776
Jeff Brown4d396052010-10-29 21:50:21 -07001777 static IAudioService getAudioService() {
1778 IAudioService audioService = IAudioService.Stub.asInterface(
1779 ServiceManager.checkService(Context.AUDIO_SERVICE));
1780 if (audioService == null) {
1781 Log.w(TAG, "Unable to find IAudioService interface.");
1782 }
1783 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001784 }
1785
1786 boolean keyguardOn() {
1787 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
1788 }
1789
1790 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
1791 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
1792 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
1793 };
1794
1795 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001796 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001797 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001798 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08001799 final int keyCode = event.getKeyCode();
1800 final int repeatCount = event.getRepeatCount();
1801 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001802 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08001803 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
1804 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001805
Jeff Brown40013652012-05-16 21:22:36 -07001806 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001807 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001808 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
1809 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001810 }
1811
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001812 // If we think we might have a volume down & power key chord on the way
1813 // but we're not sure, then tell the dispatcher to wait a little while and
1814 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08001815 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001816 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
1817 final long now = SystemClock.uptimeMillis();
1818 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
1819 if (now < timeoutTime) {
1820 return timeoutTime - now;
1821 }
1822 }
1823 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
1824 && mVolumeDownKeyConsumedByScreenshotChord) {
1825 if (!down) {
1826 mVolumeDownKeyConsumedByScreenshotChord = false;
1827 }
1828 return -1;
1829 }
1830 }
1831
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001832 // First we always handle the home key here, so applications
1833 // can never break it, although if keyguard is on, we do let
1834 // it handle it, because that gives us the correct 5 second
1835 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001836 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001837
Jeff Brown49ed71d2010-12-06 17:13:33 -08001838 // If we have released the home key, and didn't do anything else
1839 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07001840 if (!down) {
1841 final boolean homeWasLongPressed = mHomeLongPressed;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001842 mHomePressed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07001843 mHomeLongPressed = false;
1844 if (!homeWasLongPressed) {
Michael Jurka01de93d2012-04-13 09:32:47 -07001845 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1846 try {
1847 IStatusBarService statusbar = getStatusBarService();
1848 if (statusbar != null) {
1849 statusbar.cancelPreloadRecentApps();
1850 }
1851 } catch (RemoteException e) {
1852 Slog.e(TAG, "RemoteException when showing recent apps", e);
1853 // re-acquire status bar service next time it is needed.
1854 mStatusBarService = null;
Dianne Hackborn42e620c2012-06-24 13:20:51 -07001855 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08001856 }
1857
Michael Jurka7f2668c2012-03-27 07:49:52 -07001858 mHomePressed = false;
1859 if (!canceled) {
1860 // If an incoming call is ringing, HOME is totally disabled.
1861 // (The user is already on the InCallScreen at this point,
1862 // and his ONLY options are to answer or reject the call.)
1863 boolean incomingRinging = false;
1864 try {
1865 ITelephony telephonyService = getTelephonyService();
1866 if (telephonyService != null) {
1867 incomingRinging = telephonyService.isRinging();
1868 }
1869 } catch (RemoteException ex) {
1870 Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
1871 }
1872
1873 if (incomingRinging) {
1874 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
1875 } else {
1876 launchHomeFromHotKey();
1877 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08001878 } else {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001879 Log.i(TAG, "Ignoring HOME; event canceled.");
Jeff Brown49ed71d2010-12-06 17:13:33 -08001880 }
Michael Jurka7f2668c2012-03-27 07:49:52 -07001881 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001882 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08001883 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001884
1885 // If a system window has focus, then it doesn't make sense
1886 // right now to interact with applications.
1887 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
1888 if (attrs != null) {
1889 final int type = attrs.type;
1890 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
1891 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
1892 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001893 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001894 }
1895 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
1896 for (int i=0; i<typeCount; i++) {
1897 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
1898 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001899 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001900 }
1901 }
1902 }
Jeff Brown98392ef2011-09-12 18:24:59 -07001903 if (down) {
Michael Jurka40040332012-05-29 08:25:32 -07001904 if (!mHomePressed && mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001905 try {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07001906 IStatusBarService statusbar = getStatusBarService();
1907 if (statusbar != null) {
1908 statusbar.preloadRecentApps();
1909 }
Michael Jurka7f2668c2012-03-27 07:49:52 -07001910 } catch (RemoteException e) {
1911 Slog.e(TAG, "RemoteException when preloading recent apps", e);
Dianne Hackborn42e620c2012-06-24 13:20:51 -07001912 // re-acquire status bar service next time it is needed.
1913 mStatusBarService = null;
Michael Jurka7f2668c2012-03-27 07:49:52 -07001914 }
1915 }
Jeff Brown98392ef2011-09-12 18:24:59 -07001916 if (repeatCount == 0) {
1917 mHomePressed = true;
1918 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
1919 if (!keyguardOn) {
1920 handleLongPressOnHome();
1921 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001922 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001923 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001924 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001925 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001926 // Hijack modified menu keys for debugging features
1927 final int chordBug = KeyEvent.META_SHIFT_ON;
1928
1929 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001930 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001931 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001932 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
1933 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001934 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001935 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001936 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001937 Intent service = new Intent();
1938 service.setClassName(mContext, "com.android.server.LoadAverageService");
1939 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07001940 boolean shown = Settings.Global.getInt(
1941 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001942 if (!shown) {
1943 mContext.startService(service);
1944 } else {
1945 mContext.stopService(service);
1946 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07001947 Settings.Global.putInt(
1948 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001949 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001950 }
1951 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001952 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001953 if (down) {
1954 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001955 mSearchKeyShortcutPending = true;
1956 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001957 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001958 } else {
1959 mSearchKeyShortcutPending = false;
1960 if (mConsumeSearchKeyUp) {
1961 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001962 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001963 }
1964 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001965 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001966 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Jeff Brown602ab322012-05-16 13:33:47 -07001967 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08001968 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS);
Jeff Brown49ed71d2010-12-06 17:13:33 -08001969 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001970 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07001971 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
1972 if (down) {
1973 if (repeatCount == 0) {
1974 mAssistKeyLongPressed = false;
1975 } else if (repeatCount == 1) {
1976 mAssistKeyLongPressed = true;
1977 if (!keyguardOn) {
1978 launchAssistLongPressAction();
1979 }
1980 }
1981 } else {
1982 if (mAssistKeyLongPressed) {
1983 mAssistKeyLongPressed = false;
1984 } else {
1985 if (!keyguardOn) {
1986 launchAssistAction();
1987 }
1988 }
1989 }
1990 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001991 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
1992 if (down && repeatCount == 0) {
1993 mHandler.post(mScreenshotRunnable);
1994 }
1995 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001996 }
Jeff Browncaab4d02010-12-09 22:13:41 -08001997
Jeff Brownc1fb48d2010-12-08 16:52:09 -08001998 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08001999 // Any printing key that is chorded with Search should be consumed
2000 // even if no shortcut was invoked. This prevents text from being
2001 // inadvertently inserted when using a keyboard that has built-in macro
2002 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002003 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002004 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2005 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002006 mConsumeSearchKeyUp = true;
2007 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002008 if (down && repeatCount == 0 && !keyguardOn) {
2009 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2010 if (shortcutIntent != null) {
2011 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002012 try {
2013 mContext.startActivity(shortcutIntent);
2014 } catch (ActivityNotFoundException ex) {
2015 Slog.w(TAG, "Dropping shortcut key combination because "
2016 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002017 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002018 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002019 } else {
2020 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002021 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002022 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002023 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002024 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002025 }
2026 }
2027
Jeff Brown68b909d2011-12-07 16:36:01 -08002028 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002029 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002030 && (metaState & KeyEvent.META_META_ON) != 0) {
2031 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002032 if (kcm.isPrintingKey(keyCode)) {
2033 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2034 metaState & ~(KeyEvent.META_META_ON
2035 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2036 if (shortcutIntent != null) {
2037 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2038 try {
2039 mContext.startActivity(shortcutIntent);
2040 } catch (ActivityNotFoundException ex) {
2041 Slog.w(TAG, "Dropping shortcut key combination because "
2042 + "the activity to which it is registered was not found: "
2043 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2044 }
2045 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002046 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002047 }
2048 }
2049
Jeff Brown6651a632011-11-28 12:59:11 -08002050 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002051 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002052 String category = sApplicationLaunchKeyCategories.get(keyCode);
2053 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002054 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002055 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2056 try {
2057 mContext.startActivity(intent);
2058 } catch (ActivityNotFoundException ex) {
2059 Slog.w(TAG, "Dropping application launch key because "
2060 + "the activity to which it is registered was not found: "
2061 + "keyCode=" + keyCode + ", category=" + category, ex);
2062 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002063 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002064 }
2065 }
2066
Jeff Brown68b909d2011-12-07 16:36:01 -08002067 // Display task switcher for ALT-TAB or Meta-TAB.
2068 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Jeff Brown602ab322012-05-16 13:33:47 -07002069 if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002070 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
2071 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2072 || KeyEvent.metaStateHasModifiers(
2073 shiftlessModifiers, KeyEvent.META_META_ON)) {
2074 mRecentAppsDialogHeldModifiers = shiftlessModifiers;
2075 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW);
2076 return -1;
2077 }
2078 }
2079 } else if (!down && mRecentAppsDialogHeldModifiers != 0
2080 && (metaState & mRecentAppsDialogHeldModifiers) == 0) {
2081 mRecentAppsDialogHeldModifiers = 0;
Jeff Brown602ab322012-05-16 13:33:47 -07002082 showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS :
2083 RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH);
Jeff Brown68b909d2011-12-07 16:36:01 -08002084 }
2085
Jeff Browncf39bdf2012-05-18 14:41:19 -07002086 // Handle keyboard language switching.
2087 if (down && repeatCount == 0
2088 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2089 || (keyCode == KeyEvent.KEYCODE_SPACE
2090 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2091 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2092 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2093 return -1;
2094 }
2095 if (mLanguageSwitchKeyPressed && !down
2096 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2097 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2098 mLanguageSwitchKeyPressed = false;
2099 return -1;
2100 }
2101
Jeff Brown68b909d2011-12-07 16:36:01 -08002102 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002103 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002104 }
2105
Jeff Brown3915bb82010-11-05 15:02:16 -07002106 /** {@inheritDoc} */
2107 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002108 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002109 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002110 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002111 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2112 + ", flags=" + event.getFlags()
2113 + ", keyCode=" + event.getKeyCode()
2114 + ", scanCode=" + event.getScanCode()
2115 + ", metaState=" + event.getMetaState()
2116 + ", repeatCount=" + event.getRepeatCount()
2117 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002118 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002119
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002120 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002121 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2122 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002123 final int keyCode = event.getKeyCode();
2124 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002125 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2126 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002127
Jeff Brown54875002011-04-06 15:33:01 -07002128 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002129 final FallbackAction fallbackAction;
2130 if (initialDown) {
2131 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2132 } else {
2133 fallbackAction = mFallbackActions.get(keyCode);
2134 }
2135
2136 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002137 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002138 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2139 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002140 }
2141
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002142 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2143 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002144 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002145 event.getAction(), fallbackAction.keyCode,
2146 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002147 event.getDeviceId(), event.getScanCode(),
2148 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002149
2150 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2151 fallbackEvent.recycle();
2152 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002153 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002154
2155 if (initialDown) {
2156 mFallbackActions.put(keyCode, fallbackAction);
2157 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2158 mFallbackActions.remove(keyCode);
2159 fallbackAction.recycle();
2160 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002161 }
2162 }
2163
Jeff Brown40013652012-05-16 21:22:36 -07002164 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002165 if (fallbackEvent == null) {
2166 Slog.d(TAG, "No fallback.");
2167 } else {
2168 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2169 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002170 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002171 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002172 }
2173
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002174 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
2175 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true);
2176 if ((actions & ACTION_PASS_TO_USER) != 0) {
2177 long delayMillis = interceptKeyBeforeDispatching(
2178 win, fallbackEvent, policyFlags);
2179 if (delayMillis == 0) {
2180 return true;
2181 }
2182 }
2183 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002184 }
2185
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002186 private void launchAssistLongPressAction() {
2187 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2188 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2189
2190 // launch the search activity
2191 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2192 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2193 try {
Jim Miller45308b12012-06-18 19:23:39 -07002194 // TODO: This only stops the factory-installed search manager.
2195 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002196 SearchManager searchManager = getSearchManager();
2197 if (searchManager != null) {
2198 searchManager.stopSearch();
2199 }
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002200 mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002201 } catch (ActivityNotFoundException e) {
2202 Slog.w(TAG, "No activity to handle assist long press action.", e);
2203 }
2204 }
2205
2206 private void launchAssistAction() {
2207 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002208 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07002209 .getAssistIntent(mContext, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002210 if (intent != null) {
2211 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2212 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2213 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2214 try {
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002215 mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
Jim Miller45308b12012-06-18 19:23:39 -07002216 } catch (ActivityNotFoundException e) {
2217 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002218 }
2219 }
2220 }
2221
2222 private SearchManager getSearchManager() {
2223 if (mSearchManager == null) {
2224 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2225 }
2226 return mSearchManager;
2227 }
2228
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002229 /**
2230 * A home key -> launch home action was detected. Take the appropriate action
2231 * given the situation with the keyguard.
2232 */
2233 void launchHomeFromHotKey() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07002234 if (mKeyguardMediator != null && mKeyguardMediator.isShowingAndNotHidden()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002235 // don't launch home if keyguard showing
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002236 } else if (!mHideLockScreen && mKeyguardMediator.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002237 // when in keyguard restricted mode, must first verify unlock
2238 // before launching home
2239 mKeyguardMediator.verifyUnlock(new OnKeyguardExitResult() {
2240 public void onKeyguardExitResult(boolean success) {
2241 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002242 try {
2243 ActivityManagerNative.getDefault().stopAppSwitches();
2244 } catch (RemoteException e) {
2245 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002246 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002247 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002248 }
2249 }
2250 });
2251 } else {
2252 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002253 try {
2254 ActivityManagerNative.getDefault().stopAppSwitches();
2255 } catch (RemoteException e) {
2256 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002257 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002258 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002259 }
2260 }
2261
Dianne Hackborne26ab702011-10-16 13:21:33 -07002262 /**
2263 * A delayed callback use to determine when it is okay to re-allow applications
2264 * to use certain system UI flags. This is used to prevent applications from
2265 * spamming system UI changes that prevent the navigation bar from being shown.
2266 */
2267 final Runnable mAllowSystemUiDelay = new Runnable() {
2268 @Override public void run() {
2269 }
2270 };
2271
2272 /**
2273 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2274 * to determine when the nav bar should be shown and prevent applications from
2275 * receiving those touches.
2276 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002277 final class HideNavInputEventReceiver extends InputEventReceiver {
2278 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2279 super(inputChannel, looper);
2280 }
2281
Dianne Hackborndf89e652011-10-06 22:35:11 -07002282 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002283 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002284 boolean handled = false;
2285 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002286 if (event instanceof MotionEvent
2287 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2288 final MotionEvent motionEvent = (MotionEvent)event;
2289 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002290 // When the user taps down, we re-show the nav bar.
2291 boolean changed = false;
2292 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002293 // Any user activity always causes us to show the
2294 // navigation controls, if they had been hidden.
2295 // We also clear the low profile and only content
2296 // flags so that tapping on the screen will atomically
2297 // restore all currently hidden screen decorations.
2298 int newVal = mResettingSystemUiFlags |
2299 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2300 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2301 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002302 if (mResettingSystemUiFlags != newVal) {
2303 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002304 changed = true;
2305 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002306 // We don't allow the system's nav bar to be hidden
2307 // again for 1 second, to prevent applications from
2308 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002309 newVal = mForceClearedSystemUiFlags |
2310 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002311 if (mForceClearedSystemUiFlags != newVal) {
2312 mForceClearedSystemUiFlags = newVal;
2313 changed = true;
2314 mHandler.postDelayed(new Runnable() {
2315 @Override public void run() {
2316 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002317 // Clear flags.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002318 mForceClearedSystemUiFlags &=
2319 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2320 }
2321 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2322 }
2323 }, 1000);
2324 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002325 }
2326 if (changed) {
2327 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2328 }
2329 }
2330 }
2331 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002332 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002333 }
2334 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002335 }
2336 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2337 new InputEventReceiver.Factory() {
2338 @Override
2339 public InputEventReceiver createInputEventReceiver(
2340 InputChannel inputChannel, Looper looper) {
2341 return new HideNavInputEventReceiver(inputChannel, looper);
2342 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002343 };
2344
2345 @Override
2346 public int adjustSystemUiVisibilityLw(int visibility) {
2347 // Reset any bits in mForceClearingStatusBarVisibility that
2348 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002349 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002350 // Clear any bits in the new visibility that are currently being
2351 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002352 return visibility & ~mResettingSystemUiFlags
2353 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002354 }
2355
Craig Mautner69b08182012-09-05 13:07:13 -07002356 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002357 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
2358 final int fl = attrs.flags;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002359 final int systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002360
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002361 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002362 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002363 int availRight, availBottom;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002364 if (mCanHideNavigationBar &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002365 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002366 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2367 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2368 } else {
2369 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2370 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2371 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002372 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2373 if ((fl & FLAG_FULLSCREEN) != 0) {
2374 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2375 availRight - mStableFullscreenRight,
2376 availBottom - mStableFullscreenBottom);
2377 } else {
2378 contentInset.set(mStableLeft, mStableTop,
2379 availRight - mStableRight, availBottom - mStableBottom);
2380 }
2381 } else if ((fl & FLAG_FULLSCREEN) != 0) {
2382 contentInset.setEmpty();
2383 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002384 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2385 contentInset.set(mCurLeft, mCurTop,
2386 availRight - mCurRight, availBottom - mCurBottom);
2387 } else {
2388 contentInset.set(mCurLeft, mCurTop,
2389 availRight - mCurRight, availBottom - mCurBottom);
2390 }
2391 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002392 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002393 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002394 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002395
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002396 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002397 @Override
2398 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2399 int displayRotation) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08002400 mUnrestrictedScreenLeft = mUnrestrictedScreenTop = 0;
2401 mUnrestrictedScreenWidth = displayWidth;
2402 mUnrestrictedScreenHeight = displayHeight;
2403 mRestrictedScreenLeft = mRestrictedScreenTop = 0;
2404 mRestrictedScreenWidth = displayWidth;
2405 mRestrictedScreenHeight = displayHeight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002406 mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft
2407 = mSystemLeft = mCurLeft = 0;
2408 mDockTop = mContentTop = mStableTop = mStableFullscreenTop
2409 = mSystemTop = mCurTop = 0;
2410 mDockRight = mContentRight = mStableRight = mStableFullscreenRight
2411 = mSystemRight = mCurRight = displayWidth;
2412 mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom
2413 = mSystemBottom = mCurBottom = displayHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002414 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002415 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002416
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002417 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2418 final Rect pf = mTmpParentFrame;
2419 final Rect df = mTmpDisplayFrame;
2420 final Rect vf = mTmpVisibleFrame;
2421 pf.left = df.left = vf.left = mDockLeft;
2422 pf.top = df.top = vf.top = mDockTop;
2423 pf.right = df.right = vf.right = mDockRight;
2424 pf.bottom = df.bottom = vf.bottom = mDockBottom;
2425
Craig Mautner69b08182012-09-05 13:07:13 -07002426 if (isDefaultDisplay) {
2427 // For purposes of putting out fake window up to steal focus, we will
2428 // drive nav being hidden only by whether it is requested.
2429 boolean navVisible = (mLastSystemUiFlags&View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002430
Craig Mautner69b08182012-09-05 13:07:13 -07002431 // When the navigation bar isn't visible, we put up a fake
2432 // input window to catch all touch events. This way we can
2433 // detect when the user presses anywhere to bring back the nav
2434 // bar and ensure the application doesn't see the event.
2435 if (navVisible) {
2436 if (mHideNavFakeWindow != null) {
2437 mHideNavFakeWindow.dismiss();
2438 mHideNavFakeWindow = null;
2439 }
2440 } else if (mHideNavFakeWindow == null) {
2441 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2442 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
2443 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER,
2444 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002445 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002446
Craig Mautner69b08182012-09-05 13:07:13 -07002447 // For purposes of positioning and showing the nav bar, if we have
2448 // decided that it can't be hidden (because of the screen aspect ratio),
2449 // then take that into account.
2450 navVisible |= !mCanHideNavigationBar;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002451
Craig Mautner69b08182012-09-05 13:07:13 -07002452 if (mNavigationBar != null) {
2453 // Force the navigation bar to its appropriate place and
2454 // size. We need to do this directly, instead of relying on
2455 // it to bubble up from the nav bar, because this needs to
2456 // change atomically with screen rotations.
2457 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2458 if (mNavigationBarOnBottom) {
2459 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
2460 int top = displayHeight - mNavigationBarHeightForRotation[displayRotation];
2461 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight);
2462 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
2463 if (navVisible) {
2464 mNavigationBar.showLw(true);
2465 mDockBottom = mTmpNavigationFrame.top;
2466 mRestrictedScreenHeight = mDockBottom - mDockTop;
2467 } else {
2468 // We currently want to hide the navigation UI.
2469 mNavigationBar.hideLw(true);
2470 }
2471 if (navVisible && !mNavigationBar.isAnimatingLw()) {
2472 // If the nav bar is currently requested to be visible,
2473 // and not in the process of animating on or off, then
2474 // we can tell the app that it is covered by it.
2475 mSystemBottom = mTmpNavigationFrame.top;
2476 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002477 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002478 // Landscape screen; nav bar goes to the right.
2479 int left = displayWidth - mNavigationBarWidthForRotation[displayRotation];
2480 mTmpNavigationFrame.set(left, 0, displayWidth, displayHeight);
2481 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
2482 if (navVisible) {
2483 mNavigationBar.showLw(true);
2484 mDockRight = mTmpNavigationFrame.left;
2485 mRestrictedScreenWidth = mDockRight - mDockLeft;
2486 } else {
2487 // We currently want to hide the navigation UI.
2488 mNavigationBar.hideLw(true);
2489 }
2490 if (navVisible && !mNavigationBar.isAnimatingLw()) {
2491 // If the nav bar is currently requested to be visible,
2492 // and not in the process of animating on or off, then
2493 // we can tell the app that it is covered by it.
2494 mSystemRight = mTmpNavigationFrame.left;
2495 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002496 }
Craig Mautner69b08182012-09-05 13:07:13 -07002497 // Make sure the content and current rectangles are updated to
2498 // account for the restrictions from the navigation bar.
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002499 mContentTop = mCurTop = mDockTop;
2500 mContentBottom = mCurBottom = mDockBottom;
2501 mContentLeft = mCurLeft = mDockLeft;
2502 mContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002503 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2504 // And compute the final frame.
2505 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
2506 mTmpNavigationFrame, mTmpNavigationFrame);
2507 if (DEBUG_LAYOUT) Log.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002508 }
Craig Mautner69b08182012-09-05 13:07:13 -07002509 if (DEBUG_LAYOUT) Log.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
2510 mDockLeft, mDockTop, mDockRight, mDockBottom));
2511
2512 // decide where the status bar goes ahead of time
2513 if (mStatusBar != null) {
2514 // apply any navigation bar insets
2515 pf.left = df.left = mUnrestrictedScreenLeft;
2516 pf.top = df.top = mUnrestrictedScreenTop;
2517 pf.right = df.right = mUnrestrictedScreenWidth - mUnrestrictedScreenLeft;
2518 pf.bottom = df.bottom = mUnrestrictedScreenHeight - mUnrestrictedScreenTop;
2519 vf.left = mStableLeft;
2520 vf.top = mStableTop;
2521 vf.right = mStableRight;
2522 vf.bottom = mStableBottom;
2523
2524 mStatusBarLayer = mStatusBar.getSurfaceLayer();
2525
2526 // Let the status bar determine its size.
2527 mStatusBar.computeFrameLw(pf, df, vf, vf);
2528
2529 // For layout, the status bar is always at the top with our fixed height.
2530 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
2531
2532 // If the status bar is hidden, we don't want to cause
2533 // windows behind it to scroll.
2534 if (mStatusBar.isVisibleLw()) {
2535 // Status bar may go away, so the screen area it occupies
2536 // is available to apps but just covering them when the
2537 // status bar is visible.
2538 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
2539
2540 mContentTop = mCurTop = mDockTop;
2541 mContentBottom = mCurBottom = mDockBottom;
2542 mContentLeft = mCurLeft = mDockLeft;
2543 mContentRight = mCurRight = mDockRight;
2544
2545 if (DEBUG_LAYOUT) Log.v(TAG, "Status bar: " +
2546 String.format(
2547 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
2548 mDockLeft, mDockTop, mDockRight, mDockBottom,
2549 mContentLeft, mContentTop, mContentRight, mContentBottom,
2550 mCurLeft, mCurTop, mCurRight, mCurBottom));
2551 }
2552 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()) {
2553 // If the status bar is currently requested to be visible,
2554 // and not in the process of animating on or off, then
2555 // we can tell the app that it is covered by it.
2556 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
2557 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002558 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002559 }
2560 }
2561
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002562 /** {@inheritDoc} */
2563 public int getSystemDecorRectLw(Rect systemRect) {
2564 systemRect.left = mSystemLeft;
2565 systemRect.top = mSystemTop;
2566 systemRect.right = mSystemRight;
2567 systemRect.bottom = mSystemBottom;
2568 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
2569 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
2570 return 0;
2571 }
2572
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002573 void setAttachedWindowFrames(WindowState win, int fl, int adjust,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002574 WindowState attached, boolean insetDecors, Rect pf, Rect df, Rect cf, Rect vf) {
2575 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
2576 // Here's a special case: if this attached window is a panel that is
2577 // above the dock window, and the window it is attached to is below
2578 // the dock window, then the frames we computed for the window it is
2579 // attached to can not be used because the dock is effectively part
2580 // of the underlying window and the attached window is floating on top
2581 // of the whole thing. So, we ignore the attached window and explicitly
2582 // compute the frames that would be appropriate without the dock.
2583 df.left = cf.left = vf.left = mDockLeft;
2584 df.top = cf.top = vf.top = mDockTop;
2585 df.right = cf.right = vf.right = mDockRight;
2586 df.bottom = cf.bottom = vf.bottom = mDockBottom;
2587 } else {
2588 // The effective display frame of the attached window depends on
2589 // whether it is taking care of insetting its content. If not,
2590 // we need to use the parent's content frame so that the entire
2591 // window is positioned within that content. Otherwise we can use
2592 // the display frame and let the attached window take care of
2593 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002594 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002595 cf.set(attached.getDisplayFrameLw());
2596 } else {
2597 // If the window is resizing, then we want to base the content
2598 // frame on our attached content frame to resize... however,
2599 // things can be tricky if the attached window is NOT in resize
2600 // mode, in which case its content frame will be larger.
2601 // Ungh. So to deal with that, make sure the content frame
2602 // we end up using is not covering the IM dock.
2603 cf.set(attached.getContentFrameLw());
2604 if (attached.getSurfaceLayer() < mDockLayer) {
2605 if (cf.left < mContentLeft) cf.left = mContentLeft;
2606 if (cf.top < mContentTop) cf.top = mContentTop;
2607 if (cf.right > mContentRight) cf.right = mContentRight;
2608 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
2609 }
2610 }
2611 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
2612 vf.set(attached.getVisibleFrameLw());
2613 }
2614 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
2615 // window should be positioned relative to its parent or the entire
2616 // screen.
2617 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
2618 ? attached.getFrameLw() : df);
2619 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002620
2621 private void applyStableConstraints(int sysui, int fl, Rect r) {
2622 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2623 // If app is requesting a stable layout, don't let the
2624 // content insets go below the stable values.
2625 if ((fl & FLAG_FULLSCREEN) != 0) {
2626 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
2627 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
2628 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
2629 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
2630 } else {
2631 if (r.left < mStableLeft) r.left = mStableLeft;
2632 if (r.top < mStableTop) r.top = mStableTop;
2633 if (r.right > mStableRight) r.right = mStableRight;
2634 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
2635 }
2636 }
2637 }
2638
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002639 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002640 @Override
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07002641 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
2642 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002643 // we've already done the status bar
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002644 if (win == mStatusBar || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002645 return;
2646 }
Craig Mautner69b08182012-09-05 13:07:13 -07002647 final boolean isDefaultDisplay = win.isDefaultDisplay();
2648 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09002649 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
2650 if (needsToOffsetInputMethodTarget) {
2651 if (DEBUG_LAYOUT) {
2652 Slog.i(TAG, "Offset ime target window by the last ime window state");
2653 }
2654 offsetInputMethodWindowLw(mLastInputMethodWindow);
2655 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002656
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002657 final int fl = attrs.flags;
2658 final int sim = attrs.softInputMode;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002659 final int sysUiFl = win.getSystemUiVisibility();
2660
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002661 final Rect pf = mTmpParentFrame;
2662 final Rect df = mTmpDisplayFrame;
2663 final Rect cf = mTmpContentFrame;
2664 final Rect vf = mTmpVisibleFrame;
Craig Mautner69b08182012-09-05 13:07:13 -07002665
2666 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04002667 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002668
Craig Mautnerf683b562012-10-02 11:10:57 -07002669 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
2670
Craig Mautner69b08182012-09-05 13:07:13 -07002671 if (!isDefaultDisplay) {
2672 if (attached != null) {
2673 // If this window is attached to another, our display
2674 // frame is the same as the one we are attached to.
Craig Mautnerf683b562012-10-02 11:10:57 -07002675 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002676 } else {
2677 // Give the window full screen.
2678 pf.left = df.left = cf.left = mUnrestrictedScreenLeft;
2679 pf.top = df.top = cf.top = mUnrestrictedScreenTop;
2680 pf.right = df.right = cf.right
2681 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2682 pf.bottom = df.bottom = cf.bottom
2683 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2684 }
2685 } else if (attrs.type == TYPE_INPUT_METHOD) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002686 pf.left = df.left = cf.left = vf.left = mDockLeft;
2687 pf.top = df.top = cf.top = vf.top = mDockTop;
2688 pf.right = df.right = cf.right = vf.right = mDockRight;
2689 pf.bottom = df.bottom = cf.bottom = vf.bottom = mDockBottom;
2690 // IM dock windows always go to the bottom of the screen.
2691 attrs.gravity = Gravity.BOTTOM;
2692 mDockLayer = win.getSurfaceLayer();
2693 } else {
Dianne Hackborn82de1ae2010-10-28 11:28:39 -07002694 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_FULLSCREEN | FLAG_LAYOUT_INSET_DECOR))
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002695 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)
2696 && (sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002697 if (DEBUG_LAYOUT)
2698 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle()
2699 + "): IN_SCREEN, INSET_DECOR, !FULLSCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002700 // This is the case for a normal activity window: we want it
2701 // to cover all of the screen space, and it can take care of
2702 // moving its contents to account for screen decorations that
2703 // intrude into that space.
2704 if (attached != null) {
2705 // If this window is attached to another, our display
2706 // frame is the same as the one we are attached to.
Craig Mautnerf683b562012-10-02 11:10:57 -07002707 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002708 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002709 if (attrs.type == TYPE_STATUS_BAR_PANEL
2710 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08002711 // Status bar panels are the only windows who can go on top of
2712 // the status bar. They are protected by the STATUS_BAR_SERVICE
2713 // permission, so they have the same privileges as the status
2714 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002715 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002716 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002717
2718 pf.left = df.left = hasNavBar ? mDockLeft : mUnrestrictedScreenLeft;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002719 pf.top = df.top = mUnrestrictedScreenTop;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002720 pf.right = df.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002721 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002722 : mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2723 pf.bottom = df.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002724 ? mRestrictedScreenTop+mRestrictedScreenHeight
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002725 : mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
2726
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002727 if (DEBUG_LAYOUT) {
2728 Log.v(TAG, String.format(
2729 "Laying out status bar window: (%d,%d - %d,%d)",
2730 pf.left, pf.top, pf.right, pf.bottom));
2731 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002732 } else if (mCanHideNavigationBar
2733 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002734 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
2735 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
2736 // Asking for layout as if the nav bar is hidden, lets the
2737 // application extend into the unrestricted screen area. We
2738 // only do this for application windows to ensure no window that
2739 // can be above the nav bar can do this.
2740 pf.left = df.left = mUnrestrictedScreenLeft;
2741 pf.top = df.top = mUnrestrictedScreenTop;
2742 pf.right = df.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2743 pf.bottom = df.bottom = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002744 } else {
2745 pf.left = df.left = mRestrictedScreenLeft;
2746 pf.top = df.top = mRestrictedScreenTop;
2747 pf.right = df.right = mRestrictedScreenLeft+mRestrictedScreenWidth;
2748 pf.bottom = df.bottom = mRestrictedScreenTop+mRestrictedScreenHeight;
2749 }
Craig Mautner69b08182012-09-05 13:07:13 -07002750
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002751 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002752 cf.left = mDockLeft;
2753 cf.top = mDockTop;
2754 cf.right = mDockRight;
2755 cf.bottom = mDockBottom;
2756 } else {
2757 cf.left = mContentLeft;
2758 cf.top = mContentTop;
2759 cf.right = mContentRight;
2760 cf.bottom = mContentBottom;
2761 }
Craig Mautner69b08182012-09-05 13:07:13 -07002762
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002763 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002764 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
2765 vf.left = mCurLeft;
2766 vf.top = mCurTop;
2767 vf.right = mCurRight;
2768 vf.bottom = mCurBottom;
2769 } else {
2770 vf.set(cf);
2771 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002772 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002773 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
2774 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
2775 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002776 if (DEBUG_LAYOUT)
2777 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002778 // A window that has requested to fill the entire screen just
2779 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002780 if (attrs.type == TYPE_STATUS_BAR_PANEL
2781 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
2782 pf.left = df.left = cf.left = hasNavBar ? mDockLeft : mUnrestrictedScreenLeft;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002783 pf.top = df.top = cf.top = mUnrestrictedScreenTop;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002784 pf.right = df.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002785 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002786 : mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2787 pf.bottom = df.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002788 ? mRestrictedScreenTop+mRestrictedScreenHeight
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002789 : mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Daniel Sandler36412a72011-08-04 09:35:13 -04002790 if (DEBUG_LAYOUT) {
2791 Log.v(TAG, String.format(
2792 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
2793 pf.left, pf.top, pf.right, pf.bottom));
2794 }
Jim Millere898ac52012-04-06 17:10:57 -07002795 } else if (attrs.type == TYPE_NAVIGATION_BAR
2796 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002797 // The navigation bar has Real Ultimate Power.
2798 pf.left = df.left = mUnrestrictedScreenLeft;
2799 pf.top = df.top = mUnrestrictedScreenTop;
2800 pf.right = df.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2801 pf.bottom = df.bottom = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
2802 if (DEBUG_LAYOUT) {
2803 Log.v(TAG, String.format(
2804 "Laying out navigation bar window: (%d,%d - %d,%d)",
2805 pf.left, pf.top, pf.right, pf.bottom));
2806 }
Dianne Hackborn01011c32012-02-21 13:54:21 -08002807 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
2808 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002809 && ((fl & FLAG_FULLSCREEN) != 0)) {
2810 // Fullscreen secure system overlays get what they ask for.
2811 pf.left = df.left = mUnrestrictedScreenLeft;
2812 pf.top = df.top = mUnrestrictedScreenTop;
2813 pf.right = df.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2814 pf.bottom = df.bottom = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002815 } else if (attrs.type == TYPE_BOOT_PROGRESS
2816 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08002817 // Boot progress screen always covers entire display.
2818 pf.left = df.left = cf.left = mUnrestrictedScreenLeft;
2819 pf.top = df.top = cf.top = mUnrestrictedScreenTop;
2820 pf.right = df.right = cf.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2821 pf.bottom = df.bottom = cf.bottom
2822 = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002823 } else if (mCanHideNavigationBar
2824 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002825 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
2826 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
2827 // Asking for layout as if the nav bar is hidden, lets the
2828 // application extend into the unrestricted screen area. We
2829 // only do this for application windows to ensure no window that
2830 // can be above the nav bar can do this.
2831 // XXX This assumes that an app asking for this will also
2832 // ask for layout in only content. We can't currently figure out
2833 // what the screen would be if only laying out to hide the nav bar.
2834 pf.left = df.left = cf.left = mUnrestrictedScreenLeft;
2835 pf.top = df.top = cf.top = mUnrestrictedScreenTop;
2836 pf.right = df.right = cf.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2837 pf.bottom = df.bottom = cf.bottom
2838 = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002839 } else {
2840 pf.left = df.left = cf.left = mRestrictedScreenLeft;
2841 pf.top = df.top = cf.top = mRestrictedScreenTop;
2842 pf.right = df.right = cf.right = mRestrictedScreenLeft+mRestrictedScreenWidth;
2843 pf.bottom = df.bottom = cf.bottom
2844 = mRestrictedScreenTop+mRestrictedScreenHeight;
2845 }
Craig Mautner69b08182012-09-05 13:07:13 -07002846
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002847 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07002848
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002849 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
2850 vf.left = mCurLeft;
2851 vf.top = mCurTop;
2852 vf.right = mCurRight;
2853 vf.bottom = mCurBottom;
2854 } else {
2855 vf.set(cf);
2856 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002857 } else if (attached != null) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002858 if (DEBUG_LAYOUT)
2859 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002860 // A child window should be placed inside of the same visible
2861 // frame that its parent had.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002862 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002863 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002864 if (DEBUG_LAYOUT)
2865 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002866 // Otherwise, a normal window must be placed inside the content
2867 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07002868 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
2869 // Status bar panels are the only windows who can go on top of
2870 // the status bar. They are protected by the STATUS_BAR_SERVICE
2871 // permission, so they have the same privileges as the status
2872 // bar itself.
Dianne Hackborn7d049322011-06-14 15:00:32 -07002873 pf.left = df.left = cf.left = mRestrictedScreenLeft;
2874 pf.top = df.top = cf.top = mRestrictedScreenTop;
2875 pf.right = df.right = cf.right = mRestrictedScreenLeft+mRestrictedScreenWidth;
2876 pf.bottom = df.bottom = cf.bottom
2877 = mRestrictedScreenTop+mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002878 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07002879 pf.left = mContentLeft;
2880 pf.top = mContentTop;
2881 pf.right = mContentRight;
2882 pf.bottom = mContentBottom;
2883 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
2884 df.left = cf.left = mDockLeft;
2885 df.top = cf.top = mDockTop;
2886 df.right = cf.right = mDockRight;
2887 df.bottom = cf.bottom = mDockBottom;
2888 } else {
2889 df.left = cf.left = mContentLeft;
2890 df.top = cf.top = mContentTop;
2891 df.right = cf.right = mContentRight;
2892 df.bottom = cf.bottom = mContentBottom;
2893 }
2894 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
2895 vf.left = mCurLeft;
2896 vf.top = mCurTop;
2897 vf.right = mCurRight;
2898 vf.bottom = mCurBottom;
2899 } else {
2900 vf.set(cf);
2901 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002902 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002903 }
2904 }
Craig Mautner69b08182012-09-05 13:07:13 -07002905
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002906 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0) {
2907 df.left = df.top = cf.left = cf.top = vf.left = vf.top = -10000;
2908 df.right = df.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
2909 }
2910
The Android Open Source Project11267662009-03-18 17:39:47 -07002911 if (DEBUG_LAYOUT) Log.v(TAG, "Compute frame " + attrs.getTitle()
2912 + ": sim=#" + Integer.toHexString(sim)
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002913 + " attach=" + attached + " type=" + attrs.type
2914 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07002915 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
2916 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07002917
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002918 win.computeFrameLw(pf, df, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002919
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002920 // Dock windows carve out the bottom of the screen, so normal windows
2921 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07002922 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
2923 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09002924 setLastInputMethodWindowLw(null, null);
2925 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002926 }
2927 }
2928
satok1bc0a492012-04-25 22:47:12 +09002929 private void offsetInputMethodWindowLw(WindowState win) {
2930 int top = win.getContentFrameLw().top;
2931 top += win.getGivenContentInsetsLw().top;
2932 if (mContentBottom > top) {
2933 mContentBottom = top;
2934 }
2935 top = win.getVisibleFrameLw().top;
2936 top += win.getGivenVisibleInsetsLw().top;
2937 if (mCurBottom > top) {
2938 mCurBottom = top;
2939 }
2940 if (DEBUG_LAYOUT) Log.v(TAG, "Input method: mDockBottom="
2941 + mDockBottom + " mContentBottom="
2942 + mContentBottom + " mCurBottom=" + mCurBottom);
2943 }
2944
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002945 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08002946 @Override
2947 public void finishLayoutLw() {
2948 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002949 }
2950
2951 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07002952 @Override
Craig Mautner39834192012-09-02 07:47:24 -07002953 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002954 mTopFullscreenOpaqueWindowState = null;
2955 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002956 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08002957 mForcingShowNavBar = false;
2958 mForcingShowNavBarLayer = -1;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002959
2960 mHideLockScreen = false;
2961 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07002962 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002963 mShowingLockscreen = false;
2964 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002965 }
2966
2967 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07002968 @Override
Craig Mautner39834192012-09-02 07:47:24 -07002969 public void applyPostLayoutPolicyLw(WindowState win,
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002970 WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07002971 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
2972 + win.isVisibleOrBehindKeyguardLw());
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08002973 if (mTopFullscreenOpaqueWindowState == null && (win.getAttrs().privateFlags
2974 &WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_SHOW_NAV_BAR) != 0) {
2975 if (mForcingShowNavBarLayer < 0) {
2976 mForcingShowNavBar = true;
2977 mForcingShowNavBarLayer = win.getSurfaceLayer();
2978 }
2979 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002980 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08002981 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002982 if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002983 if (attrs.type == TYPE_KEYGUARD) {
2984 mForceStatusBarFromKeyguard = true;
2985 } else {
2986 mForceStatusBar = true;
2987 }
2988 }
2989 if (attrs.type == TYPE_KEYGUARD) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002990 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07002991 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002992 boolean applyWindow = attrs.type >= FIRST_APPLICATION_WINDOW
2993 && attrs.type <= LAST_APPLICATION_WINDOW;
2994 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07002995 // If the lockscreen was showing when the dream started then wait
2996 // for the dream to draw before hiding the lockscreen.
2997 if (!mDreamingLockscreen
2998 || (win.isVisibleLw() && win.hasDrawnLw())) {
2999 mShowingDream = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003000 applyWindow = true;
3001 }
3002 }
3003 if (applyWindow
Dianne Hackborn6493e642010-10-01 13:06:30 -07003004 && attrs.x == 0 && attrs.y == 0
3005 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3006 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003007 if (DEBUG_LAYOUT) Log.v(TAG, "Fullscreen window: " + win);
3008 mTopFullscreenOpaqueWindowState = win;
3009 if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003010 if (DEBUG_LAYOUT) Log.v(TAG, "Setting mHideLockScreen to true by win " + win);
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003011 mHideLockScreen = true;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003012 mForceStatusBarFromKeyguard = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003013 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003014 if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0
3015 && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003016 if (DEBUG_LAYOUT) Log.v(TAG, "Setting mDismissKeyguard to true by win " + win);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003017 mDismissKeyguard = mWinDismissingKeyguard == win ?
3018 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3019 mWinDismissingKeyguard = win;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003020 mForceStatusBarFromKeyguard = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003021 }
3022 if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
3023 mAllowLockscreenWhenOn = true;
3024 }
3025 }
3026 }
3027 }
3028
3029 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003030 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003031 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003032 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003033 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003034
3035 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3036 ? mTopFullscreenOpaqueWindowState.getAttrs()
3037 : null;
3038
Jeff Brownc8018eb2012-10-29 21:33:27 -07003039 // If we are not currently showing a dream then remember the current
3040 // lockscreen state. We will use this to determine whether the dream
3041 // started while the lockscreen was showing and remember this state
3042 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003043 if (!mShowingDream) {
3044 mDreamingLockscreen = mShowingLockscreen;
3045 }
3046
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003047 if (mStatusBar != null) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003048 if (DEBUG_LAYOUT) Log.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003049 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003050 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003051 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003052 if (DEBUG_LAYOUT) Log.v(TAG, "Showing status bar: forced");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003053 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003054 } else if (mTopFullscreenOpaqueWindowState != null) {
Joe Onorato93056472010-09-10 10:30:46 -04003055 if (localLOGV) {
3056 Log.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
3057 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
3058 Log.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
3059 + " lp.flags=0x" + Integer.toHexString(lp.flags));
3060 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003061 topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
3062 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003063 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3064 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3065 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3066 // case though.
3067 if (topIsFullscreen) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003068 if (DEBUG_LAYOUT) Log.v(TAG, "** HIDING status bar");
3069 if (mStatusBar.hideLw(true)) {
3070 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Daniel Sandler9c00d5b2011-09-13 14:04:26 -04003071
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003072 mHandler.post(new Runnable() {
3073 @Override
3074 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07003075 try {
3076 IStatusBarService statusbar = getStatusBarService();
3077 if (statusbar != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -04003078 statusbar.collapsePanels();
Dianne Hackborn42e620c2012-06-24 13:20:51 -07003079 }
3080 } catch (RemoteException ex) {
3081 // re-acquire status bar service next time it is needed.
3082 mStatusBarService = null;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003083 }
3084 }});
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003085 } else if (DEBUG_LAYOUT) {
Daniel Sandler40427442010-07-16 11:44:52 -04003086 Log.v(TAG, "Preventing status bar from hiding by policy");
3087 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003088 } else {
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003089 if (DEBUG_LAYOUT) Log.v(TAG, "** SHOWING status bar: top is not fullscreen");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003090 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003091 }
3092 }
3093 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003094
Joe Onorato644f9c32011-01-25 12:06:23 -08003095 mTopIsFullscreen = topIsFullscreen;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003096
Craig Mautner39834192012-09-02 07:47:24 -07003097 // Hide the key guard if a visible window explicitly specifies that it wants to be
3098 // displayed when the screen is locked.
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003099 if (mKeyguard != null) {
Craig Mautner39834192012-09-02 07:47:24 -07003100 if (localLOGV) Log.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3101 + mHideLockScreen);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003102 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardMediator.isSecure()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003103 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003104 changes |= FINISH_LAYOUT_REDO_LAYOUT
3105 | FINISH_LAYOUT_REDO_CONFIG
3106 | FINISH_LAYOUT_REDO_WALLPAPER;
3107 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003108 if (mKeyguardMediator.isShowing()) {
Dianne Hackbornb446e972009-09-20 15:23:25 -07003109 mHandler.post(new Runnable() {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003110 @Override
Dianne Hackbornb446e972009-09-20 15:23:25 -07003111 public void run() {
Dianne Hackborn05726582009-09-22 17:28:24 -07003112 mKeyguardMediator.keyguardDone(false, false);
Dianne Hackbornb446e972009-09-20 15:23:25 -07003113 }
3114 });
3115 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003116 } else if (mHideLockScreen) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003117 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003118 changes |= FINISH_LAYOUT_REDO_LAYOUT
3119 | FINISH_LAYOUT_REDO_CONFIG
3120 | FINISH_LAYOUT_REDO_WALLPAPER;
3121 }
Mike Lockwoodf3bfed52010-01-21 16:38:44 -05003122 mKeyguardMediator.setHidden(true);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003123 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3124 // This is the case of keyguard isSecure() and not mHideLockScreen.
3125 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3126 // Only launch the next keyguard unlock window once per window.
3127 if (mKeyguard.showLw(true)) {
3128 changes |= FINISH_LAYOUT_REDO_LAYOUT
3129 | FINISH_LAYOUT_REDO_CONFIG
3130 | FINISH_LAYOUT_REDO_WALLPAPER;
3131 }
3132 mKeyguardMediator.setHidden(false);
3133 mHandler.post(new Runnable() {
3134 @Override
3135 public void run() {
3136 mKeyguardMediator.dismiss();
3137 }
3138 });
3139 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003140 } else {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003141 mWinDismissingKeyguard = null;
Dianne Hackborn08743722009-12-21 12:16:51 -08003142 if (mKeyguard.showLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003143 changes |= FINISH_LAYOUT_REDO_LAYOUT
3144 | FINISH_LAYOUT_REDO_CONFIG
3145 | FINISH_LAYOUT_REDO_WALLPAPER;
3146 }
Mike Lockwoodf3bfed52010-01-21 16:38:44 -05003147 mKeyguardMediator.setHidden(false);
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003148 }
3149 }
Joe Onorato664644d2011-01-23 17:53:23 -08003150
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003151 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003152 // If the navigation bar has been hidden or shown, we need to do another
3153 // layout pass to update that window.
3154 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3155 }
Joe Onorato664644d2011-01-23 17:53:23 -08003156
Mike Lockwood28569302010-01-28 11:54:40 -05003157 // update since mAllowLockscreenWhenOn might have changed
3158 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003159 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003160 }
3161
Dianne Hackborn08743722009-12-21 12:16:51 -08003162 public boolean allowAppAnimationsLw() {
Craig Mautnerf03e4c52012-06-14 14:11:27 -07003163 if (mKeyguard != null && mKeyguard.isVisibleLw() && !mKeyguard.isAnimatingLw()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003164 // If keyguard is currently visible, no reason to animate
3165 // behind it.
3166 return false;
3167 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003168 return true;
3169 }
3170
Dianne Hackborndf89e652011-10-06 22:35:11 -07003171 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003172 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003173 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003174 // If the navigation bar has been hidden or shown, we need to do another
3175 // layout pass to update that window.
3176 return FINISH_LAYOUT_REDO_LAYOUT;
3177 }
3178 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003179 }
3180
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003181 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07003182 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003183 // do nothing if headless
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003184 if (mHeadless) return;
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003185
Jeff Brown46b9ac02010-04-22 18:58:52 -07003186 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003187 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3188 if (newLidState == mLidState) {
3189 return;
3190 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003191
Jeff Brownc458ce92012-04-30 14:58:40 -07003192 mLidState = newLidState;
3193 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003194 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003195
3196 if (lidOpen) {
3197 if (keyguardIsShowingTq()) {
Jeff Brown1c2e4942012-11-06 16:32:01 -08003198 mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(KeyEvent.KEYCODE_POWER);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003199 } else {
Jeff Brown96307042012-07-27 15:51:34 -07003200 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brown46b9ac02010-04-22 18:58:52 -07003201 }
Jeff Brownc458ce92012-04-30 14:58:40 -07003202 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003203 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003204 }
3205 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003206
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003207 void setHdmiPlugged(boolean plugged) {
3208 if (mHdmiPlugged != plugged) {
3209 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003210 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003211 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003212 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003213 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003214 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003215 }
3216 }
3217
Joe Onoratoea495d42011-04-06 11:41:11 -07003218 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003219 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003220 // watch for HDMI plug messages if the hdmi switch exists
3221 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3222 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3223
Joe Onoratoea495d42011-04-06 11:41:11 -07003224 final String filename = "/sys/class/switch/hdmi/state";
3225 FileReader reader = null;
3226 try {
3227 reader = new FileReader(filename);
3228 char[] buf = new char[15];
3229 int n = reader.read(buf);
3230 if (n > 1) {
3231 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3232 }
3233 } catch (IOException ex) {
3234 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3235 } catch (NumberFormatException ex) {
3236 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3237 } finally {
3238 if (reader != null) {
3239 try {
3240 reader.close();
3241 } catch (IOException ex) {
3242 }
Joe Onoratodc100302011-01-11 17:07:41 -08003243 }
3244 }
3245 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07003246 // This dance forces the code in setHdmiPlugged to run.
3247 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
3248 mHdmiPlugged = !plugged;
3249 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08003250 }
3251
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003252 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003253 * @return Whether music is being played right now.
3254 */
3255 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07003256 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
3257 if (am == null) {
3258 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003259 return false;
3260 }
Eric Laurent413cb9d2009-07-17 11:52:43 -07003261 return am.isMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003262 }
3263
3264 /**
3265 * Tell the audio service to adjust the volume appropriate to the event.
3266 * @param keycode
3267 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04003268 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07003269 IAudioService audioService = getAudioService();
3270 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003271 return;
3272 }
3273 try {
3274 // since audio is playing, we shouldn't have to hold a wake lock
3275 // during the call, but we do it as a precaution for the rare possibility
3276 // that the music stops right before we call this
Jeff Brownb0418da2010-11-01 15:24:01 -07003277 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003278 mBroadcastWakeLock.acquire();
Jeff Brown4d396052010-10-29 21:50:21 -07003279 audioService.adjustStreamVolume(stream,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003280 keycode == KeyEvent.KEYCODE_VOLUME_UP
3281 ? AudioManager.ADJUST_RAISE
3282 : AudioManager.ADJUST_LOWER,
3283 0);
3284 } catch (RemoteException e) {
3285 Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e);
3286 } finally {
3287 mBroadcastWakeLock.release();
3288 }
3289 }
Jeff Brown4d396052010-10-29 21:50:21 -07003290
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07003291 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003292 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003293
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003294 final Runnable mScreenshotTimeout = new Runnable() {
3295 @Override public void run() {
3296 synchronized (mScreenshotLock) {
3297 if (mScreenshotConnection != null) {
3298 mContext.unbindService(mScreenshotConnection);
3299 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003300 }
Winson Chung9112ec32011-06-27 13:15:32 -07003301 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003302 }
3303 };
3304
3305 // Assume this is called from the Handler thread.
3306 private void takeScreenshot() {
3307 synchronized (mScreenshotLock) {
3308 if (mScreenshotConnection != null) {
3309 return;
3310 }
3311 ComponentName cn = new ComponentName("com.android.systemui",
3312 "com.android.systemui.screenshot.TakeScreenshotService");
3313 Intent intent = new Intent();
3314 intent.setComponent(cn);
3315 ServiceConnection conn = new ServiceConnection() {
3316 @Override
3317 public void onServiceConnected(ComponentName name, IBinder service) {
3318 synchronized (mScreenshotLock) {
3319 if (mScreenshotConnection != this) {
3320 return;
3321 }
3322 Messenger messenger = new Messenger(service);
3323 Message msg = Message.obtain(null, 1);
3324 final ServiceConnection myConn = this;
3325 Handler h = new Handler(mHandler.getLooper()) {
3326 @Override
3327 public void handleMessage(Message msg) {
3328 synchronized (mScreenshotLock) {
3329 if (mScreenshotConnection == myConn) {
3330 mContext.unbindService(mScreenshotConnection);
3331 mScreenshotConnection = null;
3332 mHandler.removeCallbacks(mScreenshotTimeout);
3333 }
3334 }
3335 }
3336 };
3337 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07003338 msg.arg1 = msg.arg2 = 0;
3339 if (mStatusBar != null && mStatusBar.isVisibleLw())
3340 msg.arg1 = 1;
3341 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
3342 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003343 try {
3344 messenger.send(msg);
3345 } catch (RemoteException e) {
3346 }
3347 }
3348 }
3349 @Override
3350 public void onServiceDisconnected(ComponentName name) {}
3351 };
Jeff Sharkey35744c12012-08-28 16:48:05 -07003352 if (mContext.bindService(
3353 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.USER_CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003354 mScreenshotConnection = conn;
3355 mHandler.postDelayed(mScreenshotTimeout, 10000);
3356 }
3357 }
Winson Chung9112ec32011-06-27 13:15:32 -07003358 }
3359
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003360 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003361 @Override
Jeff Brown1f245102010-11-18 20:53:46 -08003362 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
Jeff Brown96307042012-07-27 15:51:34 -07003363 if (!mSystemBooted) {
3364 // If we have not yet booted, don't let key events do anything.
3365 return 0;
3366 }
3367
Jeff Brown1f245102010-11-18 20:53:46 -08003368 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3369 final boolean canceled = event.isCanceled();
3370 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07003371
Jeff Brown3122e442010-10-11 23:32:49 -07003372 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07003373
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05003374 // If screen is off then we treat the case where the keyguard is open but hidden
3375 // the same as if it were open and in front.
3376 // This will prevent any keys other than the power button from waking the screen
3377 // when the keyguard is hidden by another activity.
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003378 final boolean keyguardActive = (mKeyguardMediator == null ? false :
3379 (isScreenOn ?
3380 mKeyguardMediator.isShowingAndNotHidden() :
3381 mKeyguardMediator.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003382
Jeff Brown96307042012-07-27 15:51:34 -07003383 if (keyCode == KeyEvent.KEYCODE_POWER) {
3384 policyFlags |= WindowManagerPolicy.FLAG_WAKE;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003385 }
Jeff Brown96307042012-07-27 15:51:34 -07003386 final boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE
3387 | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003388
Jeff Brown40013652012-05-16 21:22:36 -07003389 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003390 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown96307042012-07-27 15:51:34 -07003391 + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive
3392 + " policyFlags=" + Integer.toHexString(policyFlags)
3393 + " isWakeKey=" + isWakeKey);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003394 }
3395
Jeff Brown98392ef2011-09-12 18:24:59 -07003396 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
3397 && event.getRepeatCount() == 0) {
Jeff Brown4d396052010-10-29 21:50:21 -07003398 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
3399 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003400
Jeff Brown4d396052010-10-29 21:50:21 -07003401 // Basic policy based on screen state and keyguard.
3402 // FIXME: This policy isn't quite correct. We shouldn't care whether the screen
3403 // is on or off, really. We should care about whether the device is in an
3404 // interactive state or is in suspend pretending to be "off".
3405 // The primary screen might be turned off due to proximity sensor or
3406 // because we are presenting media on an auxiliary screen or remotely controlling
3407 // the device some other way (which is why we have an exemption here for injected
3408 // events).
3409 int result;
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003410 if ((isScreenOn && !mHeadless) || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003411 // When the screen is on or if the key is injected pass the key to the application.
3412 result = ACTION_PASS_TO_USER;
3413 } else {
3414 // When the screen is off and the key is not injected, determine whether
3415 // to wake the device but don't pass the key to the application.
3416 result = 0;
Jeff Brown1c2e4942012-11-06 16:32:01 -08003417 if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003418 if (keyguardActive) {
Jeff Brown1c2e4942012-11-06 16:32:01 -08003419 // If the keyguard is showing, let it wake the device when ready.
3420 mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode);
Jeff Brown4d396052010-10-29 21:50:21 -07003421 } else {
3422 // Otherwise, wake the device ourselves.
Jeff Brown96307042012-07-27 15:51:34 -07003423 result |= ACTION_WAKE_UP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003424 }
3425 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003426 }
3427
Jeff Brown4d396052010-10-29 21:50:21 -07003428 // Handle special keys.
3429 switch (keyCode) {
3430 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07003431 case KeyEvent.KEYCODE_VOLUME_UP:
3432 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003433 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
3434 if (down) {
3435 if (isScreenOn && !mVolumeDownKeyTriggered
3436 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3437 mVolumeDownKeyTriggered = true;
3438 mVolumeDownKeyTime = event.getDownTime();
3439 mVolumeDownKeyConsumedByScreenshotChord = false;
3440 cancelPendingPowerKeyAction();
3441 interceptScreenshotChord();
3442 }
3443 } else {
3444 mVolumeDownKeyTriggered = false;
3445 cancelPendingScreenshotChordAction();
3446 }
3447 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
3448 if (down) {
3449 if (isScreenOn && !mVolumeUpKeyTriggered
3450 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3451 mVolumeUpKeyTriggered = true;
3452 cancelPendingPowerKeyAction();
3453 cancelPendingScreenshotChordAction();
3454 }
3455 } else {
3456 mVolumeUpKeyTriggered = false;
3457 cancelPendingScreenshotChordAction();
3458 }
3459 }
Jeff Brown4d396052010-10-29 21:50:21 -07003460 if (down) {
3461 ITelephony telephonyService = getTelephonyService();
3462 if (telephonyService != null) {
3463 try {
3464 if (telephonyService.isRinging()) {
3465 // If an incoming call is ringing, either VOLUME key means
3466 // "silence ringer". We handle these keys here, rather than
3467 // in the InCallScreen, to make sure we'll respond to them
3468 // even if the InCallScreen hasn't come to the foreground yet.
3469 // Look for the DOWN event here, to agree with the "fallback"
3470 // behavior in the InCallScreen.
3471 Log.i(TAG, "interceptKeyBeforeQueueing:"
3472 + " VOLUME key-down while ringing: Silence ringer!");
3473
3474 // Silence the ringer. (It's safe to call this
3475 // even if the ringer has already been silenced.)
3476 telephonyService.silenceRinger();
3477
3478 // And *don't* pass this key thru to the current activity
3479 // (which is probably the InCallScreen.)
3480 result &= ~ACTION_PASS_TO_USER;
3481 break;
3482 }
3483 if (telephonyService.isOffhook()
3484 && (result & ACTION_PASS_TO_USER) == 0) {
3485 // If we are in call but we decided not to pass the key to
3486 // the application, handle the volume change here.
3487 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
3488 break;
3489 }
3490 } catch (RemoteException ex) {
3491 Log.w(TAG, "ITelephony threw RemoteException", ex);
3492 }
3493 }
3494
3495 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
3496 // If music is playing but we decided not to pass the key to the
3497 // application, handle the volume change here.
3498 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
3499 break;
3500 }
3501 }
3502 break;
3503 }
3504
3505 case KeyEvent.KEYCODE_ENDCALL: {
3506 result &= ~ACTION_PASS_TO_USER;
3507 if (down) {
3508 ITelephony telephonyService = getTelephonyService();
3509 boolean hungUp = false;
3510 if (telephonyService != null) {
3511 try {
3512 hungUp = telephonyService.endCall();
3513 } catch (RemoteException ex) {
3514 Log.w(TAG, "ITelephony threw RemoteException", ex);
3515 }
3516 }
3517 interceptPowerKeyDown(!isScreenOn || hungUp);
3518 } else {
3519 if (interceptPowerKeyUp(canceled)) {
3520 if ((mEndcallBehavior
3521 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
3522 if (goHome()) {
3523 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07003524 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003525 }
Jeff Brown4d396052010-10-29 21:50:21 -07003526 if ((mEndcallBehavior
3527 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown96307042012-07-27 15:51:34 -07003528 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
Jeff Brown4d396052010-10-29 21:50:21 -07003529 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003530 }
Jeff Brown4d396052010-10-29 21:50:21 -07003531 }
3532 break;
3533 }
3534
3535 case KeyEvent.KEYCODE_POWER: {
3536 result &= ~ACTION_PASS_TO_USER;
3537 if (down) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003538 if (isScreenOn && !mPowerKeyTriggered
3539 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3540 mPowerKeyTriggered = true;
3541 mPowerKeyTime = event.getDownTime();
3542 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07003543 }
Winson Chung9112ec32011-06-27 13:15:32 -07003544
Jeff Brown4d396052010-10-29 21:50:21 -07003545 ITelephony telephonyService = getTelephonyService();
3546 boolean hungUp = false;
3547 if (telephonyService != null) {
3548 try {
3549 if (telephonyService.isRinging()) {
3550 // Pressing Power while there's a ringing incoming
3551 // call should silence the ringer.
3552 telephonyService.silenceRinger();
3553 } else if ((mIncallPowerBehavior
3554 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
3555 && telephonyService.isOffhook()) {
3556 // Otherwise, if "Power button ends call" is enabled,
3557 // the Power button will hang up any current active call.
3558 hungUp = telephonyService.endCall();
3559 }
3560 } catch (RemoteException ex) {
3561 Log.w(TAG, "ITelephony threw RemoteException", ex);
3562 }
3563 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003564 interceptPowerKeyDown(!isScreenOn || hungUp
3565 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003566 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003567 mPowerKeyTriggered = false;
3568 cancelPendingScreenshotChordAction();
3569 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown96307042012-07-27 15:51:34 -07003570 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003571 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003572 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07003573 }
3574 break;
3575 }
3576
3577 case KeyEvent.KEYCODE_MEDIA_PLAY:
3578 case KeyEvent.KEYCODE_MEDIA_PAUSE:
3579 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3580 if (down) {
3581 ITelephony telephonyService = getTelephonyService();
3582 if (telephonyService != null) {
3583 try {
3584 if (!telephonyService.isIdle()) {
3585 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
3586 // to avoid music playback.
3587 break;
3588 }
3589 } catch (RemoteException ex) {
3590 Log.w(TAG, "ITelephony threw RemoteException", ex);
Jeff Brown3122e442010-10-11 23:32:49 -07003591 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003592 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003593 }
Jeff Brown4d396052010-10-29 21:50:21 -07003594 case KeyEvent.KEYCODE_HEADSETHOOK:
3595 case KeyEvent.KEYCODE_MUTE:
3596 case KeyEvent.KEYCODE_MEDIA_STOP:
3597 case KeyEvent.KEYCODE_MEDIA_NEXT:
3598 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
3599 case KeyEvent.KEYCODE_MEDIA_REWIND:
3600 case KeyEvent.KEYCODE_MEDIA_RECORD:
3601 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: {
3602 if ((result & ACTION_PASS_TO_USER) == 0) {
3603 // Only do this if we would otherwise not pass it to the user. In that
3604 // case, the PhoneWindow class will do the same thing, except it will
3605 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07003606 // Note that we need to make a copy of the key event here because the
3607 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07003608 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07003609 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
3610 new KeyEvent(event));
3611 msg.setAsynchronous(true);
3612 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07003613 }
3614 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003615 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003616
Jeff Brown4d396052010-10-29 21:50:21 -07003617 case KeyEvent.KEYCODE_CALL: {
3618 if (down) {
3619 ITelephony telephonyService = getTelephonyService();
3620 if (telephonyService != null) {
3621 try {
3622 if (telephonyService.isRinging()) {
3623 Log.i(TAG, "interceptKeyBeforeQueueing:"
3624 + " CALL key-down while ringing: Answer the call!");
3625 telephonyService.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003626
Jeff Brown4d396052010-10-29 21:50:21 -07003627 // And *don't* pass this key thru to the current activity
3628 // (which is presumably the InCallScreen.)
3629 result &= ~ACTION_PASS_TO_USER;
3630 }
3631 } catch (RemoteException ex) {
3632 Log.w(TAG, "ITelephony threw RemoteException", ex);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003633 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003634 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003635 }
Jeff Brown4d396052010-10-29 21:50:21 -07003636 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003637 }
3638 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003639 return result;
3640 }
3641
Jeff Brown1c2e4942012-11-06 16:32:01 -08003642 /**
3643 * When the screen is off we ignore some keys that might otherwise typically
3644 * be considered wake keys. We filter them out here.
3645 *
3646 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
3647 * is always considered a wake key.
3648 */
3649 private boolean isWakeKeyWhenScreenOff(int keyCode) {
3650 switch (keyCode) {
3651 // ignore volume keys unless docked
3652 case KeyEvent.KEYCODE_VOLUME_UP:
3653 case KeyEvent.KEYCODE_VOLUME_DOWN:
3654 case KeyEvent.KEYCODE_VOLUME_MUTE:
3655 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
3656
3657 // ignore media and camera keys
3658 case KeyEvent.KEYCODE_MUTE:
3659 case KeyEvent.KEYCODE_HEADSETHOOK:
3660 case KeyEvent.KEYCODE_MEDIA_PLAY:
3661 case KeyEvent.KEYCODE_MEDIA_PAUSE:
3662 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3663 case KeyEvent.KEYCODE_MEDIA_STOP:
3664 case KeyEvent.KEYCODE_MEDIA_NEXT:
3665 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
3666 case KeyEvent.KEYCODE_MEDIA_REWIND:
3667 case KeyEvent.KEYCODE_MEDIA_RECORD:
3668 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
3669 case KeyEvent.KEYCODE_CAMERA:
3670 return false;
3671 }
3672 return true;
3673 }
3674
3675
Jeff Brown56194eb2011-03-02 19:23:13 -08003676 /** {@inheritDoc} */
3677 @Override
3678 public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
3679 int result = 0;
3680
3681 final boolean isWakeMotion = (policyFlags
3682 & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
3683 if (isWakeMotion) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003684 if (mKeyguardMediator != null && mKeyguardMediator.isShowing()) {
Jeff Brown56194eb2011-03-02 19:23:13 -08003685 // If the keyguard is showing, let it decide what to do with the wake motion.
3686 mKeyguardMediator.onWakeMotionWhenKeyguardShowingTq();
3687 } else {
3688 // Otherwise, wake the device ourselves.
Jeff Brown96307042012-07-27 15:51:34 -07003689 result |= ACTION_WAKE_UP;
Jeff Brown56194eb2011-03-02 19:23:13 -08003690 }
3691 }
3692 return result;
3693 }
3694
Jeff Brown40013652012-05-16 21:22:36 -07003695 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
3696 if (DEBUG_INPUT) {
3697 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003698 }
3699
Jeff Brown40013652012-05-16 21:22:36 -07003700 if (mHavePendingMediaKeyRepeatWithWakeLock) {
3701 if (DEBUG_INPUT) {
3702 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
3703 }
3704
3705 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
3706 mHavePendingMediaKeyRepeatWithWakeLock = false;
3707 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
3708 }
3709
3710 dispatchMediaKeyWithWakeLockToAudioService(event);
3711
3712 if (event.getAction() == KeyEvent.ACTION_DOWN
3713 && event.getRepeatCount() == 0) {
3714 mHavePendingMediaKeyRepeatWithWakeLock = true;
3715
3716 Message msg = mHandler.obtainMessage(
3717 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
3718 msg.setAsynchronous(true);
3719 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
3720 } else {
3721 mBroadcastWakeLock.release();
3722 }
3723 }
3724
3725 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
3726 mHavePendingMediaKeyRepeatWithWakeLock = false;
3727
3728 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
3729 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
3730 if (DEBUG_INPUT) {
3731 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
3732 }
3733
3734 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
3735 mBroadcastWakeLock.release();
3736 }
3737
3738 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
3739 if (ActivityManagerNative.isSystemReady()) {
3740 IAudioService audioService = getAudioService();
3741 if (audioService != null) {
3742 try {
3743 audioService.dispatchMediaKeyEventUnderWakelock(event);
3744 } catch (RemoteException e) {
3745 Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
Jean-Michel Trivic6802222012-04-30 11:15:03 -07003746 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003747 }
3748 }
3749 }
3750
Mike Lockwood1753f7f2009-08-24 14:49:07 -07003751 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
3752 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07003753 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
3754 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
3755 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Dianne Hackborn80fa1662009-10-07 14:02:10 -07003756 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003757 updateRotation(true);
Mike Lockwoode9867d22009-09-20 01:59:02 -04003758 updateOrientationListenerLp();
Mike Lockwood1753f7f2009-08-24 14:49:07 -07003759 }
3760 };
3761
Jeff Brown6aaf2952012-10-05 16:01:08 -07003762 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
3763 @Override
3764 public void onReceive(Context context, Intent intent) {
3765 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
3766 if (mKeyguardMediator != null) {
3767 mKeyguardMediator.onDreamingStarted();
3768 }
3769 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
3770 if (mKeyguardMediator != null) {
3771 mKeyguardMediator.onDreamingStopped();
3772 }
3773 }
3774 }
3775 };
3776
Christopher Tate5e08af02012-09-21 17:17:22 -07003777 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
3778 @Override
3779 public void onReceive(Context context, Intent intent) {
3780 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
3781 // tickle the settings observer: this first ensures that we're
3782 // observing the relevant settings for the newly-active user,
3783 // and then updates our own bookkeeping based on the now-
3784 // current user.
3785 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05003786
3787 // force a re-application of focused window sysui visibility.
3788 // the window may never have been shown for this user
3789 // e.g. the keyguard when going through the new-user setup flow
3790 synchronized(mLock) {
3791 mLastSystemUiFlags = 0;
3792 updateSystemUiVisibilityLw();
3793 }
Christopher Tate5e08af02012-09-21 17:17:22 -07003794 }
3795 }
3796 };
3797
Jeff Brownc38c9be2012-10-04 13:16:19 -07003798 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003799 public void screenTurnedOff(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07003800 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07003801 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003802 mScreenOnEarly = false;
3803 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07003804 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003805 if (mKeyguardMediator != null) {
3806 mKeyguardMediator.onScreenTurnedOff(why);
3807 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07003808 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07003809 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05003810 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07003811 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003812 }
3813
Jeff Brownc38c9be2012-10-04 13:16:19 -07003814 @Override
Dianne Hackborn38e29a62011-09-18 14:43:08 -07003815 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07003816 EventLog.writeEvent(70000, 1);
Dianne Hackborn40011092011-09-22 13:37:48 -07003817 if (false) {
3818 RuntimeException here = new RuntimeException("here");
3819 here.fillInStackTrace();
3820 Slog.i(TAG, "Screen turning on...", here);
3821 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07003822
The Android Open Source Project0727d222009-03-11 12:11:58 -07003823 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003824 mScreenOnEarly = true;
The Android Open Source Project0727d222009-03-11 12:11:58 -07003825 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05003826 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07003827 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07003828
Jeff Brownc38c9be2012-10-04 13:16:19 -07003829 waitForKeyguard(screenOnListener);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003830 }
3831
Jeff Brownc38c9be2012-10-04 13:16:19 -07003832 private void waitForKeyguard(final ScreenOnListener screenOnListener) {
3833 if (mKeyguardMediator != null) {
3834 if (screenOnListener != null) {
3835 mKeyguardMediator.onScreenTurnedOn(new KeyguardViewManager.ShowListener() {
3836 @Override
3837 public void onShown(IBinder windowToken) {
3838 waitForKeyguardWindowDrawn(windowToken, screenOnListener);
3839 }
3840 });
3841 return;
3842 } else {
3843 mKeyguardMediator.onScreenTurnedOn(null);
3844 }
3845 } else {
3846 Slog.i(TAG, "No keyguard mediator!");
3847 }
3848 finishScreenTurningOn(screenOnListener);
3849 }
3850
3851 private void waitForKeyguardWindowDrawn(IBinder windowToken,
3852 final ScreenOnListener screenOnListener) {
3853 if (windowToken != null) {
3854 try {
3855 if (mWindowManager.waitForWindowDrawn(
3856 windowToken, new IRemoteCallback.Stub() {
3857 @Override
3858 public void sendResult(Bundle data) {
3859 Slog.i(TAG, "Lock screen displayed!");
3860 finishScreenTurningOn(screenOnListener);
3861 }
3862 })) {
3863 return;
3864 }
3865 } catch (RemoteException ex) {
3866 // Can't happen in system process.
3867 }
3868 }
3869
3870 Slog.i(TAG, "No lock screen!");
3871 finishScreenTurningOn(screenOnListener);
3872 }
3873
3874 private void finishScreenTurningOn(ScreenOnListener screenOnListener) {
3875 synchronized (mLock) {
3876 mScreenOnFully = true;
3877 }
3878
Jeff Brown4fc45272012-10-10 18:28:14 -07003879 try {
3880 mWindowManager.setEventDispatching(true);
3881 } catch (RemoteException unhandled) {
3882 }
3883
Jeff Brownc38c9be2012-10-04 13:16:19 -07003884 if (screenOnListener != null) {
3885 screenOnListener.onScreenOn();
3886 }
3887 }
3888
3889 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003890 public boolean isScreenOnEarly() {
3891 return mScreenOnEarly;
3892 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07003893
3894 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003895 public boolean isScreenOnFully() {
3896 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08003897 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07003898
Dianne Hackborn08743722009-12-21 12:16:51 -08003899 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003900 public void enableKeyguard(boolean enabled) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003901 if (mKeyguardMediator != null) {
3902 mKeyguardMediator.setKeyguardEnabled(enabled);
3903 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003904 }
3905
3906 /** {@inheritDoc} */
3907 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003908 if (mKeyguardMediator != null) {
3909 mKeyguardMediator.verifyUnlock(callback);
3910 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003911 }
3912
Mike Lockwoodf7913302009-11-28 22:27:10 -05003913 private boolean keyguardIsShowingTq() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003914 if (mKeyguardMediator == null) return false;
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -08003915 return mKeyguardMediator.isShowingAndNotHidden();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003916 }
3917
Mike Lockwood520d8bc2011-02-18 13:23:13 -05003918
3919 /** {@inheritDoc} */
3920 public boolean isKeyguardLocked() {
3921 return keyguardOn();
3922 }
3923
3924 /** {@inheritDoc} */
3925 public boolean isKeyguardSecure() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003926 if (mKeyguardMediator == null) return false;
Mike Lockwood520d8bc2011-02-18 13:23:13 -05003927 return mKeyguardMediator.isSecure();
3928 }
3929
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003930 /** {@inheritDoc} */
3931 public boolean inKeyguardRestrictedKeyInputMode() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003932 if (mKeyguardMediator == null) return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003933 return mKeyguardMediator.isInputRestricted();
3934 }
3935
Dianne Hackborn90c52de2011-09-23 12:57:44 -07003936 public void dismissKeyguardLw() {
Daniel Sandler1ce804392012-11-07 15:07:12 -05003937 if (mKeyguardMediator.isShowing()) {
3938 mHandler.post(new Runnable() {
3939 public void run() {
3940 if (mKeyguardMediator.isDismissable()) {
3941 // Can we just finish the keyguard straight away?
Dianne Hackborn90c52de2011-09-23 12:57:44 -07003942 mKeyguardMediator.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05003943 } else {
3944 // ask the keyguard to prompt the user to authenticate if necessary
3945 mKeyguardMediator.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07003946 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05003947 }
3948 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07003949 }
3950 }
3951
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003952 void sendCloseSystemWindows() {
3953 sendCloseSystemWindows(mContext, null);
3954 }
3955
3956 void sendCloseSystemWindows(String reason) {
3957 sendCloseSystemWindows(mContext, reason);
3958 }
3959
3960 static void sendCloseSystemWindows(Context context, String reason) {
3961 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07003962 try {
3963 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
3964 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003965 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003966 }
3967 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07003968
Jeff Brown01a98dd2011-09-20 15:08:29 -07003969 @Override
3970 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05003971 if (false) {
3972 Slog.v(TAG, "rotationForOrientationLw(orient="
3973 + orientation + ", last=" + lastRotation
3974 + "); user=" + mUserRotation + " "
3975 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
3976 ? "USER_ROTATION_LOCKED" : "")
3977 );
3978 }
3979
The Android Open Source Project0727d222009-03-11 12:11:58 -07003980 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07003981 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
3982 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07003983 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07003984 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003985
Jeff Browndec6cf42011-11-15 14:08:20 -08003986 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07003987 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07003988 // Ignore sensor when lid switch is open and rotation is forced.
3989 preferredRotation = mLidOpenRotation;
3990 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07003991 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07003992 // Ignore sensor when in car dock unless explicitly enabled.
3993 // This case can override the behavior of NOSENSOR, and can also
3994 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07003995 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07003996 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08003997 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
3998 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
3999 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004000 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004001 // Ignore sensor when in desk dock unless explicitly enabled.
4002 // This case can override the behavior of NOSENSOR, and can also
4003 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004004 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004005 ? sensorRotation : mDeskDockRotation;
Jeff Brown27f1d672012-10-17 18:32:34 -07004006 } else if (mHdmiPlugged && mHdmiRotationLock) {
Jeff Browneb3e4b92011-12-06 19:54:24 -08004007 // Ignore sensor when plugged into HDMI.
4008 // Note that the dock orientation overrides the HDMI orientation.
4009 preferredRotation = mHdmiRotation;
Jeff Brown207673cd2012-06-05 17:47:11 -07004010 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004011 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
4012 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED))
4013 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4014 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4015 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4016 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4017 // Otherwise, use sensor only if requested by the application or enabled
4018 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004019 if (mAllowAllRotations < 0) {
4020 // Can't read this during init() because the context doesn't
4021 // have display metrics at that time so we cannot determine
4022 // tablet vs. phone then.
4023 mAllowAllRotations = mContext.getResources().getBoolean(
4024 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4025 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004026 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004027 || mAllowAllRotations == 1
Jeff Brown01a98dd2011-09-20 15:08:29 -07004028 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR) {
4029 preferredRotation = sensorRotation;
4030 } else {
4031 preferredRotation = lastRotation;
4032 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004033 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4034 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4035 // Apply rotation lock. Does not apply to NOSENSOR.
4036 // The idea is that the user rotation expresses a weak preference for the direction
4037 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4038 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004039 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004040 } else {
4041 // No overriding preference.
4042 // We will do exactly what the application asked us to do.
4043 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004044 }
4045
Dianne Hackborne5439f22010-10-02 16:53:50 -07004046 switch (orientation) {
4047 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004048 // Return portrait unless overridden.
4049 if (isAnyPortrait(preferredRotation)) {
4050 return preferredRotation;
4051 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004052 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004053
Jeff Brown01a98dd2011-09-20 15:08:29 -07004054 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004055 // Return landscape unless overridden.
4056 if (isLandscapeOrSeascape(preferredRotation)) {
4057 return preferredRotation;
4058 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004059 return mLandscapeRotation;
4060
4061 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004062 // Return reverse portrait unless overridden.
4063 if (isAnyPortrait(preferredRotation)) {
4064 return preferredRotation;
4065 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004066 return mUpsideDownRotation;
4067
4068 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004069 // Return seascape unless overridden.
4070 if (isLandscapeOrSeascape(preferredRotation)) {
4071 return preferredRotation;
4072 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004073 return mSeascapeRotation;
4074
4075 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4076 // Return either landscape rotation.
4077 if (isLandscapeOrSeascape(preferredRotation)) {
4078 return preferredRotation;
4079 }
4080 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004081 return lastRotation;
4082 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004083 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004084
Jeff Brown01a98dd2011-09-20 15:08:29 -07004085 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4086 // Return either portrait rotation.
4087 if (isAnyPortrait(preferredRotation)) {
4088 return preferredRotation;
4089 }
4090 if (isAnyPortrait(lastRotation)) {
4091 return lastRotation;
4092 }
4093 return mPortraitRotation;
4094
4095 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004096 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4097 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004098 if (preferredRotation >= 0) {
4099 return preferredRotation;
4100 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004101 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004102 }
4103 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004104 }
4105
Jeff Brown01a98dd2011-09-20 15:08:29 -07004106 @Override
4107 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4108 switch (orientation) {
4109 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4110 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4111 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4112 return isAnyPortrait(rotation);
4113
4114 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4115 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4116 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4117 return isLandscapeOrSeascape(rotation);
4118
4119 default:
4120 return true;
4121 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004122 }
4123
Jeff Brownc0347aa2011-09-23 17:26:09 -07004124 @Override
4125 public void setRotationLw(int rotation) {
4126 mOrientationListener.setCurrentRotation(rotation);
4127 }
4128
Jeff Brown01a98dd2011-09-20 15:08:29 -07004129 private boolean isLandscapeOrSeascape(int rotation) {
4130 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004131 }
4132
Jeff Brown01a98dd2011-09-20 15:08:29 -07004133 private boolean isAnyPortrait(int rotation) {
4134 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004135 }
4136
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004137
4138 // User rotation: to be used when all else fails in assigning an orientation to the device
4139 public void setUserRotationMode(int mode, int rot) {
4140 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004141
4142 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004143 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004144 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004145 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004146 rot,
4147 UserHandle.USER_CURRENT);
4148 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004149 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004150 0,
4151 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004152 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004153 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004154 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004155 1,
4156 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004157 }
4158 }
4159
Jeff Brownac143512012-04-05 18:57:33 -07004160 public void setSafeMode(boolean safeMode) {
4161 mSafeMode = safeMode;
4162 performHapticFeedbackLw(null, safeMode
4163 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4164 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004165 }
4166
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004167 static long[] getLongIntArray(Resources r, int resid) {
4168 int[] ar = r.getIntArray(resid);
4169 if (ar == null) {
4170 return null;
4171 }
4172 long[] out = new long[ar.length];
4173 for (int i=0; i<ar.length; i++) {
4174 out[i] = ar[i];
4175 }
4176 return out;
4177 }
4178
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004179 /** {@inheritDoc} */
4180 public void systemReady() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004181 if (mKeyguardMediator != null) {
4182 // tell the keyguard
4183 mKeyguardMediator.onSystemReady();
4184 }
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004185 synchronized (mLock) {
4186 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08004187 mSystemReady = true;
4188 mHandler.post(new Runnable() {
4189 public void run() {
4190 updateSettings();
4191 }
4192 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004193 }
4194 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07004195
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004196 /** {@inheritDoc} */
4197 public void systemBooted() {
4198 synchronized (mLock) {
4199 mSystemBooted = true;
4200 }
4201 }
4202
Dianne Hackborn661cd522011-08-22 00:26:20 -07004203 ProgressDialog mBootMsgDialog = null;
4204
4205 /** {@inheritDoc} */
4206 public void showBootMessage(final CharSequence msg, final boolean always) {
Mike Lockwoodaa5bf142011-09-21 13:03:40 -04004207 if (mHeadless) return;
Dianne Hackborn661cd522011-08-22 00:26:20 -07004208 mHandler.post(new Runnable() {
4209 @Override public void run() {
4210 if (mBootMsgDialog == null) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07004211 mBootMsgDialog = new ProgressDialog(mContext) {
4212 // This dialog will consume all events coming in to
4213 // it, to avoid it trying to do things too early in boot.
4214 @Override public boolean dispatchKeyEvent(KeyEvent event) {
4215 return true;
4216 }
4217 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
4218 return true;
4219 }
4220 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
4221 return true;
4222 }
4223 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
4224 return true;
4225 }
4226 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
4227 return true;
4228 }
4229 @Override public boolean dispatchPopulateAccessibilityEvent(
4230 AccessibilityEvent event) {
4231 return true;
4232 }
4233 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07004234 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
4235 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
4236 mBootMsgDialog.setIndeterminate(true);
4237 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004238 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004239 mBootMsgDialog.getWindow().addFlags(
4240 WindowManager.LayoutParams.FLAG_DIM_BEHIND
4241 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
4242 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08004243 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
4244 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
4245 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004246 mBootMsgDialog.setCancelable(false);
4247 mBootMsgDialog.show();
4248 }
4249 mBootMsgDialog.setMessage(msg);
4250 }
4251 });
4252 }
4253
4254 /** {@inheritDoc} */
4255 public void hideBootMessages() {
4256 mHandler.post(new Runnable() {
4257 @Override public void run() {
4258 if (mBootMsgDialog != null) {
4259 mBootMsgDialog.dismiss();
4260 mBootMsgDialog = null;
4261 }
4262 }
4263 });
4264 }
4265
Mike Lockwood28569302010-01-28 11:54:40 -05004266 /** {@inheritDoc} */
4267 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004268 // ***************************************
4269 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
4270 // ***************************************
4271 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
4272 // WITH ITS LOCKS HELD.
4273 //
4274 // This code must be VERY careful about the locks
4275 // it acquires.
4276 // In fact, the current code acquires way too many,
4277 // and probably has lurking deadlocks.
4278
Mike Lockwood28569302010-01-28 11:54:40 -05004279 synchronized (mScreenLockTimeout) {
4280 if (mLockScreenTimerActive) {
4281 // reset the timer
4282 mHandler.removeCallbacks(mScreenLockTimeout);
4283 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4284 }
4285 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04004286 }
4287
Adam Cohenf7522022012-10-03 20:03:18 -07004288 class ScreenLockTimeout implements Runnable {
4289 Bundle options;
4290
4291 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05004292 public void run() {
4293 synchronized (this) {
4294 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004295 if (mKeyguardMediator != null) {
Adam Cohenf7522022012-10-03 20:03:18 -07004296 mKeyguardMediator.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004297 }
Mike Lockwood28569302010-01-28 11:54:40 -05004298 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07004299 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05004300 }
4301 }
Mike Lockwood28569302010-01-28 11:54:40 -05004302
Adam Cohenf7522022012-10-03 20:03:18 -07004303 public void setLockOptions(Bundle options) {
4304 this.options = options;
4305 }
4306 }
4307
4308 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
4309
4310 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08004311 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
4312 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07004313 if (options != null) {
4314 // In case multiple calls are made to lockNow, we don't wipe out the options
4315 // until the runnable actually executes.
4316 mScreenLockTimeout.setLockOptions(options);
4317 }
Jim Miller93c518e2012-01-17 15:55:31 -08004318 mHandler.post(mScreenLockTimeout);
4319 }
4320
Mike Lockwood28569302010-01-28 11:54:40 -05004321 private void updateLockScreenTimeout() {
4322 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004323 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
4324 mKeyguardMediator != null && mKeyguardMediator.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05004325 if (mLockScreenTimerActive != enable) {
4326 if (enable) {
4327 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
4328 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4329 } else {
4330 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
4331 mHandler.removeCallbacks(mScreenLockTimeout);
4332 }
4333 mLockScreenTimerActive = enable;
4334 }
4335 }
4336 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004337
4338 /** {@inheritDoc} */
4339 public void enableScreenAfterBoot() {
4340 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07004341 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004342 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004343 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07004344
Jeff Brownc458ce92012-04-30 14:58:40 -07004345 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07004346 if (mLidState == LID_CLOSED && mLidControlsSleep) {
4347 mPowerManager.goToSleep(SystemClock.uptimeMillis());
4348 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004349 }
4350
4351 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004352 try {
4353 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004354 mWindowManager.updateRotation(alwaysSendConfiguration, false);
4355 } catch (RemoteException e) {
4356 // Ignore
4357 }
4358 }
4359
4360 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
4361 try {
4362 //set orientation on WindowManager
4363 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004364 } catch (RemoteException e) {
4365 // Ignore
4366 }
4367 }
4368
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004369 void startDockOrHome() {
Daniel Sandler7c135202012-09-28 14:04:59 -04004370 // We don't have dock home anymore. Home is home. If you lived here, you'd be home by now.
Dianne Hackbornd8883992012-09-07 15:58:52 -07004371 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004372 }
4373
4374 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004375 * goes to the home screen
4376 * @return whether it did anything
4377 */
4378 boolean goHome() {
4379 if (false) {
4380 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07004381 try {
4382 ActivityManagerNative.getDefault().stopAppSwitches();
4383 } catch (RemoteException e) {
4384 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004385 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004386 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004387 } else {
4388 // This code brings home to the front or, if it is already
4389 // at the front, puts the device to sleep.
4390 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08004391 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
4392 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
4393 Log.d(TAG, "UTS-TEST-MODE");
4394 } else {
4395 ActivityManagerNative.getDefault().stopAppSwitches();
4396 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004397 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004398 int result = ActivityManagerNative.getDefault()
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004399 .startActivityAsUser(null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004400 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07004401 null, null, 0,
4402 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004403 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07004404 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004405 return false;
4406 }
4407 } catch (RemoteException ex) {
4408 // bummer, the activity manager, which is in this process, is dead
4409 }
4410 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004411 return true;
4412 }
4413
The Android Open Source Project0727d222009-03-11 12:11:58 -07004414 public void setCurrentOrientationLw(int newOrientation) {
4415 synchronized (mLock) {
4416 if (newOrientation != mCurrentAppOrientation) {
4417 mCurrentAppOrientation = newOrientation;
4418 updateOrientationListenerLp();
4419 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004420 }
4421 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004422
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07004423 private void performAuditoryFeedbackForAccessibilityIfNeed() {
4424 if (!isGlobalAccessibilityGestureEnabled()) {
4425 return;
4426 }
4427 AudioManager audioManager = (AudioManager) mContext.getSystemService(
4428 Context.AUDIO_SERVICE);
4429 if (audioManager.isSilentMode()) {
4430 return;
4431 }
4432 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
4433 Settings.System.DEFAULT_NOTIFICATION_URI);
4434 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
4435 ringTone.play();
4436 }
4437 private boolean isGlobalAccessibilityGestureEnabled() {
4438 return Settings.Global.getInt(mContext.getContentResolver(),
4439 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
4440 }
4441
The Android Open Source Project0727d222009-03-11 12:11:58 -07004442 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07004443 if (!mVibrator.hasVibrator()) {
4444 return false;
4445 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004446 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
4447 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -08004448 if (!always && (hapticsDisabled || mKeyguardMediator.isShowingAndNotHidden())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004449 return false;
4450 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004451 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004452 switch (effectId) {
4453 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004454 pattern = mLongPressVibePattern;
4455 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004456 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004457 pattern = mVirtualKeyVibePattern;
4458 break;
4459 case HapticFeedbackConstants.KEYBOARD_TAP:
4460 pattern = mKeyboardTapVibePattern;
4461 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004462 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004463 pattern = mSafeModeDisabledVibePattern;
4464 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004465 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004466 pattern = mSafeModeEnabledVibePattern;
4467 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08004468 default:
4469 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004470 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004471 if (pattern.length == 1) {
4472 // One-shot vibration
4473 mVibrator.vibrate(pattern[0]);
4474 } else {
4475 // Pattern vibration
4476 mVibrator.vibrate(pattern, -1);
4477 }
4478 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004479 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004480
4481 @Override
4482 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04004483 }
4484
Jeff Brownc38c9be2012-10-04 13:16:19 -07004485 @Override
4486 public void keepScreenOnStoppedLw() {
4487 if (mKeyguardMediator != null && !mKeyguardMediator.isShowingAndNotHidden()) {
4488 long curTime = SystemClock.uptimeMillis();
4489 mPowerManager.userActivity(curTime, false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004490 }
4491 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04004492
Dianne Hackborndf89e652011-10-06 22:35:11 -07004493 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08004494 // If there is no window focused, there will be nobody to handle the events
4495 // anyway, so just hang on in whatever state we're in until things settle down.
Dianne Hackborndf89e652011-10-06 22:35:11 -07004496 if (mFocusedWindow == null) {
4497 return 0;
4498 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004499 if (mFocusedWindow.getAttrs().type == TYPE_KEYGUARD && mHideLockScreen == true) {
4500 // We are updating at a point where the keyguard has gotten
4501 // focus, but we were last in a state where the top window is
4502 // hiding it. This is probably because the keyguard as been
4503 // shown while the top window was displayed, so we want to ignore
4504 // it here because this is just a very transient change and it
4505 // will quickly lose focus once it correctly gets hidden.
4506 return 0;
4507 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004508 int tmpVisibility = mFocusedWindow.getSystemUiVisibility()
Dianne Hackborne26ab702011-10-16 13:21:33 -07004509 & ~mResettingSystemUiFlags
4510 & ~mForceClearedSystemUiFlags;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004511 if (mForcingShowNavBar && mFocusedWindow.getSurfaceLayer() < mForcingShowNavBarLayer) {
4512 tmpVisibility &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
4513 }
4514 final int visibility = tmpVisibility;
Dianne Hackborne26ab702011-10-16 13:21:33 -07004515 int diff = visibility ^ mLastSystemUiFlags;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08004516 final boolean needsMenu = mFocusedWindow.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08004517 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
4518 && mFocusedApp == mFocusedWindow.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004519 return 0;
4520 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07004521 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08004522 mLastFocusNeedsMenu = needsMenu;
Dianne Hackborne0f085d2011-11-30 18:41:15 -08004523 mFocusedApp = mFocusedWindow.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07004524 mHandler.post(new Runnable() {
4525 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07004526 try {
4527 IStatusBarService statusbar = getStatusBarService();
4528 if (statusbar != null) {
4529 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
4530 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08004531 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07004532 } catch (RemoteException e) {
4533 // re-acquire status bar service next time it is needed.
4534 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08004535 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07004536 }
4537 });
4538 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08004539 }
4540
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04004541 // Use this instead of checking config_showNavigationBar so that it can be consistently
4542 // overridden by qemu.hw.mainkeys in the emulator.
4543 public boolean hasNavigationBar() {
4544 return mHasNavigationBar;
4545 }
4546
satok1bc0a492012-04-25 22:47:12 +09004547 @Override
4548 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
4549 mLastInputMethodWindow = ime;
4550 mLastInputMethodTargetWindow = target;
4551 }
4552
Craig Mautnerf1b67412012-09-19 13:18:29 -07004553 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07004554 public void setCurrentUserLw(int newUserId) {
4555 if (mKeyguardMediator != null) {
4556 mKeyguardMediator.setCurrentUser(newUserId);
4557 }
John Spurlock13451a22012-09-28 14:40:41 -04004558 if (mStatusBarService != null) {
4559 try {
4560 mStatusBarService.setCurrentUser(newUserId);
4561 } catch (RemoteException e) {
4562 // oh well
4563 }
4564 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07004565 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07004566 }
4567
4568 @Override
Jim Miller4eeb4f62012-11-08 00:04:29 -08004569 public void showAssistant() {
4570 mKeyguardMediator.showAssistant();
4571 }
4572
Svetoslav Ganov545252f2012-12-10 18:29:24 -08004573 @Override
4574 public boolean canMagnifyWindow(int windowType) {
4575 switch (windowType) {
4576 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
4577 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
4578 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
4579 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
4580 return false;
4581 }
4582 }
4583 return true;
4584 }
4585
4586 @Override
4587 public boolean isTopLevelWindow(int windowType) {
4588 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
4589 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4590 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
4591 }
4592 return true;
4593 }
4594
Jim Miller4eeb4f62012-11-08 00:04:29 -08004595 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07004596 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004597 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004598 pw.print(" mSystemReady="); pw.print(mSystemReady);
4599 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07004600 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004601 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
4602 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07004603 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
4604 || mForceClearedSystemUiFlags != 0) {
4605 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
4606 pw.print(Integer.toHexString(mLastSystemUiFlags));
4607 pw.print(" mResettingSystemUiFlags=0x");
4608 pw.print(Integer.toHexString(mResettingSystemUiFlags));
4609 pw.print(" mForceClearedSystemUiFlags=0x");
4610 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07004611 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08004612 if (mLastFocusNeedsMenu) {
4613 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
4614 pw.println(mLastFocusNeedsMenu);
4615 }
Daniel Sandler7c135202012-09-28 14:04:59 -04004616 pw.print(prefix); pw.print("mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004617 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
4618 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
4619 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
4620 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004621 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07004622 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004623 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
4624 pw.print(mCarDockEnablesAccelerometer);
4625 pw.print(" mDeskDockEnablesAccelerometer=");
4626 pw.println(mDeskDockEnablesAccelerometer);
4627 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
4628 pw.print(mLidKeyboardAccessibility);
4629 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07004630 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
4631 pw.print(prefix); pw.print("mLongPressOnPowerBehavior=");
4632 pw.print(mLongPressOnPowerBehavior);
4633 pw.print(" mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004634 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
4635 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07004636 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004637 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
4638 pw.print(","); pw.print(mUnrestrictedScreenTop);
4639 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
4640 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
4641 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
4642 pw.print(","); pw.print(mRestrictedScreenTop);
4643 pw.print(") "); pw.print(mRestrictedScreenWidth);
4644 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004645 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
4646 pw.print(","); pw.print(mStableFullscreenTop);
4647 pw.print(")-("); pw.print(mStableFullscreenRight);
4648 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004649 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
4650 pw.print(","); pw.print(mStableTop);
4651 pw.print(")-("); pw.print(mStableRight);
4652 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07004653 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
4654 pw.print(","); pw.print(mSystemTop);
4655 pw.print(")-("); pw.print(mSystemRight);
4656 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004657 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
4658 pw.print(","); pw.print(mCurTop);
4659 pw.print(")-("); pw.print(mCurRight);
4660 pw.print(","); pw.print(mCurBottom); pw.println(")");
4661 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
4662 pw.print(","); pw.print(mContentTop);
4663 pw.print(")-("); pw.print(mContentRight);
4664 pw.print(","); pw.print(mContentBottom); pw.println(")");
4665 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
4666 pw.print(","); pw.print(mDockTop);
4667 pw.print(")-("); pw.print(mDockRight);
4668 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07004669 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
4670 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004671 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
4672 pw.print(" mShowingDream="); pw.print(mShowingDream);
4673 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07004674 if (mLastInputMethodWindow != null) {
4675 pw.print(prefix); pw.print("mLastInputMethodWindow=");
4676 pw.println(mLastInputMethodWindow);
4677 }
4678 if (mLastInputMethodTargetWindow != null) {
4679 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
4680 pw.println(mLastInputMethodTargetWindow);
4681 }
4682 if (mStatusBar != null) {
4683 pw.print(prefix); pw.print("mStatusBar=");
4684 pw.println(mStatusBar);
4685 }
4686 if (mNavigationBar != null) {
4687 pw.print(prefix); pw.print("mNavigationBar=");
4688 pw.println(mNavigationBar);
4689 }
4690 if (mKeyguard != null) {
4691 pw.print(prefix); pw.print("mKeyguard=");
4692 pw.println(mKeyguard);
4693 }
4694 if (mFocusedWindow != null) {
4695 pw.print(prefix); pw.print("mFocusedWindow=");
4696 pw.println(mFocusedWindow);
4697 }
4698 if (mFocusedApp != null) {
4699 pw.print(prefix); pw.print("mFocusedApp=");
4700 pw.println(mFocusedApp);
4701 }
4702 if (mWinDismissingKeyguard != null) {
4703 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
4704 pw.println(mWinDismissingKeyguard);
4705 }
4706 if (mTopFullscreenOpaqueWindowState != null) {
4707 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
4708 pw.println(mTopFullscreenOpaqueWindowState);
4709 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004710 if (mForcingShowNavBar) {
4711 pw.print(prefix); pw.print("mForcingShowNavBar=");
4712 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
4713 pw.println(mForcingShowNavBarLayer);
4714 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004715 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004716 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004717 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
4718 pw.print(" mForceStatusBarFromKeyguard=");
4719 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004720 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004721 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004722 pw.print(" mHomePressed="); pw.println(mHomePressed);
4723 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
4724 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
4725 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
4726 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
4727 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
4728 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
4729 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
4730 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
4731 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
4732 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brown27f1d672012-10-17 18:32:34 -07004733 pw.print(prefix); pw.print("mHdmiRotation="); pw.print(mHdmiRotation);
4734 pw.print(" mHdmiRotationLock="); pw.println(mHdmiRotationLock);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004735 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004736}