blob: 024c2477ef355828bda00f5669aab6dca3eaa72b [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 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700231 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;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700415
416 // States of keyguard dismiss.
417 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
418 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
419 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
420 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
421
422 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
423 * be done once per window. */
424 private WindowState mWinDismissingKeyguard;
425
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700426 boolean mShowingLockscreen;
427 boolean mShowingDream;
428 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800429 boolean mHomePressed;
Michael Jurka7f2668c2012-03-27 07:49:52 -0700430 boolean mHomeLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800431 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700432 Intent mCarDockIntent;
433 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700434 boolean mSearchKeyShortcutPending;
435 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700436 boolean mAssistKeyLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800437
Mike Lockwood28569302010-01-28 11:54:40 -0500438 // support for activating the lock screen while the screen is on
439 boolean mAllowLockscreenWhenOn;
440 int mLockScreenTimeout;
441 boolean mLockScreenTimerActive;
442
David Brownbaf8d092010-03-08 21:52:59 -0800443 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800444 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800445
446 // Behavior of POWER button while in-call and screen on.
447 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
448 int mIncallPowerBehavior;
449
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700450 Display mDisplay;
451
Dianne Hackborn9d132642011-04-21 17:26:39 -0700452 int mLandscapeRotation = 0; // default landscape rotation
453 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
454 int mPortraitRotation = 0; // default portrait rotation
455 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700456
Joe Onorato46b0d682010-11-22 17:37:27 -0800457 // What we do when the user long presses on home
458 private int mLongPressOnHomeBehavior = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800459
Winson Chung9112ec32011-06-27 13:15:32 -0700460 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700461 // Time to volume and power must be pressed within this interval of each other.
462 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700463 // Increase the chord delay when taking a screenshot from the keyguard
464 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800465 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700466 private boolean mVolumeDownKeyTriggered;
467 private long mVolumeDownKeyTime;
468 private boolean mVolumeDownKeyConsumedByScreenshotChord;
469 private boolean mVolumeUpKeyTriggered;
470 private boolean mPowerKeyTriggered;
471 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700472
Christopher Tate5e08af02012-09-21 17:17:22 -0700473 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800474 ShortcutManager mShortcutManager;
475 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700476 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800477
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700478 // Fallback actions by key code.
479 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
480 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800481
Jeff Brown70825162012-03-28 17:27:48 -0700482 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
483 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700484 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
485 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Jeff Brown70825162012-03-28 17:27:48 -0700486
487 private class PolicyHandler extends Handler {
488 @Override
489 public void handleMessage(Message msg) {
490 switch (msg.what) {
491 case MSG_ENABLE_POINTER_LOCATION:
492 enablePointerLocation();
493 break;
494 case MSG_DISABLE_POINTER_LOCATION:
495 disablePointerLocation();
496 break;
Jeff Brown40013652012-05-16 21:22:36 -0700497 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
498 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
499 break;
500 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
501 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
502 break;
Jeff Brown70825162012-03-28 17:27:48 -0700503 }
504 }
505 }
506
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800507 private UEventObserver mHDMIObserver = new UEventObserver() {
508 @Override
509 public void onUEvent(UEventObserver.UEvent event) {
510 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
511 }
512 };
513
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800514 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800515 SettingsObserver(Handler handler) {
516 super(handler);
517 }
David Brownbaf8d092010-03-08 21:52:59 -0800518
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800519 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700520 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800521 ContentResolver resolver = mContext.getContentResolver();
522 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700523 Settings.System.END_BUTTON_BEHAVIOR), false, this,
524 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800525 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700526 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
527 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800528 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700529 Settings.System.ACCELEROMETER_ROTATION), false, this,
530 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500531 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700532 Settings.System.USER_ROTATION), false, this,
533 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400534 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700535 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
536 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800537 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700538 Settings.System.POINTER_LOCATION), false, this,
539 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800540 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700541 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
542 UserHandle.USER_ALL);
Dianne Hackborn03759ed2009-03-27 16:04:08 -0700543 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700544 "fancy_rotation_anim"), false, this,
545 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800546 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800547 }
548
549 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800550 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700551 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800552 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800553 }
554
555 class MyOrientationListener extends WindowOrientationListener {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800556 MyOrientationListener(Context context) {
557 super(context);
558 }
559
560 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700561 public void onProposedRotationChanged(int rotation) {
562 if (localLOGV) Log.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700563 updateRotation(false);
564 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800565 }
566 MyOrientationListener mOrientationListener;
567
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700568 IStatusBarService getStatusBarService() {
569 synchronized (mServiceAquireLock) {
570 if (mStatusBarService == null) {
571 mStatusBarService = IStatusBarService.Stub.asInterface(
572 ServiceManager.getService("statusbar"));
573 }
574 return mStatusBarService;
575 }
576 }
577
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700578 /*
579 * We always let the sensor be switched on by default except when
580 * the user has explicitly disabled sensor based rotation or when the
581 * screen is switched off.
582 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700583 boolean needSensorRunningLp() {
Dianne Hackborne5439f22010-10-02 16:53:50 -0700584 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
585 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
586 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
587 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800588 // If the application has explicitly requested to follow the
589 // orientation, then we need to turn the sensor or.
590 return true;
591 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700592 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800593 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
594 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
595 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400596 // enable accelerometer if we are docked in a dock that enables accelerometer
597 // orientation management,
598 return true;
599 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700600 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800601 // If the setting for using the sensor by default is enabled, then
602 // we will always leave it on. Note that the user could go to
603 // a window that forces an orientation that does not use the
604 // sensor and in theory we could turn it off... however, when next
605 // turning it on we won't have a good value for the current
606 // orientation for a little bit, which can cause orientation
607 // changes to lag, so we'd like to keep it always on. (It will
608 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700609 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800610 }
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700611 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800612 }
613
614 /*
615 * Various use cases for invoking this function
616 * screen turning off, should always disable listeners if already enabled
617 * screen turned on and current app has sensor based orientation, enable listeners
618 * if not already enabled
619 * screen turned on and current app does not have sensor orientation, disable listeners if
620 * already enabled
621 * screen turning on and current app has sensor based orientation, enable listeners if needed
622 * screen turning on and current app has nosensor based orientation, do nothing
623 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700624 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800625 if (!mOrientationListener.canDetectOrientation()) {
626 // If sensor is turned off or nonexistent for some reason
627 return;
628 }
629 //Could have been invoked due to screen turning on or off or
630 //change of the currently visible window's orientation
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700631 if (localLOGV) Log.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800632 ", current orientation="+mCurrentAppOrientation+
633 ", SensorEnabled="+mOrientationSensorEnabled);
634 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700635 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700636 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800637 disable = false;
638 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700639 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800640 mOrientationListener.enable();
Dianne Hackborn05726582009-09-22 17:28:24 -0700641 if(localLOGV) Log.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800642 mOrientationSensorEnabled = true;
643 }
644 }
645 }
646 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700647 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800648 mOrientationListener.disable();
Dianne Hackborn05726582009-09-22 17:28:24 -0700649 if(localLOGV) Log.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800650 mOrientationSensorEnabled = false;
651 }
652 }
653
Jeff Brown4d396052010-10-29 21:50:21 -0700654 private void interceptPowerKeyDown(boolean handled) {
655 mPowerKeyHandled = handled;
656 if (!handled) {
657 mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
658 }
659 }
660
661 private boolean interceptPowerKeyUp(boolean canceled) {
662 if (!mPowerKeyHandled) {
663 mHandler.removeCallbacks(mPowerLongPress);
664 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700665 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700666 return false;
667 }
668
669 private void cancelPendingPowerKeyAction() {
670 if (!mPowerKeyHandled) {
671 mHandler.removeCallbacks(mPowerLongPress);
672 }
Jeff Brownff204712011-10-25 21:27:54 -0700673 if (mPowerKeyTriggered) {
674 mPendingPowerKeyUpCanceled = true;
675 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700676 }
677
678 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800679 if (mScreenshotChordEnabled
680 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700681 final long now = SystemClock.uptimeMillis();
682 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
683 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
684 mVolumeDownKeyConsumedByScreenshotChord = true;
685 cancelPendingPowerKeyAction();
686
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800687 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700688 }
689 }
690 }
691
Winson Chung1cea2f32012-10-08 20:42:01 -0700692 private long getScreenshotChordLongPressDelay() {
693 if (mKeyguardMediator.isShowing()) {
694 // Double the time it takes to take a screenshot from the keyguard
695 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
696 ViewConfiguration.getGlobalActionKeyTimeout());
697 } else {
698 return ViewConfiguration.getGlobalActionKeyTimeout();
699 }
700 }
701
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700702 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800703 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700704 }
705
706 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700707 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800708 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700709 // The context isn't read
710 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700711 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
712 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400713 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700714 int resolvedBehavior = mLongPressOnPowerBehavior;
715 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
716 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
717 }
718
719 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700720 case LONG_PRESS_POWER_NOTHING:
721 break;
722 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
723 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700724 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
725 performAuditoryFeedbackForAccessibilityIfNeed();
726 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700727 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
728 showGlobalActionsDialog();
729 break;
730 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700731 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700732 mPowerKeyHandled = true;
733 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
734 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700735 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700736 break;
737 }
738 }
739 };
740
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800741 private final Runnable mScreenshotRunnable = new Runnable() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700742 public void run() {
743 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800744 }
745 };
746
747 void showGlobalActionsDialog() {
748 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700749 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800750 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700751 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800752 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
753 if (keyguardShowing) {
754 // since it took two seconds of long press to bring this up,
755 // poke the wake lock so they have some time to see the dialog.
Jeff Brown3dc524b2012-09-30 19:49:11 -0700756 mKeyguardMediator.userActivity();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800757 }
758 }
759
760 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700761 return Settings.Global.getInt(
762 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800763 }
764
Patrick Dubroyece94522011-02-23 18:35:01 -0800765 private void handleLongPressOnHome() {
Jim Milleree969aa2010-08-26 20:17:43 -0700766 // We can't initialize this in init() since the configuration hasn't been loaded yet.
Joe Onorato46b0d682010-11-22 17:37:27 -0800767 if (mLongPressOnHomeBehavior < 0) {
768 mLongPressOnHomeBehavior
Joe Onorato50262e52010-11-26 14:04:54 -0800769 = mContext.getResources().getInteger(R.integer.config_longPressOnHomeBehavior);
Joe Onorato46b0d682010-11-22 17:37:27 -0800770 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Michael Jurka3b1fc472011-06-13 10:54:40 -0700771 mLongPressOnHomeBehavior > LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
Joe Onorato46b0d682010-11-22 17:37:27 -0800772 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
773 }
774 }
775
776 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
777 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
778 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
Patrick Dubroyece94522011-02-23 18:35:01 -0800779
780 // Eat the longpress so it won't dismiss the recent apps dialog when
781 // the user lets go of the home key
Michael Jurka7f2668c2012-03-27 07:49:52 -0700782 mHomeLongPressed = true;
Jim Milleree969aa2010-08-26 20:17:43 -0700783 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800784
Joe Onorato46b0d682010-11-22 17:37:27 -0800785 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_DIALOG) {
Jeff Brown68b909d2011-12-07 16:36:01 -0800786 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS);
Michael Jurka3b1fc472011-06-13 10:54:40 -0700787 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
Jim Millere6ad1a82010-08-20 19:25:39 -0700788 try {
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700789 IStatusBarService statusbar = getStatusBarService();
790 if (statusbar != null) {
791 statusbar.toggleRecentApps();
792 }
Michael Jurka3b1fc472011-06-13 10:54:40 -0700793 } catch (RemoteException e) {
794 Slog.e(TAG, "RemoteException when showing recent apps", e);
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700795 // re-acquire status bar service next time it is needed.
796 mStatusBarService = null;
Jim Millere6ad1a82010-08-20 19:25:39 -0700797 }
798 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800799 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800800
801 /**
Jeff Brown68b909d2011-12-07 16:36:01 -0800802 * Create (if necessary) and show or dismiss the recent apps dialog according
803 * according to the requested behavior.
Patrick Dubroyece94522011-02-23 18:35:01 -0800804 */
Jeff Brown68b909d2011-12-07 16:36:01 -0800805 void showOrHideRecentAppsDialog(final int behavior) {
Jeff Brownda3d5a92011-03-29 15:11:34 -0700806 mHandler.post(new Runnable() {
807 @Override
808 public void run() {
809 if (mRecentAppsDialog == null) {
Jeff Brown54875002011-04-06 15:33:01 -0700810 mRecentAppsDialog = new RecentApplicationsDialog(mContext);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700811 }
Jeff Brown54875002011-04-06 15:33:01 -0700812 if (mRecentAppsDialog.isShowing()) {
Jeff Brown68b909d2011-12-07 16:36:01 -0800813 switch (behavior) {
814 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
Jeff Brown602ab322012-05-16 13:33:47 -0700815 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800816 mRecentAppsDialog.dismiss();
817 break;
818 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
819 mRecentAppsDialog.dismissAndSwitch();
820 break;
821 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
822 default:
823 break;
Jeff Brown54875002011-04-06 15:33:01 -0700824 }
825 } else {
Jeff Brown68b909d2011-12-07 16:36:01 -0800826 switch (behavior) {
827 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
828 mRecentAppsDialog.show();
829 break;
830 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
831 try {
832 mWindowManager.setInTouchMode(false);
833 } catch (RemoteException e) {
834 }
835 mRecentAppsDialog.show();
836 break;
Jeff Brown602ab322012-05-16 13:33:47 -0700837 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800838 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
839 default:
840 break;
841 }
Jeff Brown54875002011-04-06 15:33:01 -0700842 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700843 }
844 });
Patrick Dubroyece94522011-02-23 18:35:01 -0800845 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700846
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800847 /** {@inheritDoc} */
848 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700849 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800850 mContext = context;
851 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700852 mWindowManagerFuncs = windowManagerFuncs;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400853 mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
854 if (!mHeadless) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700855 // don't create KeyguardViewMediator if headless
Jim Miller9c7e6302012-08-29 13:48:34 -0700856 mKeyguardMediator = new KeyguardViewMediator(context, null);
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700857 }
Jeff Brown70825162012-03-28 17:27:48 -0700858 mHandler = new PolicyHandler();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800859 mOrientationListener = new MyOrientationListener(mContext);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700860 try {
861 mOrientationListener.setCurrentRotation(windowManager.getRotation());
862 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700863 mSettingsObserver = new SettingsObserver(mHandler);
864 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800865 mShortcutManager = new ShortcutManager(context, mHandler);
866 mShortcutManager.observe();
867 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
868 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
869 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
870 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700871 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
872 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
873 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
874 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
875 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
876 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
877 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
878 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700879
Jeff Brown96307042012-07-27 15:51:34 -0700880 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
881 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800882 "PhoneWindowManager.mBroadcastWakeLock");
883 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700884 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400885 com.android.internal.R.integer.config_lidOpenRotation);
886 mCarDockRotation = readRotation(
887 com.android.internal.R.integer.config_carDockRotation);
888 mDeskDockRotation = readRotation(
889 com.android.internal.R.integer.config_deskDockRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400890 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
891 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
892 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
893 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700894 mLidKeyboardAccessibility = mContext.getResources().getInteger(
895 com.android.internal.R.integer.config_lidKeyboardAccessibility);
896 mLidNavigationAccessibility = mContext.getResources().getInteger(
897 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -0700898 mLidControlsSleep = mContext.getResources().getBoolean(
899 com.android.internal.R.bool.config_lidControlsSleep);
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700900 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800901 IntentFilter filter = new IntentFilter();
902 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
903 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
904 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
905 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700906 filter.addAction(Intent.ACTION_DOCK_EVENT);
907 Intent intent = context.registerReceiver(mDockReceiver, filter);
908 if (intent != null) {
909 // Retrieve current sticky dock event broadcast.
910 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
911 Intent.EXTRA_DOCK_STATE_UNDOCKED);
912 }
Daniel Sandler7e37df52011-11-16 22:08:23 -0800913
Jeff Brown6aaf2952012-10-05 16:01:08 -0700914 // register for dream-related broadcasts
915 filter = new IntentFilter();
916 filter.addAction(Intent.ACTION_DREAMING_STARTED);
917 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
918 context.registerReceiver(mDreamReceiver, filter);
919
Christopher Tate5e08af02012-09-21 17:17:22 -0700920 // register for multiuser-relevant broadcasts
921 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
922 context.registerReceiver(mMultiuserReceiver, filter);
923
Jeff Brownc2346132012-04-13 01:55:38 -0700924 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700925 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
926 com.android.internal.R.array.config_longPressVibePattern);
927 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
928 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -0800929 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
930 com.android.internal.R.array.config_keyboardTapVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700931 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
932 com.android.internal.R.array.config_safeModeDisabledVibePattern);
933 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
934 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -0400935
Christopher Tatee90585f2012-03-05 18:56:25 -0800936 mScreenshotChordEnabled = mContext.getResources().getBoolean(
937 com.android.internal.R.bool.config_enableScreenshotChord);
938
Joe Onoratoea495d42011-04-06 11:41:11 -0700939 // Controls rotation and the like.
940 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -0700941
942 // Match current screen state.
943 if (mPowerManager.isScreenOn()) {
944 screenTurningOn(null);
945 } else {
946 screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
947 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700948 }
949
Dianne Hackborndde331c2012-08-03 14:01:57 -0700950 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700951 mDisplay = display;
952
953 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700954 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700955 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700956 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700957 mLandscapeRotation = Surface.ROTATION_0;
958 mSeascapeRotation = Surface.ROTATION_180;
959 if (mContext.getResources().getBoolean(
960 com.android.internal.R.bool.config_reverseDefaultRotation)) {
961 mPortraitRotation = Surface.ROTATION_90;
962 mUpsideDownRotation = Surface.ROTATION_270;
963 } else {
964 mPortraitRotation = Surface.ROTATION_270;
965 mUpsideDownRotation = Surface.ROTATION_90;
966 }
967 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700968 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700969 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700970 mPortraitRotation = Surface.ROTATION_0;
971 mUpsideDownRotation = Surface.ROTATION_180;
972 if (mContext.getResources().getBoolean(
973 com.android.internal.R.bool.config_reverseDefaultRotation)) {
974 mLandscapeRotation = Surface.ROTATION_270;
975 mSeascapeRotation = Surface.ROTATION_90;
976 } else {
977 mLandscapeRotation = Surface.ROTATION_90;
978 mSeascapeRotation = Surface.ROTATION_270;
979 }
980 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700981
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700982 mStatusBarHeight = mContext.getResources().getDimensionPixelSize(
983 com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700984
Daniel Sandler9f65c4c2012-04-26 01:35:35 -0400985 // Height of the navigation bar when presented horizontally at bottom
986 mNavigationBarHeightForRotation[mPortraitRotation] =
987 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Daniel Sandler4a066c52012-04-20 14:49:13 -0400988 mContext.getResources().getDimensionPixelSize(
989 com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -0400990 mNavigationBarHeightForRotation[mLandscapeRotation] =
991 mNavigationBarHeightForRotation[mSeascapeRotation] =
992 mContext.getResources().getDimensionPixelSize(
993 com.android.internal.R.dimen.navigation_bar_height_landscape);
994
995 // Width of the navigation bar when presented vertically along one side
996 mNavigationBarWidthForRotation[mPortraitRotation] =
997 mNavigationBarWidthForRotation[mUpsideDownRotation] =
998 mNavigationBarWidthForRotation[mLandscapeRotation] =
999 mNavigationBarWidthForRotation[mSeascapeRotation] =
Daniel Sandler4a066c52012-04-20 14:49:13 -04001000 mContext.getResources().getDimensionPixelSize(
1001 com.android.internal.R.dimen.navigation_bar_width);
1002
1003 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001004 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001005
1006 if (shortSizeDp < 600) {
1007 // 0-599dp: "phone" UI with a separate status & navigation bar
1008 mHasSystemNavBar = false;
1009 mNavigationBarCanMove = true;
1010 } else if (shortSizeDp < 720) {
Daniel Sandleref863702012-07-11 10:03:34 -04001011 // 600+dp: "phone" UI with modifications for larger screens
Daniel Sandler4a066c52012-04-20 14:49:13 -04001012 mHasSystemNavBar = false;
1013 mNavigationBarCanMove = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001014 }
Daniel Sandler36412a72011-08-04 09:35:13 -04001015
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001016 if (!mHasSystemNavBar) {
1017 mHasNavigationBar = mContext.getResources().getBoolean(
1018 com.android.internal.R.bool.config_showNavigationBar);
1019 // Allow a system property to override this. Used by the emulator.
1020 // See also hasNavigationBar().
1021 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1022 if (! "".equals(navBarOverride)) {
1023 if (navBarOverride.equals("1")) mHasNavigationBar = false;
1024 else if (navBarOverride.equals("0")) mHasNavigationBar = true;
1025 }
1026 } else {
1027 mHasNavigationBar = false;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001028 }
1029
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001030 if (mHasSystemNavBar) {
1031 // The system bar is always at the bottom. If you are watching
1032 // a video in landscape, we don't need to hide it if we can still
1033 // show a 16:9 aspect ratio with it.
Dianne Hackborndde331c2012-08-03 14:01:57 -07001034 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001035 int barHeightDp = mNavigationBarHeightForRotation[mLandscapeRotation]
Dianne Hackborndde331c2012-08-03 14:01:57 -07001036 * DisplayMetrics.DENSITY_DEFAULT / density;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001037 int aspect = ((shortSizeDp-barHeightDp) * 16) / longSizeDp;
1038 // We have computed the aspect ratio with the bar height taken
1039 // out to be 16:aspect. If this is less than 9, then hiding
1040 // the navigation bar will provide more useful space for wide
1041 // screen movies.
1042 mCanHideNavigationBar = aspect < 9;
1043 } else if (mHasNavigationBar) {
1044 // The navigation bar is at the right in landscape; it seems always
1045 // useful to hide it for showing a video.
1046 mCanHideNavigationBar = true;
1047 } else {
1048 mCanHideNavigationBar = false;
1049 }
Erik Gilling9a41ef82011-09-26 19:21:03 -07001050
Jeff Brown27f1d672012-10-17 18:32:34 -07001051 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1052 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001053 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
1054 mHdmiRotation = mPortraitRotation;
1055 } else {
1056 mHdmiRotation = mLandscapeRotation;
1057 }
Jeff Brown74bea062012-10-25 12:16:10 -07001058 mHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Dianne Hackborn9d132642011-04-21 17:26:39 -07001059 }
1060
Dianne Hackbornc777e072010-02-12 13:07:59 -08001061 public void updateSettings() {
1062 ContentResolver resolver = mContext.getContentResolver();
1063 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001064 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001065 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001066 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001067 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1068 UserHandle.USER_CURRENT);
1069 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001070 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001071 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1072 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001073
Jeff Brown207673cd2012-06-05 17:47:11 -07001074 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001075 int userRotation = Settings.System.getIntForUser(resolver,
1076 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1077 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001078 if (mUserRotation != userRotation) {
1079 mUserRotation = userRotation;
1080 updateRotation = true;
1081 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001082 int userRotationMode = Settings.System.getIntForUser(resolver,
1083 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001084 WindowManagerPolicy.USER_ROTATION_FREE :
1085 WindowManagerPolicy.USER_ROTATION_LOCKED;
1086 if (mUserRotationMode != userRotationMode) {
1087 mUserRotationMode = userRotationMode;
1088 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001089 updateOrientationListenerLp();
1090 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001091
Dianne Hackbornc777e072010-02-12 13:07:59 -08001092 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001093 int pointerLocation = Settings.System.getIntForUser(resolver,
1094 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001095 if (mPointerLocationMode != pointerLocation) {
1096 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001097 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1098 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001099 }
1100 }
1101 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001102 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1103 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1104 String imId = Settings.Secure.getStringForUser(resolver,
1105 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001106 boolean hasSoftInput = imId != null && imId.length() > 0;
1107 if (mHasSoftInput != hasSoftInput) {
1108 mHasSoftInput = hasSoftInput;
1109 updateRotation = true;
1110 }
1111 }
1112 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001113 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001114 }
Jeff Brown70825162012-03-28 17:27:48 -07001115 }
1116
1117 private void enablePointerLocation() {
1118 if (mPointerLocationView == null) {
1119 mPointerLocationView = new PointerLocationView(mContext);
1120 mPointerLocationView.setPrintCoords(false);
1121
Dianne Hackbornc777e072010-02-12 13:07:59 -08001122 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1123 WindowManager.LayoutParams.MATCH_PARENT,
1124 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001125 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001126 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1127 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1128 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1129 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001130 if (ActivityManager.isHighEndGfx()) {
1131 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1132 lp.privateFlags |=
1133 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1134 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001135 lp.format = PixelFormat.TRANSLUCENT;
1136 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001137 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001138 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001139 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001140 wm.addView(mPointerLocationView, lp);
1141
Jeff Brownac143512012-04-05 18:57:33 -07001142 mPointerLocationInputChannel =
1143 mWindowManagerFuncs.monitorInput("PointerLocationView");
1144 mPointerLocationInputEventReceiver =
1145 new PointerLocationInputEventReceiver(mPointerLocationInputChannel,
1146 Looper.myLooper(), mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001147 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001148 }
Jeff Brown70825162012-03-28 17:27:48 -07001149
1150 private void disablePointerLocation() {
1151 if (mPointerLocationInputEventReceiver != null) {
1152 mPointerLocationInputEventReceiver.dispose();
1153 mPointerLocationInputEventReceiver = null;
1154 }
1155
1156 if (mPointerLocationInputChannel != null) {
1157 mPointerLocationInputChannel.dispose();
1158 mPointerLocationInputChannel = null;
1159 }
1160
1161 if (mPointerLocationView != null) {
1162 WindowManager wm = (WindowManager)
1163 mContext.getSystemService(Context.WINDOW_SERVICE);
1164 wm.removeView(mPointerLocationView);
1165 mPointerLocationView = null;
1166 }
1167 }
1168
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001169 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001170 try {
1171 int rotation = mContext.getResources().getInteger(resID);
1172 switch (rotation) {
1173 case 0:
1174 return Surface.ROTATION_0;
1175 case 90:
1176 return Surface.ROTATION_90;
1177 case 180:
1178 return Surface.ROTATION_180;
1179 case 270:
1180 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001181 }
1182 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001183 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001184 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001185 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001186 }
1187
1188 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001189 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001190 public int checkAddPermission(WindowManager.LayoutParams attrs) {
1191 int type = attrs.type;
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07001192
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001193 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1194 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001195 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001196 }
1197 String permission = null;
1198 switch (type) {
1199 case TYPE_TOAST:
1200 // XXX right now the app process has complete control over
1201 // this... should introduce a token to let the system
1202 // monitor/control what they are doing.
1203 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001204 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001205 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001206 case TYPE_WALLPAPER:
1207 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001208 break;
1209 case TYPE_PHONE:
1210 case TYPE_PRIORITY_PHONE:
1211 case TYPE_SYSTEM_ALERT:
1212 case TYPE_SYSTEM_ERROR:
1213 case TYPE_SYSTEM_OVERLAY:
1214 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
1215 break;
1216 default:
1217 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1218 }
1219 if (permission != null) {
1220 if (mContext.checkCallingOrSelfPermission(permission)
1221 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001222 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001223 }
1224 }
Jeff Brown98365d72012-08-19 20:30:52 -07001225 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001226 }
Craig Mautner88400d32012-09-30 12:35:45 -07001227
1228 @Override
1229 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1230
1231 // If this switch statement is modified, modify the comment in the declarations of
1232 // the type in {@link WindowManager.LayoutParams} as well.
1233 switch (attrs.type) {
1234 default:
1235 // These are the windows that by default are shown only to the user that created
1236 // them. If this needs to be overridden, set
1237 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1238 // {@link WindowManager.LayoutParams}. Note that permission
1239 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1240 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1241 return true;
1242 }
1243 break;
1244
1245 // These are the windows that by default are shown to all users. However, to
1246 // protect against spoofing, check permissions below.
1247 case TYPE_APPLICATION_STARTING:
1248 case TYPE_BOOT_PROGRESS:
1249 case TYPE_DISPLAY_OVERLAY:
1250 case TYPE_HIDDEN_NAV_CONSUMER:
1251 case TYPE_KEYGUARD:
1252 case TYPE_KEYGUARD_DIALOG:
1253 case TYPE_MAGNIFICATION_OVERLAY:
1254 case TYPE_NAVIGATION_BAR:
1255 case TYPE_NAVIGATION_BAR_PANEL:
1256 case TYPE_PHONE:
1257 case TYPE_POINTER:
1258 case TYPE_PRIORITY_PHONE:
1259 case TYPE_RECENTS_OVERLAY:
1260 case TYPE_SEARCH_BAR:
1261 case TYPE_STATUS_BAR:
1262 case TYPE_STATUS_BAR_PANEL:
1263 case TYPE_STATUS_BAR_SUB_PANEL:
1264 case TYPE_SYSTEM_DIALOG:
1265 case TYPE_UNIVERSE_BACKGROUND:
1266 case TYPE_VOLUME_OVERLAY:
1267 break;
1268 }
1269
1270 // Check if third party app has set window to system window type.
1271 return mContext.checkCallingOrSelfPermission(
1272 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1273 != PackageManager.PERMISSION_GRANTED;
1274 }
1275
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001276 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1277 switch (attrs.type) {
1278 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001279 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001280 case TYPE_TOAST:
1281 // These types of windows can't receive input events.
1282 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1283 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001284 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001285 break;
1286 }
1287 }
1288
1289 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001290 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001291 }
1292
Jeff Browndaa37532012-05-01 15:54:03 -07001293 private boolean isHidden(int accessibilityMode) {
1294 switch (accessibilityMode) {
1295 case 1:
1296 return mLidState == LID_CLOSED;
1297 case 2:
1298 return mLidState == LID_OPEN;
1299 default:
1300 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001301 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001302 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001303
Jeff Browndaa37532012-05-01 15:54:03 -07001304 private boolean isBuiltInKeyboardVisible() {
1305 return mHaveBuiltInKeyboard && !isHidden(mLidKeyboardAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -07001306 }
1307
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001308 /** {@inheritDoc} */
Jeff Browndaa37532012-05-01 15:54:03 -07001309 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1310 int navigationPresence) {
1311 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1312
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001313 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001314 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001315
Jeff Browndaa37532012-05-01 15:54:03 -07001316 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1317 || (keyboardPresence == PRESENCE_INTERNAL
1318 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001319 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001320 if (!mHasSoftInput) {
1321 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1322 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001323 }
1324
Jeff Browndaa37532012-05-01 15:54:03 -07001325 if (config.navigation == Configuration.NAVIGATION_NONAV
1326 || (navigationPresence == PRESENCE_INTERNAL
1327 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001328 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001329 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001330 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001331
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001332 /** {@inheritDoc} */
1333 public int windowTypeToLayerLw(int type) {
1334 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001335 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001336 }
1337 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001338 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001339 return 1;
1340 case TYPE_WALLPAPER:
1341 // wallpaper is at the bottom, though the window manager may move it.
1342 return 2;
1343 case TYPE_PHONE:
1344 return 3;
1345 case TYPE_SEARCH_BAR:
1346 return 4;
Craig Mautner88400d32012-09-30 12:35:45 -07001347 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001348 case TYPE_SYSTEM_DIALOG:
1349 return 5;
1350 case TYPE_TOAST:
1351 // toasts and the plugged-in battery thing
1352 return 6;
1353 case TYPE_PRIORITY_PHONE:
1354 // SIM errors and unlock. Not sure if this really should be in a high layer.
1355 return 7;
1356 case TYPE_DREAM:
1357 // used for Dreams (screensavers with TYPE_DREAM windows)
1358 return 8;
1359 case TYPE_SYSTEM_ALERT:
1360 // like the ANR / app crashed dialogs
1361 return 9;
1362 case TYPE_INPUT_METHOD:
1363 // on-screen keyboards and other such input method user interfaces go here.
1364 return 10;
1365 case TYPE_INPUT_METHOD_DIALOG:
1366 // on-screen keyboards and other such input method user interfaces go here.
1367 return 11;
1368 case TYPE_KEYGUARD:
1369 // the keyguard; nothing on top of these can take focus, since they are
1370 // responsible for power management when displayed.
1371 return 12;
1372 case TYPE_KEYGUARD_DIALOG:
1373 return 13;
1374 case TYPE_STATUS_BAR_SUB_PANEL:
1375 return 14;
1376 case TYPE_STATUS_BAR:
1377 return 15;
1378 case TYPE_STATUS_BAR_PANEL:
1379 return 16;
1380 case TYPE_VOLUME_OVERLAY:
1381 // the on-screen volume indicator and controller shown when the user
1382 // changes the device volume
1383 return 17;
1384 case TYPE_SYSTEM_OVERLAY:
1385 // the on-screen volume indicator and controller shown when the user
1386 // changes the device volume
1387 return 18;
1388 case TYPE_NAVIGATION_BAR:
1389 // the navigation bar, if available, shows atop most things
1390 return 19;
1391 case TYPE_NAVIGATION_BAR_PANEL:
1392 // some panels (e.g. search) need to show on top of the navigation bar
1393 return 20;
1394 case TYPE_SYSTEM_ERROR:
1395 // system-level error dialogs
1396 return 21;
1397 case TYPE_MAGNIFICATION_OVERLAY:
1398 // used to highlight the magnified portion of a display
1399 return 22;
1400 case TYPE_DISPLAY_OVERLAY:
1401 // used to simulate secondary display devices
1402 return 23;
1403 case TYPE_DRAG:
1404 // the drag layer: input for drag-and-drop is associated with this window,
1405 // which sits above all other focusable windows
1406 return 24;
1407 case TYPE_SECURE_SYSTEM_OVERLAY:
1408 return 25;
1409 case TYPE_BOOT_PROGRESS:
1410 return 26;
1411 case TYPE_POINTER:
1412 // the (mouse) pointer layer
1413 return 27;
1414 case TYPE_HIDDEN_NAV_CONSUMER:
1415 return 28;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001416 }
1417 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001418 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001419 }
1420
1421 /** {@inheritDoc} */
1422 public int subWindowTypeToLayerLw(int type) {
1423 switch (type) {
1424 case TYPE_APPLICATION_PANEL:
1425 case TYPE_APPLICATION_ATTACHED_DIALOG:
1426 return APPLICATION_PANEL_SUBLAYER;
1427 case TYPE_APPLICATION_MEDIA:
1428 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001429 case TYPE_APPLICATION_MEDIA_OVERLAY:
1430 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001431 case TYPE_APPLICATION_SUB_PANEL:
1432 return APPLICATION_SUB_PANEL_SUBLAYER;
1433 }
1434 Log.e(TAG, "Unknown sub-window type: " + type);
1435 return 0;
1436 }
1437
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001438 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001439 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001440 }
1441
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001442 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001443 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001444 }
1445
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001446 public boolean hasSystemNavBar() {
1447 return mHasSystemNavBar;
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001448 }
1449
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001450 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001451 if (mHasNavigationBar) {
1452 // For a basic navigation bar, when we are in landscape mode we place
1453 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001454 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1455 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001456 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001457 }
1458 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001459 }
1460
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001461 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001462 if (mHasSystemNavBar) {
1463 // For the system navigation bar, we always place it at the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001464 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001465 }
1466 if (mHasNavigationBar) {
1467 // For a basic navigation bar, when we are in portrait mode we place
1468 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001469 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1470 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001471 }
1472 }
1473 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001474 }
1475
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001476 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1477 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001478 }
1479
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001480 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001481 // If we don't have a system nav bar, then there is a separate status
1482 // bar at the top of the display. We don't count that as part of the
1483 // fixed decor, since it can hide; however, for purposes of configurations,
1484 // we do want to exclude it since applications can't generally use that part
1485 // of the screen.
1486 if (!mHasSystemNavBar) {
1487 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
1488 }
1489 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation);
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001490 }
1491
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001492 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001493 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) {
1494 return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD;
1495 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001496
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001497 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001498 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001499 switch (attrs.type) {
1500 case TYPE_STATUS_BAR:
1501 case TYPE_NAVIGATION_BAR:
1502 case TYPE_WALLPAPER:
1503 case TYPE_DREAM:
1504 case TYPE_UNIVERSE_BACKGROUND:
1505 case TYPE_KEYGUARD:
1506 return false;
1507 default:
1508 return true;
1509 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001510 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001511
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001512 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001513 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001514 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1515 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
1516 int icon, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001517 if (!SHOW_STARTING_ANIMATIONS) {
1518 return null;
1519 }
1520 if (packageName == null) {
1521 return null;
1522 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001523
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001524 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001525 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001526 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1527 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1528 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001529 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001530 try {
1531 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001532 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001533 } catch (PackageManager.NameNotFoundException e) {
1534 // Ignore
1535 }
1536 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001537
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001538 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001539 final TypedArray ta = win.getWindowStyle();
1540 if (ta.getBoolean(
1541 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1542 || ta.getBoolean(
1543 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001544 return null;
1545 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001546
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001547 Resources r = context.getResources();
1548 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001549
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001550 win.setType(
1551 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1552 // Force the window flags: this is a fake window, so it is not really
1553 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1554 // flag because we do know that the next window will take input
1555 // focus, so we want to get the IME window up on top of us right away.
1556 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001557 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001558 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1559 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1560 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
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);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001565
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001566 if (!compatInfo.supportsScreen()) {
1567 win.addFlags(WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW);
1568 }
1569
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001570 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001571 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001572
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001573 final WindowManager.LayoutParams params = win.getAttributes();
1574 params.token = appToken;
1575 params.packageName = packageName;
1576 params.windowAnimations = win.getWindowStyle().getResourceId(
1577 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001578 params.privateFlags |=
1579 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001580 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001581 params.setTitle("Starting " + packageName);
1582
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001583 WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001584 View view = win.getDecorView();
1585
1586 if (win.isFloating()) {
1587 // Whoops, there is no way to display an animation/preview
1588 // of such a thing! After all that work... let's skip it.
1589 // (Note that we must do this here because it is in
1590 // getDecorView() where the theme is evaluated... maybe
1591 // we should peek the floating attribute from the theme
1592 // earlier.)
1593 return null;
1594 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001595
Craig Mautner6fbda632012-07-03 09:26:39 -07001596 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001597 TAG, "Adding starting window for " + packageName
1598 + " / " + appToken + ": "
1599 + (view.getParent() != null ? view : null));
1600
1601 wm.addView(view, params);
1602
1603 // Only return the view if it was successfully added to the
1604 // window manager... which we can tell by it having a parent.
1605 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001606 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001607 // ignore
1608 Log.w(TAG, appToken + " already running, starting window not displayed");
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001609 } catch (RuntimeException e) {
1610 // don't crash if something else bad happens, for example a
1611 // failure loading resources because we are loading from an app
1612 // on external storage that has been unmounted.
1613 Log.w(TAG, appToken + " failed creating starting window", e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001614 }
1615
1616 return null;
1617 }
1618
1619 /** {@inheritDoc} */
1620 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001621 if (DEBUG_STARTING_WINDOW) {
1622 RuntimeException e = new RuntimeException("here");
1623 e.fillInStackTrace();
1624 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1625 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001626
1627 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001628 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001629 wm.removeView(window);
1630 }
1631 }
1632
1633 /**
1634 * Preflight adding a window to the system.
1635 *
1636 * Currently enforces that three window types are singletons:
1637 * <ul>
1638 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001639 * <li>KEYGUARD_TYPE</li>
1640 * </ul>
1641 *
1642 * @param win The window to be added
1643 * @param attrs Information about the window to be added
1644 *
Jeff Brown98365d72012-08-19 20:30:52 -07001645 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1646 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001647 */
1648 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1649 switch (attrs.type) {
1650 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001651 mContext.enforceCallingOrSelfPermission(
1652 android.Manifest.permission.STATUS_BAR_SERVICE,
1653 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001654 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001655 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001656 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001657 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001658 }
1659 mStatusBar = win;
1660 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001661 case TYPE_NAVIGATION_BAR:
1662 mContext.enforceCallingOrSelfPermission(
1663 android.Manifest.permission.STATUS_BAR_SERVICE,
1664 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001665 if (mNavigationBar != null) {
1666 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001667 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001668 }
1669 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001670 mNavigationBar = win;
1671 if (DEBUG_LAYOUT) Log.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
1672 break;
Jim Millere898ac52012-04-06 17:10:57 -07001673 case TYPE_NAVIGATION_BAR_PANEL:
1674 mContext.enforceCallingOrSelfPermission(
1675 android.Manifest.permission.STATUS_BAR_SERVICE,
1676 "PhoneWindowManager");
1677 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001678 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001679 mContext.enforceCallingOrSelfPermission(
1680 android.Manifest.permission.STATUS_BAR_SERVICE,
1681 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001682 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001683 case TYPE_STATUS_BAR_SUB_PANEL:
1684 mContext.enforceCallingOrSelfPermission(
1685 android.Manifest.permission.STATUS_BAR_SERVICE,
1686 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001687 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001688 case TYPE_KEYGUARD:
1689 if (mKeyguard != null) {
Jeff Brown98365d72012-08-19 20:30:52 -07001690 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001691 }
1692 mKeyguard = win;
1693 break;
1694 }
Jeff Brown98365d72012-08-19 20:30:52 -07001695 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001696 }
1697
1698 /** {@inheritDoc} */
1699 public void removeWindowLw(WindowState win) {
1700 if (mStatusBar == win) {
1701 mStatusBar = null;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001702 } else if (mKeyguard == win) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001703 mKeyguard = null;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001704 } else if (mNavigationBar == win) {
1705 mNavigationBar = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001706 }
1707 }
1708
1709 static final boolean PRINT_ANIM = false;
1710
1711 /** {@inheritDoc} */
1712 public int selectAnimationLw(WindowState win, int transit) {
1713 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1714 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001715 if (win == mStatusBar) {
1716 if (transit == TRANSIT_EXIT || transit == TRANSIT_HIDE) {
1717 return R.anim.dock_top_exit;
1718 } else if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
1719 return R.anim.dock_top_enter;
1720 }
1721 } else if (win == mNavigationBar) {
1722 // This can be on either the bottom or the right.
1723 if (mNavigationBarOnBottom) {
1724 if (transit == TRANSIT_EXIT || transit == TRANSIT_HIDE) {
1725 return R.anim.dock_bottom_exit;
1726 } else if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
1727 return R.anim.dock_bottom_enter;
1728 }
1729 } else {
1730 if (transit == TRANSIT_EXIT || transit == TRANSIT_HIDE) {
1731 return R.anim.dock_right_exit;
1732 } else if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
1733 return R.anim.dock_right_enter;
1734 }
1735 }
1736 } if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001737 if (win.hasAppShownWindows()) {
1738 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1739 return com.android.internal.R.anim.app_starting_exit;
1740 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001741 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001742 && transit == TRANSIT_ENTER) {
1743 // Special case: we are animating in a dream, while the keyguard
1744 // is shown. We don't want an animation on the dream, because
1745 // we need it shown immediately with the keyguard animating away
1746 // to reveal it.
1747 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001748 }
1749
1750 return 0;
1751 }
1752
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07001753 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
1754 return AnimationUtils.loadAnimation(mContext, onWallpaper
1755 ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter
1756 : com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001757 }
1758
Jeff Brown4d396052010-10-29 21:50:21 -07001759 static ITelephony getTelephonyService() {
Mike Lockwoodf5f4ec92011-11-08 14:05:31 -08001760 return ITelephony.Stub.asInterface(
Jeff Brown4d396052010-10-29 21:50:21 -07001761 ServiceManager.checkService(Context.TELEPHONY_SERVICE));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001762 }
1763
Jeff Brown4d396052010-10-29 21:50:21 -07001764 static IAudioService getAudioService() {
1765 IAudioService audioService = IAudioService.Stub.asInterface(
1766 ServiceManager.checkService(Context.AUDIO_SERVICE));
1767 if (audioService == null) {
1768 Log.w(TAG, "Unable to find IAudioService interface.");
1769 }
1770 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001771 }
1772
1773 boolean keyguardOn() {
1774 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
1775 }
1776
1777 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
1778 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
1779 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
1780 };
1781
1782 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001783 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001784 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001785 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08001786 final int keyCode = event.getKeyCode();
1787 final int repeatCount = event.getRepeatCount();
1788 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001789 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08001790 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
1791 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001792
Jeff Brown40013652012-05-16 21:22:36 -07001793 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001794 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001795 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
1796 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001797 }
1798
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001799 // If we think we might have a volume down & power key chord on the way
1800 // but we're not sure, then tell the dispatcher to wait a little while and
1801 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08001802 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001803 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
1804 final long now = SystemClock.uptimeMillis();
1805 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
1806 if (now < timeoutTime) {
1807 return timeoutTime - now;
1808 }
1809 }
1810 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
1811 && mVolumeDownKeyConsumedByScreenshotChord) {
1812 if (!down) {
1813 mVolumeDownKeyConsumedByScreenshotChord = false;
1814 }
1815 return -1;
1816 }
1817 }
1818
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001819 // First we always handle the home key here, so applications
1820 // can never break it, although if keyguard is on, we do let
1821 // it handle it, because that gives us the correct 5 second
1822 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001823 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001824
Jeff Brown49ed71d2010-12-06 17:13:33 -08001825 // If we have released the home key, and didn't do anything else
1826 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07001827 if (!down) {
1828 final boolean homeWasLongPressed = mHomeLongPressed;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001829 mHomePressed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07001830 mHomeLongPressed = false;
1831 if (!homeWasLongPressed) {
Michael Jurka01de93d2012-04-13 09:32:47 -07001832 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1833 try {
1834 IStatusBarService statusbar = getStatusBarService();
1835 if (statusbar != null) {
1836 statusbar.cancelPreloadRecentApps();
1837 }
1838 } catch (RemoteException e) {
1839 Slog.e(TAG, "RemoteException when showing recent apps", e);
1840 // re-acquire status bar service next time it is needed.
1841 mStatusBarService = null;
Dianne Hackborn42e620c2012-06-24 13:20:51 -07001842 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08001843 }
1844
Michael Jurka7f2668c2012-03-27 07:49:52 -07001845 mHomePressed = false;
1846 if (!canceled) {
1847 // If an incoming call is ringing, HOME is totally disabled.
1848 // (The user is already on the InCallScreen at this point,
1849 // and his ONLY options are to answer or reject the call.)
1850 boolean incomingRinging = false;
1851 try {
1852 ITelephony telephonyService = getTelephonyService();
1853 if (telephonyService != null) {
1854 incomingRinging = telephonyService.isRinging();
1855 }
1856 } catch (RemoteException ex) {
1857 Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
1858 }
1859
1860 if (incomingRinging) {
1861 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
1862 } else {
1863 launchHomeFromHotKey();
1864 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08001865 } else {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001866 Log.i(TAG, "Ignoring HOME; event canceled.");
Jeff Brown49ed71d2010-12-06 17:13:33 -08001867 }
Michael Jurka7f2668c2012-03-27 07:49:52 -07001868 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001869 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08001870 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001871
1872 // If a system window has focus, then it doesn't make sense
1873 // right now to interact with applications.
1874 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
1875 if (attrs != null) {
1876 final int type = attrs.type;
1877 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
1878 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
1879 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001880 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001881 }
1882 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
1883 for (int i=0; i<typeCount; i++) {
1884 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
1885 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001886 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001887 }
1888 }
1889 }
Jeff Brown98392ef2011-09-12 18:24:59 -07001890 if (down) {
Michael Jurka40040332012-05-29 08:25:32 -07001891 if (!mHomePressed && mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001892 try {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07001893 IStatusBarService statusbar = getStatusBarService();
1894 if (statusbar != null) {
1895 statusbar.preloadRecentApps();
1896 }
Michael Jurka7f2668c2012-03-27 07:49:52 -07001897 } catch (RemoteException e) {
1898 Slog.e(TAG, "RemoteException when preloading recent apps", e);
Dianne Hackborn42e620c2012-06-24 13:20:51 -07001899 // re-acquire status bar service next time it is needed.
1900 mStatusBarService = null;
Michael Jurka7f2668c2012-03-27 07:49:52 -07001901 }
1902 }
Jeff Brown98392ef2011-09-12 18:24:59 -07001903 if (repeatCount == 0) {
1904 mHomePressed = true;
1905 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
1906 if (!keyguardOn) {
1907 handleLongPressOnHome();
1908 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001909 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001910 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001911 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001912 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001913 // Hijack modified menu keys for debugging features
1914 final int chordBug = KeyEvent.META_SHIFT_ON;
1915
1916 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001917 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001918 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07001919 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
1920 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001921 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001922 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001923 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001924 Intent service = new Intent();
1925 service.setClassName(mContext, "com.android.server.LoadAverageService");
1926 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07001927 boolean shown = Settings.Global.getInt(
1928 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001929 if (!shown) {
1930 mContext.startService(service);
1931 } else {
1932 mContext.stopService(service);
1933 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07001934 Settings.Global.putInt(
1935 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001936 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001937 }
1938 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001939 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001940 if (down) {
1941 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001942 mSearchKeyShortcutPending = true;
1943 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001944 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001945 } else {
1946 mSearchKeyShortcutPending = false;
1947 if (mConsumeSearchKeyUp) {
1948 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001949 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001950 }
1951 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001952 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001953 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Jeff Brown602ab322012-05-16 13:33:47 -07001954 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08001955 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS);
Jeff Brown49ed71d2010-12-06 17:13:33 -08001956 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001957 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07001958 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
1959 if (down) {
1960 if (repeatCount == 0) {
1961 mAssistKeyLongPressed = false;
1962 } else if (repeatCount == 1) {
1963 mAssistKeyLongPressed = true;
1964 if (!keyguardOn) {
1965 launchAssistLongPressAction();
1966 }
1967 }
1968 } else {
1969 if (mAssistKeyLongPressed) {
1970 mAssistKeyLongPressed = false;
1971 } else {
1972 if (!keyguardOn) {
1973 launchAssistAction();
1974 }
1975 }
1976 }
1977 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001978 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
1979 if (down && repeatCount == 0) {
1980 mHandler.post(mScreenshotRunnable);
1981 }
1982 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001983 }
Jeff Browncaab4d02010-12-09 22:13:41 -08001984
Jeff Brownc1fb48d2010-12-08 16:52:09 -08001985 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08001986 // Any printing key that is chorded with Search should be consumed
1987 // even if no shortcut was invoked. This prevents text from being
1988 // inadvertently inserted when using a keyboard that has built-in macro
1989 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001990 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08001991 final KeyCharacterMap kcm = event.getKeyCharacterMap();
1992 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001993 mConsumeSearchKeyUp = true;
1994 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08001995 if (down && repeatCount == 0 && !keyguardOn) {
1996 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
1997 if (shortcutIntent != null) {
1998 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08001999 try {
2000 mContext.startActivity(shortcutIntent);
2001 } catch (ActivityNotFoundException ex) {
2002 Slog.w(TAG, "Dropping shortcut key combination because "
2003 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002004 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002005 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002006 } else {
2007 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002008 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002009 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002010 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002011 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002012 }
2013 }
2014
Jeff Brown68b909d2011-12-07 16:36:01 -08002015 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002016 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002017 && (metaState & KeyEvent.META_META_ON) != 0) {
2018 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002019 if (kcm.isPrintingKey(keyCode)) {
2020 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2021 metaState & ~(KeyEvent.META_META_ON
2022 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2023 if (shortcutIntent != null) {
2024 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2025 try {
2026 mContext.startActivity(shortcutIntent);
2027 } catch (ActivityNotFoundException ex) {
2028 Slog.w(TAG, "Dropping shortcut key combination because "
2029 + "the activity to which it is registered was not found: "
2030 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2031 }
2032 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002033 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002034 }
2035 }
2036
Jeff Brown6651a632011-11-28 12:59:11 -08002037 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002038 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002039 String category = sApplicationLaunchKeyCategories.get(keyCode);
2040 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002041 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002042 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2043 try {
2044 mContext.startActivity(intent);
2045 } catch (ActivityNotFoundException ex) {
2046 Slog.w(TAG, "Dropping application launch key because "
2047 + "the activity to which it is registered was not found: "
2048 + "keyCode=" + keyCode + ", category=" + category, ex);
2049 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002050 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002051 }
2052 }
2053
Jeff Brown68b909d2011-12-07 16:36:01 -08002054 // Display task switcher for ALT-TAB or Meta-TAB.
2055 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Jeff Brown602ab322012-05-16 13:33:47 -07002056 if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002057 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
2058 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2059 || KeyEvent.metaStateHasModifiers(
2060 shiftlessModifiers, KeyEvent.META_META_ON)) {
2061 mRecentAppsDialogHeldModifiers = shiftlessModifiers;
2062 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW);
2063 return -1;
2064 }
2065 }
2066 } else if (!down && mRecentAppsDialogHeldModifiers != 0
2067 && (metaState & mRecentAppsDialogHeldModifiers) == 0) {
2068 mRecentAppsDialogHeldModifiers = 0;
Jeff Brown602ab322012-05-16 13:33:47 -07002069 showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS :
2070 RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH);
Jeff Brown68b909d2011-12-07 16:36:01 -08002071 }
2072
Jeff Browncf39bdf2012-05-18 14:41:19 -07002073 // Handle keyboard language switching.
2074 if (down && repeatCount == 0
2075 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2076 || (keyCode == KeyEvent.KEYCODE_SPACE
2077 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2078 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2079 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2080 return -1;
2081 }
2082 if (mLanguageSwitchKeyPressed && !down
2083 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2084 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2085 mLanguageSwitchKeyPressed = false;
2086 return -1;
2087 }
2088
Jeff Brown68b909d2011-12-07 16:36:01 -08002089 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002090 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002091 }
2092
Jeff Brown3915bb82010-11-05 15:02:16 -07002093 /** {@inheritDoc} */
2094 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002095 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002096 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002097 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002098 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2099 + ", flags=" + event.getFlags()
2100 + ", keyCode=" + event.getKeyCode()
2101 + ", scanCode=" + event.getScanCode()
2102 + ", metaState=" + event.getMetaState()
2103 + ", repeatCount=" + event.getRepeatCount()
2104 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002105 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002106
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002107 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002108 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2109 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002110 final int keyCode = event.getKeyCode();
2111 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002112 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2113 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002114
Jeff Brown54875002011-04-06 15:33:01 -07002115 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002116 final FallbackAction fallbackAction;
2117 if (initialDown) {
2118 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2119 } else {
2120 fallbackAction = mFallbackActions.get(keyCode);
2121 }
2122
2123 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002124 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002125 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2126 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002127 }
2128
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002129 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2130 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002131 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002132 event.getAction(), fallbackAction.keyCode,
2133 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002134 event.getDeviceId(), event.getScanCode(),
2135 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002136
2137 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2138 fallbackEvent.recycle();
2139 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002140 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002141
2142 if (initialDown) {
2143 mFallbackActions.put(keyCode, fallbackAction);
2144 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2145 mFallbackActions.remove(keyCode);
2146 fallbackAction.recycle();
2147 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002148 }
2149 }
2150
Jeff Brown40013652012-05-16 21:22:36 -07002151 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002152 if (fallbackEvent == null) {
2153 Slog.d(TAG, "No fallback.");
2154 } else {
2155 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2156 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002157 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002158 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002159 }
2160
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002161 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
2162 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true);
2163 if ((actions & ACTION_PASS_TO_USER) != 0) {
2164 long delayMillis = interceptKeyBeforeDispatching(
2165 win, fallbackEvent, policyFlags);
2166 if (delayMillis == 0) {
2167 return true;
2168 }
2169 }
2170 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002171 }
2172
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002173 private void launchAssistLongPressAction() {
2174 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2175 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2176
2177 // launch the search activity
2178 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2179 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2180 try {
Jim Miller45308b12012-06-18 19:23:39 -07002181 // TODO: This only stops the factory-installed search manager.
2182 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002183 SearchManager searchManager = getSearchManager();
2184 if (searchManager != null) {
2185 searchManager.stopSearch();
2186 }
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002187 mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002188 } catch (ActivityNotFoundException e) {
2189 Slog.w(TAG, "No activity to handle assist long press action.", e);
2190 }
2191 }
2192
2193 private void launchAssistAction() {
2194 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002195 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07002196 .getAssistIntent(mContext, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002197 if (intent != null) {
2198 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2199 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2200 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2201 try {
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002202 mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
Jim Miller45308b12012-06-18 19:23:39 -07002203 } catch (ActivityNotFoundException e) {
2204 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002205 }
2206 }
2207 }
2208
2209 private SearchManager getSearchManager() {
2210 if (mSearchManager == null) {
2211 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2212 }
2213 return mSearchManager;
2214 }
2215
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002216 /**
2217 * A home key -> launch home action was detected. Take the appropriate action
2218 * given the situation with the keyguard.
2219 */
2220 void launchHomeFromHotKey() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07002221 if (mKeyguardMediator != null && mKeyguardMediator.isShowingAndNotHidden()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002222 // don't launch home if keyguard showing
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002223 } else if (!mHideLockScreen && mKeyguardMediator.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002224 // when in keyguard restricted mode, must first verify unlock
2225 // before launching home
2226 mKeyguardMediator.verifyUnlock(new OnKeyguardExitResult() {
2227 public void onKeyguardExitResult(boolean success) {
2228 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002229 try {
2230 ActivityManagerNative.getDefault().stopAppSwitches();
2231 } catch (RemoteException e) {
2232 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002233 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002234 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002235 }
2236 }
2237 });
2238 } else {
2239 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002240 try {
2241 ActivityManagerNative.getDefault().stopAppSwitches();
2242 } catch (RemoteException e) {
2243 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002244 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002245 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002246 }
2247 }
2248
Dianne Hackborne26ab702011-10-16 13:21:33 -07002249 /**
2250 * A delayed callback use to determine when it is okay to re-allow applications
2251 * to use certain system UI flags. This is used to prevent applications from
2252 * spamming system UI changes that prevent the navigation bar from being shown.
2253 */
2254 final Runnable mAllowSystemUiDelay = new Runnable() {
2255 @Override public void run() {
2256 }
2257 };
2258
2259 /**
2260 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2261 * to determine when the nav bar should be shown and prevent applications from
2262 * receiving those touches.
2263 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002264 final class HideNavInputEventReceiver extends InputEventReceiver {
2265 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2266 super(inputChannel, looper);
2267 }
2268
Dianne Hackborndf89e652011-10-06 22:35:11 -07002269 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002270 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002271 boolean handled = false;
2272 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002273 if (event instanceof MotionEvent
2274 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2275 final MotionEvent motionEvent = (MotionEvent)event;
2276 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002277 // When the user taps down, we re-show the nav bar.
2278 boolean changed = false;
2279 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002280 // Any user activity always causes us to show the
2281 // navigation controls, if they had been hidden.
2282 // We also clear the low profile and only content
2283 // flags so that tapping on the screen will atomically
2284 // restore all currently hidden screen decorations.
2285 int newVal = mResettingSystemUiFlags |
2286 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2287 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2288 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002289 if (mResettingSystemUiFlags != newVal) {
2290 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002291 changed = true;
2292 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002293 // We don't allow the system's nav bar to be hidden
2294 // again for 1 second, to prevent applications from
2295 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002296 newVal = mForceClearedSystemUiFlags |
2297 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002298 if (mForceClearedSystemUiFlags != newVal) {
2299 mForceClearedSystemUiFlags = newVal;
2300 changed = true;
2301 mHandler.postDelayed(new Runnable() {
2302 @Override public void run() {
2303 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002304 // Clear flags.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002305 mForceClearedSystemUiFlags &=
2306 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2307 }
2308 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2309 }
2310 }, 1000);
2311 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002312 }
2313 if (changed) {
2314 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2315 }
2316 }
2317 }
2318 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002319 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002320 }
2321 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002322 }
2323 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2324 new InputEventReceiver.Factory() {
2325 @Override
2326 public InputEventReceiver createInputEventReceiver(
2327 InputChannel inputChannel, Looper looper) {
2328 return new HideNavInputEventReceiver(inputChannel, looper);
2329 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002330 };
2331
2332 @Override
2333 public int adjustSystemUiVisibilityLw(int visibility) {
2334 // Reset any bits in mForceClearingStatusBarVisibility that
2335 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002336 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002337 // Clear any bits in the new visibility that are currently being
2338 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002339 return visibility & ~mResettingSystemUiFlags
2340 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002341 }
2342
Craig Mautner69b08182012-09-05 13:07:13 -07002343 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002344 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
2345 final int fl = attrs.flags;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002346 final int systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002347
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002348 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002349 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002350 int availRight, availBottom;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002351 if (mCanHideNavigationBar &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002352 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002353 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2354 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2355 } else {
2356 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2357 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2358 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002359 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2360 if ((fl & FLAG_FULLSCREEN) != 0) {
2361 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2362 availRight - mStableFullscreenRight,
2363 availBottom - mStableFullscreenBottom);
2364 } else {
2365 contentInset.set(mStableLeft, mStableTop,
2366 availRight - mStableRight, availBottom - mStableBottom);
2367 }
2368 } else if ((fl & FLAG_FULLSCREEN) != 0) {
2369 contentInset.setEmpty();
2370 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002371 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2372 contentInset.set(mCurLeft, mCurTop,
2373 availRight - mCurRight, availBottom - mCurBottom);
2374 } else {
2375 contentInset.set(mCurLeft, mCurTop,
2376 availRight - mCurRight, availBottom - mCurBottom);
2377 }
2378 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002379 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002380 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002381 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002382
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002383 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002384 @Override
2385 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2386 int displayRotation) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08002387 mUnrestrictedScreenLeft = mUnrestrictedScreenTop = 0;
2388 mUnrestrictedScreenWidth = displayWidth;
2389 mUnrestrictedScreenHeight = displayHeight;
2390 mRestrictedScreenLeft = mRestrictedScreenTop = 0;
2391 mRestrictedScreenWidth = displayWidth;
2392 mRestrictedScreenHeight = displayHeight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002393 mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft
2394 = mSystemLeft = mCurLeft = 0;
2395 mDockTop = mContentTop = mStableTop = mStableFullscreenTop
2396 = mSystemTop = mCurTop = 0;
2397 mDockRight = mContentRight = mStableRight = mStableFullscreenRight
2398 = mSystemRight = mCurRight = displayWidth;
2399 mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom
2400 = mSystemBottom = mCurBottom = displayHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002401 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002402 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002403
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002404 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2405 final Rect pf = mTmpParentFrame;
2406 final Rect df = mTmpDisplayFrame;
2407 final Rect vf = mTmpVisibleFrame;
2408 pf.left = df.left = vf.left = mDockLeft;
2409 pf.top = df.top = vf.top = mDockTop;
2410 pf.right = df.right = vf.right = mDockRight;
2411 pf.bottom = df.bottom = vf.bottom = mDockBottom;
2412
Craig Mautner69b08182012-09-05 13:07:13 -07002413 if (isDefaultDisplay) {
2414 // For purposes of putting out fake window up to steal focus, we will
2415 // drive nav being hidden only by whether it is requested.
2416 boolean navVisible = (mLastSystemUiFlags&View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002417
Craig Mautner69b08182012-09-05 13:07:13 -07002418 // When the navigation bar isn't visible, we put up a fake
2419 // input window to catch all touch events. This way we can
2420 // detect when the user presses anywhere to bring back the nav
2421 // bar and ensure the application doesn't see the event.
2422 if (navVisible) {
2423 if (mHideNavFakeWindow != null) {
2424 mHideNavFakeWindow.dismiss();
2425 mHideNavFakeWindow = null;
2426 }
2427 } else if (mHideNavFakeWindow == null) {
2428 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2429 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
2430 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER,
2431 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002432 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002433
Craig Mautner69b08182012-09-05 13:07:13 -07002434 // For purposes of positioning and showing the nav bar, if we have
2435 // decided that it can't be hidden (because of the screen aspect ratio),
2436 // then take that into account.
2437 navVisible |= !mCanHideNavigationBar;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002438
Craig Mautner69b08182012-09-05 13:07:13 -07002439 if (mNavigationBar != null) {
2440 // Force the navigation bar to its appropriate place and
2441 // size. We need to do this directly, instead of relying on
2442 // it to bubble up from the nav bar, because this needs to
2443 // change atomically with screen rotations.
2444 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2445 if (mNavigationBarOnBottom) {
2446 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
2447 int top = displayHeight - mNavigationBarHeightForRotation[displayRotation];
2448 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight);
2449 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
2450 if (navVisible) {
2451 mNavigationBar.showLw(true);
2452 mDockBottom = mTmpNavigationFrame.top;
2453 mRestrictedScreenHeight = mDockBottom - mDockTop;
2454 } else {
2455 // We currently want to hide the navigation UI.
2456 mNavigationBar.hideLw(true);
2457 }
2458 if (navVisible && !mNavigationBar.isAnimatingLw()) {
2459 // If the nav bar is currently requested to be visible,
2460 // and not in the process of animating on or off, then
2461 // we can tell the app that it is covered by it.
2462 mSystemBottom = mTmpNavigationFrame.top;
2463 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002464 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002465 // Landscape screen; nav bar goes to the right.
2466 int left = displayWidth - mNavigationBarWidthForRotation[displayRotation];
2467 mTmpNavigationFrame.set(left, 0, displayWidth, displayHeight);
2468 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
2469 if (navVisible) {
2470 mNavigationBar.showLw(true);
2471 mDockRight = mTmpNavigationFrame.left;
2472 mRestrictedScreenWidth = mDockRight - mDockLeft;
2473 } else {
2474 // We currently want to hide the navigation UI.
2475 mNavigationBar.hideLw(true);
2476 }
2477 if (navVisible && !mNavigationBar.isAnimatingLw()) {
2478 // If the nav bar is currently requested to be visible,
2479 // and not in the process of animating on or off, then
2480 // we can tell the app that it is covered by it.
2481 mSystemRight = mTmpNavigationFrame.left;
2482 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002483 }
Craig Mautner69b08182012-09-05 13:07:13 -07002484 // Make sure the content and current rectangles are updated to
2485 // account for the restrictions from the navigation bar.
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002486 mContentTop = mCurTop = mDockTop;
2487 mContentBottom = mCurBottom = mDockBottom;
2488 mContentLeft = mCurLeft = mDockLeft;
2489 mContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002490 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2491 // And compute the final frame.
2492 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
2493 mTmpNavigationFrame, mTmpNavigationFrame);
2494 if (DEBUG_LAYOUT) Log.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002495 }
Craig Mautner69b08182012-09-05 13:07:13 -07002496 if (DEBUG_LAYOUT) Log.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
2497 mDockLeft, mDockTop, mDockRight, mDockBottom));
2498
2499 // decide where the status bar goes ahead of time
2500 if (mStatusBar != null) {
2501 // apply any navigation bar insets
2502 pf.left = df.left = mUnrestrictedScreenLeft;
2503 pf.top = df.top = mUnrestrictedScreenTop;
2504 pf.right = df.right = mUnrestrictedScreenWidth - mUnrestrictedScreenLeft;
2505 pf.bottom = df.bottom = mUnrestrictedScreenHeight - mUnrestrictedScreenTop;
2506 vf.left = mStableLeft;
2507 vf.top = mStableTop;
2508 vf.right = mStableRight;
2509 vf.bottom = mStableBottom;
2510
2511 mStatusBarLayer = mStatusBar.getSurfaceLayer();
2512
2513 // Let the status bar determine its size.
2514 mStatusBar.computeFrameLw(pf, df, vf, vf);
2515
2516 // For layout, the status bar is always at the top with our fixed height.
2517 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
2518
2519 // If the status bar is hidden, we don't want to cause
2520 // windows behind it to scroll.
2521 if (mStatusBar.isVisibleLw()) {
2522 // Status bar may go away, so the screen area it occupies
2523 // is available to apps but just covering them when the
2524 // status bar is visible.
2525 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
2526
2527 mContentTop = mCurTop = mDockTop;
2528 mContentBottom = mCurBottom = mDockBottom;
2529 mContentLeft = mCurLeft = mDockLeft;
2530 mContentRight = mCurRight = mDockRight;
2531
2532 if (DEBUG_LAYOUT) Log.v(TAG, "Status bar: " +
2533 String.format(
2534 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
2535 mDockLeft, mDockTop, mDockRight, mDockBottom,
2536 mContentLeft, mContentTop, mContentRight, mContentBottom,
2537 mCurLeft, mCurTop, mCurRight, mCurBottom));
2538 }
2539 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()) {
2540 // If the status bar is currently requested to be visible,
2541 // and not in the process of animating on or off, then
2542 // we can tell the app that it is covered by it.
2543 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
2544 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002545 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002546 }
2547 }
2548
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002549 /** {@inheritDoc} */
2550 public int getSystemDecorRectLw(Rect systemRect) {
2551 systemRect.left = mSystemLeft;
2552 systemRect.top = mSystemTop;
2553 systemRect.right = mSystemRight;
2554 systemRect.bottom = mSystemBottom;
2555 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
2556 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
2557 return 0;
2558 }
2559
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002560 void setAttachedWindowFrames(WindowState win, int fl, int adjust,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002561 WindowState attached, boolean insetDecors, Rect pf, Rect df, Rect cf, Rect vf) {
2562 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
2563 // Here's a special case: if this attached window is a panel that is
2564 // above the dock window, and the window it is attached to is below
2565 // the dock window, then the frames we computed for the window it is
2566 // attached to can not be used because the dock is effectively part
2567 // of the underlying window and the attached window is floating on top
2568 // of the whole thing. So, we ignore the attached window and explicitly
2569 // compute the frames that would be appropriate without the dock.
2570 df.left = cf.left = vf.left = mDockLeft;
2571 df.top = cf.top = vf.top = mDockTop;
2572 df.right = cf.right = vf.right = mDockRight;
2573 df.bottom = cf.bottom = vf.bottom = mDockBottom;
2574 } else {
2575 // The effective display frame of the attached window depends on
2576 // whether it is taking care of insetting its content. If not,
2577 // we need to use the parent's content frame so that the entire
2578 // window is positioned within that content. Otherwise we can use
2579 // the display frame and let the attached window take care of
2580 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002581 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002582 cf.set(attached.getDisplayFrameLw());
2583 } else {
2584 // If the window is resizing, then we want to base the content
2585 // frame on our attached content frame to resize... however,
2586 // things can be tricky if the attached window is NOT in resize
2587 // mode, in which case its content frame will be larger.
2588 // Ungh. So to deal with that, make sure the content frame
2589 // we end up using is not covering the IM dock.
2590 cf.set(attached.getContentFrameLw());
2591 if (attached.getSurfaceLayer() < mDockLayer) {
2592 if (cf.left < mContentLeft) cf.left = mContentLeft;
2593 if (cf.top < mContentTop) cf.top = mContentTop;
2594 if (cf.right > mContentRight) cf.right = mContentRight;
2595 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
2596 }
2597 }
2598 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
2599 vf.set(attached.getVisibleFrameLw());
2600 }
2601 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
2602 // window should be positioned relative to its parent or the entire
2603 // screen.
2604 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
2605 ? attached.getFrameLw() : df);
2606 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002607
2608 private void applyStableConstraints(int sysui, int fl, Rect r) {
2609 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2610 // If app is requesting a stable layout, don't let the
2611 // content insets go below the stable values.
2612 if ((fl & FLAG_FULLSCREEN) != 0) {
2613 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
2614 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
2615 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
2616 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
2617 } else {
2618 if (r.left < mStableLeft) r.left = mStableLeft;
2619 if (r.top < mStableTop) r.top = mStableTop;
2620 if (r.right > mStableRight) r.right = mStableRight;
2621 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
2622 }
2623 }
2624 }
2625
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002626 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002627 @Override
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07002628 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
2629 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002630 // we've already done the status bar
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002631 if (win == mStatusBar || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002632 return;
2633 }
Craig Mautner69b08182012-09-05 13:07:13 -07002634 final boolean isDefaultDisplay = win.isDefaultDisplay();
2635 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09002636 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
2637 if (needsToOffsetInputMethodTarget) {
2638 if (DEBUG_LAYOUT) {
2639 Slog.i(TAG, "Offset ime target window by the last ime window state");
2640 }
2641 offsetInputMethodWindowLw(mLastInputMethodWindow);
2642 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002643
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002644 final int fl = attrs.flags;
2645 final int sim = attrs.softInputMode;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002646 final int sysUiFl = win.getSystemUiVisibility();
2647
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002648 final Rect pf = mTmpParentFrame;
2649 final Rect df = mTmpDisplayFrame;
2650 final Rect cf = mTmpContentFrame;
2651 final Rect vf = mTmpVisibleFrame;
Craig Mautner69b08182012-09-05 13:07:13 -07002652
2653 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04002654 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002655
Craig Mautnerf683b562012-10-02 11:10:57 -07002656 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
2657
Craig Mautner69b08182012-09-05 13:07:13 -07002658 if (!isDefaultDisplay) {
2659 if (attached != null) {
2660 // If this window is attached to another, our display
2661 // frame is the same as the one we are attached to.
Craig Mautnerf683b562012-10-02 11:10:57 -07002662 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002663 } else {
2664 // Give the window full screen.
2665 pf.left = df.left = cf.left = mUnrestrictedScreenLeft;
2666 pf.top = df.top = cf.top = mUnrestrictedScreenTop;
2667 pf.right = df.right = cf.right
2668 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2669 pf.bottom = df.bottom = cf.bottom
2670 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2671 }
2672 } else if (attrs.type == TYPE_INPUT_METHOD) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002673 pf.left = df.left = cf.left = vf.left = mDockLeft;
2674 pf.top = df.top = cf.top = vf.top = mDockTop;
2675 pf.right = df.right = cf.right = vf.right = mDockRight;
2676 pf.bottom = df.bottom = cf.bottom = vf.bottom = mDockBottom;
2677 // IM dock windows always go to the bottom of the screen.
2678 attrs.gravity = Gravity.BOTTOM;
2679 mDockLayer = win.getSurfaceLayer();
2680 } else {
Dianne Hackborn82de1ae2010-10-28 11:28:39 -07002681 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_FULLSCREEN | FLAG_LAYOUT_INSET_DECOR))
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002682 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)
2683 && (sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002684 if (DEBUG_LAYOUT)
2685 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle()
2686 + "): IN_SCREEN, INSET_DECOR, !FULLSCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002687 // This is the case for a normal activity window: we want it
2688 // to cover all of the screen space, and it can take care of
2689 // moving its contents to account for screen decorations that
2690 // intrude into that space.
2691 if (attached != null) {
2692 // If this window is attached to another, our display
2693 // frame is the same as the one we are attached to.
Craig Mautnerf683b562012-10-02 11:10:57 -07002694 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002695 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002696 if (attrs.type == TYPE_STATUS_BAR_PANEL
2697 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08002698 // Status bar panels are the only windows who can go on top of
2699 // the status bar. They are protected by the STATUS_BAR_SERVICE
2700 // permission, so they have the same privileges as the status
2701 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002702 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002703 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002704
2705 pf.left = df.left = hasNavBar ? mDockLeft : mUnrestrictedScreenLeft;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002706 pf.top = df.top = mUnrestrictedScreenTop;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002707 pf.right = df.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002708 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002709 : mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2710 pf.bottom = df.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002711 ? mRestrictedScreenTop+mRestrictedScreenHeight
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002712 : mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
2713
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002714 if (DEBUG_LAYOUT) {
2715 Log.v(TAG, String.format(
2716 "Laying out status bar window: (%d,%d - %d,%d)",
2717 pf.left, pf.top, pf.right, pf.bottom));
2718 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002719 } else if (mCanHideNavigationBar
2720 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002721 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
2722 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
2723 // Asking for layout as if the nav bar is hidden, lets the
2724 // application extend into the unrestricted screen area. We
2725 // only do this for application windows to ensure no window that
2726 // can be above the nav bar can do this.
2727 pf.left = df.left = mUnrestrictedScreenLeft;
2728 pf.top = df.top = mUnrestrictedScreenTop;
2729 pf.right = df.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2730 pf.bottom = df.bottom = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002731 } else {
2732 pf.left = df.left = mRestrictedScreenLeft;
2733 pf.top = df.top = mRestrictedScreenTop;
2734 pf.right = df.right = mRestrictedScreenLeft+mRestrictedScreenWidth;
2735 pf.bottom = df.bottom = mRestrictedScreenTop+mRestrictedScreenHeight;
2736 }
Craig Mautner69b08182012-09-05 13:07:13 -07002737
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002738 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002739 cf.left = mDockLeft;
2740 cf.top = mDockTop;
2741 cf.right = mDockRight;
2742 cf.bottom = mDockBottom;
2743 } else {
2744 cf.left = mContentLeft;
2745 cf.top = mContentTop;
2746 cf.right = mContentRight;
2747 cf.bottom = mContentBottom;
2748 }
Craig Mautner69b08182012-09-05 13:07:13 -07002749
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002750 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002751 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
2752 vf.left = mCurLeft;
2753 vf.top = mCurTop;
2754 vf.right = mCurRight;
2755 vf.bottom = mCurBottom;
2756 } else {
2757 vf.set(cf);
2758 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002759 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002760 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
2761 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
2762 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002763 if (DEBUG_LAYOUT)
2764 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002765 // A window that has requested to fill the entire screen just
2766 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002767 if (attrs.type == TYPE_STATUS_BAR_PANEL
2768 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
2769 pf.left = df.left = cf.left = hasNavBar ? mDockLeft : mUnrestrictedScreenLeft;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002770 pf.top = df.top = cf.top = mUnrestrictedScreenTop;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002771 pf.right = df.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002772 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002773 : mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2774 pf.bottom = df.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002775 ? mRestrictedScreenTop+mRestrictedScreenHeight
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002776 : mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Daniel Sandler36412a72011-08-04 09:35:13 -04002777 if (DEBUG_LAYOUT) {
2778 Log.v(TAG, String.format(
2779 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
2780 pf.left, pf.top, pf.right, pf.bottom));
2781 }
Jim Millere898ac52012-04-06 17:10:57 -07002782 } else if (attrs.type == TYPE_NAVIGATION_BAR
2783 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002784 // The navigation bar has Real Ultimate Power.
2785 pf.left = df.left = mUnrestrictedScreenLeft;
2786 pf.top = df.top = mUnrestrictedScreenTop;
2787 pf.right = df.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2788 pf.bottom = df.bottom = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
2789 if (DEBUG_LAYOUT) {
2790 Log.v(TAG, String.format(
2791 "Laying out navigation bar window: (%d,%d - %d,%d)",
2792 pf.left, pf.top, pf.right, pf.bottom));
2793 }
Dianne Hackborn01011c32012-02-21 13:54:21 -08002794 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
2795 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002796 && ((fl & FLAG_FULLSCREEN) != 0)) {
2797 // Fullscreen secure system overlays get what they ask for.
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;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002802 } else if (attrs.type == TYPE_BOOT_PROGRESS
2803 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08002804 // Boot progress screen always covers entire display.
2805 pf.left = df.left = cf.left = mUnrestrictedScreenLeft;
2806 pf.top = df.top = cf.top = mUnrestrictedScreenTop;
2807 pf.right = df.right = cf.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2808 pf.bottom = df.bottom = cf.bottom
2809 = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002810 } else if (mCanHideNavigationBar
2811 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002812 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
2813 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
2814 // Asking for layout as if the nav bar is hidden, lets the
2815 // application extend into the unrestricted screen area. We
2816 // only do this for application windows to ensure no window that
2817 // can be above the nav bar can do this.
2818 // XXX This assumes that an app asking for this will also
2819 // ask for layout in only content. We can't currently figure out
2820 // what the screen would be if only laying out to hide the nav bar.
2821 pf.left = df.left = cf.left = mUnrestrictedScreenLeft;
2822 pf.top = df.top = cf.top = mUnrestrictedScreenTop;
2823 pf.right = df.right = cf.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2824 pf.bottom = df.bottom = cf.bottom
2825 = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002826 } else {
2827 pf.left = df.left = cf.left = mRestrictedScreenLeft;
2828 pf.top = df.top = cf.top = mRestrictedScreenTop;
2829 pf.right = df.right = cf.right = mRestrictedScreenLeft+mRestrictedScreenWidth;
2830 pf.bottom = df.bottom = cf.bottom
2831 = mRestrictedScreenTop+mRestrictedScreenHeight;
2832 }
Craig Mautner69b08182012-09-05 13:07:13 -07002833
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002834 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07002835
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002836 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
2837 vf.left = mCurLeft;
2838 vf.top = mCurTop;
2839 vf.right = mCurRight;
2840 vf.bottom = mCurBottom;
2841 } else {
2842 vf.set(cf);
2843 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002844 } else if (attached != null) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002845 if (DEBUG_LAYOUT)
2846 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002847 // A child window should be placed inside of the same visible
2848 // frame that its parent had.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002849 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002850 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002851 if (DEBUG_LAYOUT)
2852 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002853 // Otherwise, a normal window must be placed inside the content
2854 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07002855 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
2856 // Status bar panels are the only windows who can go on top of
2857 // the status bar. They are protected by the STATUS_BAR_SERVICE
2858 // permission, so they have the same privileges as the status
2859 // bar itself.
Dianne Hackborn7d049322011-06-14 15:00:32 -07002860 pf.left = df.left = cf.left = mRestrictedScreenLeft;
2861 pf.top = df.top = cf.top = mRestrictedScreenTop;
2862 pf.right = df.right = cf.right = mRestrictedScreenLeft+mRestrictedScreenWidth;
2863 pf.bottom = df.bottom = cf.bottom
2864 = mRestrictedScreenTop+mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002865 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07002866 pf.left = mContentLeft;
2867 pf.top = mContentTop;
2868 pf.right = mContentRight;
2869 pf.bottom = mContentBottom;
2870 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
2871 df.left = cf.left = mDockLeft;
2872 df.top = cf.top = mDockTop;
2873 df.right = cf.right = mDockRight;
2874 df.bottom = cf.bottom = mDockBottom;
2875 } else {
2876 df.left = cf.left = mContentLeft;
2877 df.top = cf.top = mContentTop;
2878 df.right = cf.right = mContentRight;
2879 df.bottom = cf.bottom = mContentBottom;
2880 }
2881 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
2882 vf.left = mCurLeft;
2883 vf.top = mCurTop;
2884 vf.right = mCurRight;
2885 vf.bottom = mCurBottom;
2886 } else {
2887 vf.set(cf);
2888 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002889 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002890 }
2891 }
Craig Mautner69b08182012-09-05 13:07:13 -07002892
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002893 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0) {
2894 df.left = df.top = cf.left = cf.top = vf.left = vf.top = -10000;
2895 df.right = df.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
2896 }
2897
The Android Open Source Project11267662009-03-18 17:39:47 -07002898 if (DEBUG_LAYOUT) Log.v(TAG, "Compute frame " + attrs.getTitle()
2899 + ": sim=#" + Integer.toHexString(sim)
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002900 + " attach=" + attached + " type=" + attrs.type
2901 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07002902 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
2903 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07002904
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002905 win.computeFrameLw(pf, df, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002906
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002907 // Dock windows carve out the bottom of the screen, so normal windows
2908 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07002909 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
2910 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09002911 setLastInputMethodWindowLw(null, null);
2912 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002913 }
2914 }
2915
satok1bc0a492012-04-25 22:47:12 +09002916 private void offsetInputMethodWindowLw(WindowState win) {
2917 int top = win.getContentFrameLw().top;
2918 top += win.getGivenContentInsetsLw().top;
2919 if (mContentBottom > top) {
2920 mContentBottom = top;
2921 }
2922 top = win.getVisibleFrameLw().top;
2923 top += win.getGivenVisibleInsetsLw().top;
2924 if (mCurBottom > top) {
2925 mCurBottom = top;
2926 }
2927 if (DEBUG_LAYOUT) Log.v(TAG, "Input method: mDockBottom="
2928 + mDockBottom + " mContentBottom="
2929 + mContentBottom + " mCurBottom=" + mCurBottom);
2930 }
2931
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002932 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08002933 @Override
2934 public void finishLayoutLw() {
2935 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002936 }
2937
2938 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07002939 @Override
Craig Mautner39834192012-09-02 07:47:24 -07002940 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002941 mTopFullscreenOpaqueWindowState = null;
2942 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002943 mForceStatusBarFromKeyguard = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002944
2945 mHideLockScreen = false;
2946 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07002947 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002948 mShowingLockscreen = false;
2949 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002950 }
2951
2952 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07002953 @Override
Craig Mautner39834192012-09-02 07:47:24 -07002954 public void applyPostLayoutPolicyLw(WindowState win,
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002955 WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07002956 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
2957 + win.isVisibleOrBehindKeyguardLw());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002958 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08002959 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002960 if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002961 if (attrs.type == TYPE_KEYGUARD) {
2962 mForceStatusBarFromKeyguard = true;
2963 } else {
2964 mForceStatusBar = true;
2965 }
2966 }
2967 if (attrs.type == TYPE_KEYGUARD) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002968 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07002969 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002970 boolean applyWindow = attrs.type >= FIRST_APPLICATION_WINDOW
2971 && attrs.type <= LAST_APPLICATION_WINDOW;
2972 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07002973 // If the lockscreen was showing when the dream started then wait
2974 // for the dream to draw before hiding the lockscreen.
2975 if (!mDreamingLockscreen
2976 || (win.isVisibleLw() && win.hasDrawnLw())) {
2977 mShowingDream = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002978 applyWindow = true;
2979 }
2980 }
2981 if (applyWindow
Dianne Hackborn6493e642010-10-01 13:06:30 -07002982 && attrs.x == 0 && attrs.y == 0
2983 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
2984 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002985 if (DEBUG_LAYOUT) Log.v(TAG, "Fullscreen window: " + win);
2986 mTopFullscreenOpaqueWindowState = win;
2987 if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002988 if (DEBUG_LAYOUT) Log.v(TAG, "Setting mHideLockScreen to true by win " + win);
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002989 mHideLockScreen = true;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002990 mForceStatusBarFromKeyguard = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002991 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07002992 if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0
2993 && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002994 if (DEBUG_LAYOUT) Log.v(TAG, "Setting mDismissKeyguard to true by win " + win);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07002995 mDismissKeyguard = mWinDismissingKeyguard == win ?
2996 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
2997 mWinDismissingKeyguard = win;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002998 mForceStatusBarFromKeyguard = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002999 }
3000 if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
3001 mAllowLockscreenWhenOn = true;
3002 }
3003 }
3004 }
3005 }
3006
3007 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003008 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003009 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003010 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003011 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003012
3013 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3014 ? mTopFullscreenOpaqueWindowState.getAttrs()
3015 : null;
3016
Jeff Brownc8018eb2012-10-29 21:33:27 -07003017 // If we are not currently showing a dream then remember the current
3018 // lockscreen state. We will use this to determine whether the dream
3019 // started while the lockscreen was showing and remember this state
3020 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003021 if (!mShowingDream) {
3022 mDreamingLockscreen = mShowingLockscreen;
3023 }
3024
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003025 if (mStatusBar != null) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003026 if (DEBUG_LAYOUT) Log.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003027 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003028 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003029 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003030 if (DEBUG_LAYOUT) Log.v(TAG, "Showing status bar: forced");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003031 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003032 } else if (mTopFullscreenOpaqueWindowState != null) {
Joe Onorato93056472010-09-10 10:30:46 -04003033 if (localLOGV) {
3034 Log.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
3035 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
3036 Log.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
3037 + " lp.flags=0x" + Integer.toHexString(lp.flags));
3038 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003039 topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
3040 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003041 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3042 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3043 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3044 // case though.
3045 if (topIsFullscreen) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003046 if (DEBUG_LAYOUT) Log.v(TAG, "** HIDING status bar");
3047 if (mStatusBar.hideLw(true)) {
3048 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Daniel Sandler9c00d5b2011-09-13 14:04:26 -04003049
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003050 mHandler.post(new Runnable() {
3051 @Override
3052 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07003053 try {
3054 IStatusBarService statusbar = getStatusBarService();
3055 if (statusbar != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -04003056 statusbar.collapsePanels();
Dianne Hackborn42e620c2012-06-24 13:20:51 -07003057 }
3058 } catch (RemoteException ex) {
3059 // re-acquire status bar service next time it is needed.
3060 mStatusBarService = null;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003061 }
3062 }});
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003063 } else if (DEBUG_LAYOUT) {
Daniel Sandler40427442010-07-16 11:44:52 -04003064 Log.v(TAG, "Preventing status bar from hiding by policy");
3065 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003066 } else {
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003067 if (DEBUG_LAYOUT) Log.v(TAG, "** SHOWING status bar: top is not fullscreen");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003068 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003069 }
3070 }
3071 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003072
Joe Onorato644f9c32011-01-25 12:06:23 -08003073 mTopIsFullscreen = topIsFullscreen;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003074
Craig Mautner39834192012-09-02 07:47:24 -07003075 // Hide the key guard if a visible window explicitly specifies that it wants to be
3076 // displayed when the screen is locked.
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003077 if (mKeyguard != null) {
Craig Mautner39834192012-09-02 07:47:24 -07003078 if (localLOGV) Log.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3079 + mHideLockScreen);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003080 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardMediator.isSecure()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003081 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003082 changes |= FINISH_LAYOUT_REDO_LAYOUT
3083 | FINISH_LAYOUT_REDO_CONFIG
3084 | FINISH_LAYOUT_REDO_WALLPAPER;
3085 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003086 if (mKeyguardMediator.isShowing()) {
Dianne Hackbornb446e972009-09-20 15:23:25 -07003087 mHandler.post(new Runnable() {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003088 @Override
Dianne Hackbornb446e972009-09-20 15:23:25 -07003089 public void run() {
Dianne Hackborn05726582009-09-22 17:28:24 -07003090 mKeyguardMediator.keyguardDone(false, false);
Dianne Hackbornb446e972009-09-20 15:23:25 -07003091 }
3092 });
3093 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003094 } else if (mHideLockScreen) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003095 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003096 changes |= FINISH_LAYOUT_REDO_LAYOUT
3097 | FINISH_LAYOUT_REDO_CONFIG
3098 | FINISH_LAYOUT_REDO_WALLPAPER;
3099 }
Mike Lockwoodf3bfed52010-01-21 16:38:44 -05003100 mKeyguardMediator.setHidden(true);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003101 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3102 // This is the case of keyguard isSecure() and not mHideLockScreen.
3103 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3104 // Only launch the next keyguard unlock window once per window.
3105 if (mKeyguard.showLw(true)) {
3106 changes |= FINISH_LAYOUT_REDO_LAYOUT
3107 | FINISH_LAYOUT_REDO_CONFIG
3108 | FINISH_LAYOUT_REDO_WALLPAPER;
3109 }
3110 mKeyguardMediator.setHidden(false);
3111 mHandler.post(new Runnable() {
3112 @Override
3113 public void run() {
3114 mKeyguardMediator.dismiss();
3115 }
3116 });
3117 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003118 } else {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003119 mWinDismissingKeyguard = null;
Dianne Hackborn08743722009-12-21 12:16:51 -08003120 if (mKeyguard.showLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003121 changes |= FINISH_LAYOUT_REDO_LAYOUT
3122 | FINISH_LAYOUT_REDO_CONFIG
3123 | FINISH_LAYOUT_REDO_WALLPAPER;
3124 }
Mike Lockwoodf3bfed52010-01-21 16:38:44 -05003125 mKeyguardMediator.setHidden(false);
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003126 }
3127 }
Joe Onorato664644d2011-01-23 17:53:23 -08003128
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003129 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003130 // If the navigation bar has been hidden or shown, we need to do another
3131 // layout pass to update that window.
3132 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3133 }
Joe Onorato664644d2011-01-23 17:53:23 -08003134
Mike Lockwood28569302010-01-28 11:54:40 -05003135 // update since mAllowLockscreenWhenOn might have changed
3136 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003137 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003138 }
3139
Dianne Hackborn08743722009-12-21 12:16:51 -08003140 public boolean allowAppAnimationsLw() {
Craig Mautnerf03e4c52012-06-14 14:11:27 -07003141 if (mKeyguard != null && mKeyguard.isVisibleLw() && !mKeyguard.isAnimatingLw()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003142 // If keyguard is currently visible, no reason to animate
3143 // behind it.
3144 return false;
3145 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003146 return true;
3147 }
3148
Dianne Hackborndf89e652011-10-06 22:35:11 -07003149 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003150 mFocusedWindow = newFocus;
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 return FINISH_LAYOUT_REDO_LAYOUT;
3155 }
3156 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003157 }
3158
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003159 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07003160 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003161 // do nothing if headless
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003162 if (mHeadless) return;
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003163
Jeff Brown46b9ac02010-04-22 18:58:52 -07003164 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003165 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3166 if (newLidState == mLidState) {
3167 return;
3168 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003169
Jeff Brownc458ce92012-04-30 14:58:40 -07003170 mLidState = newLidState;
3171 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003172 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003173
3174 if (lidOpen) {
3175 if (keyguardIsShowingTq()) {
Jeff Brown1c2e4942012-11-06 16:32:01 -08003176 mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(KeyEvent.KEYCODE_POWER);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003177 } else {
Jeff Brown96307042012-07-27 15:51:34 -07003178 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brown46b9ac02010-04-22 18:58:52 -07003179 }
Jeff Brownc458ce92012-04-30 14:58:40 -07003180 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003181 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003182 }
3183 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003184
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003185 void setHdmiPlugged(boolean plugged) {
3186 if (mHdmiPlugged != plugged) {
3187 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003188 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003189 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003190 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003191 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003192 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003193 }
3194 }
3195
Joe Onoratoea495d42011-04-06 11:41:11 -07003196 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003197 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003198 // watch for HDMI plug messages if the hdmi switch exists
3199 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3200 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3201
Joe Onoratoea495d42011-04-06 11:41:11 -07003202 final String filename = "/sys/class/switch/hdmi/state";
3203 FileReader reader = null;
3204 try {
3205 reader = new FileReader(filename);
3206 char[] buf = new char[15];
3207 int n = reader.read(buf);
3208 if (n > 1) {
3209 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3210 }
3211 } catch (IOException ex) {
3212 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3213 } catch (NumberFormatException ex) {
3214 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3215 } finally {
3216 if (reader != null) {
3217 try {
3218 reader.close();
3219 } catch (IOException ex) {
3220 }
Joe Onoratodc100302011-01-11 17:07:41 -08003221 }
3222 }
3223 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07003224 // This dance forces the code in setHdmiPlugged to run.
3225 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
3226 mHdmiPlugged = !plugged;
3227 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08003228 }
3229
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003230 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003231 * @return Whether music is being played right now.
3232 */
3233 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07003234 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
3235 if (am == null) {
3236 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003237 return false;
3238 }
Eric Laurent413cb9d2009-07-17 11:52:43 -07003239 return am.isMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003240 }
3241
3242 /**
3243 * Tell the audio service to adjust the volume appropriate to the event.
3244 * @param keycode
3245 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04003246 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07003247 IAudioService audioService = getAudioService();
3248 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003249 return;
3250 }
3251 try {
3252 // since audio is playing, we shouldn't have to hold a wake lock
3253 // during the call, but we do it as a precaution for the rare possibility
3254 // that the music stops right before we call this
Jeff Brownb0418da2010-11-01 15:24:01 -07003255 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003256 mBroadcastWakeLock.acquire();
Jeff Brown4d396052010-10-29 21:50:21 -07003257 audioService.adjustStreamVolume(stream,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003258 keycode == KeyEvent.KEYCODE_VOLUME_UP
3259 ? AudioManager.ADJUST_RAISE
3260 : AudioManager.ADJUST_LOWER,
3261 0);
3262 } catch (RemoteException e) {
3263 Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e);
3264 } finally {
3265 mBroadcastWakeLock.release();
3266 }
3267 }
Jeff Brown4d396052010-10-29 21:50:21 -07003268
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07003269 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003270 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003271
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003272 final Runnable mScreenshotTimeout = new Runnable() {
3273 @Override public void run() {
3274 synchronized (mScreenshotLock) {
3275 if (mScreenshotConnection != null) {
3276 mContext.unbindService(mScreenshotConnection);
3277 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003278 }
Winson Chung9112ec32011-06-27 13:15:32 -07003279 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003280 }
3281 };
3282
3283 // Assume this is called from the Handler thread.
3284 private void takeScreenshot() {
3285 synchronized (mScreenshotLock) {
3286 if (mScreenshotConnection != null) {
3287 return;
3288 }
3289 ComponentName cn = new ComponentName("com.android.systemui",
3290 "com.android.systemui.screenshot.TakeScreenshotService");
3291 Intent intent = new Intent();
3292 intent.setComponent(cn);
3293 ServiceConnection conn = new ServiceConnection() {
3294 @Override
3295 public void onServiceConnected(ComponentName name, IBinder service) {
3296 synchronized (mScreenshotLock) {
3297 if (mScreenshotConnection != this) {
3298 return;
3299 }
3300 Messenger messenger = new Messenger(service);
3301 Message msg = Message.obtain(null, 1);
3302 final ServiceConnection myConn = this;
3303 Handler h = new Handler(mHandler.getLooper()) {
3304 @Override
3305 public void handleMessage(Message msg) {
3306 synchronized (mScreenshotLock) {
3307 if (mScreenshotConnection == myConn) {
3308 mContext.unbindService(mScreenshotConnection);
3309 mScreenshotConnection = null;
3310 mHandler.removeCallbacks(mScreenshotTimeout);
3311 }
3312 }
3313 }
3314 };
3315 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07003316 msg.arg1 = msg.arg2 = 0;
3317 if (mStatusBar != null && mStatusBar.isVisibleLw())
3318 msg.arg1 = 1;
3319 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
3320 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003321 try {
3322 messenger.send(msg);
3323 } catch (RemoteException e) {
3324 }
3325 }
3326 }
3327 @Override
3328 public void onServiceDisconnected(ComponentName name) {}
3329 };
Jeff Sharkey35744c12012-08-28 16:48:05 -07003330 if (mContext.bindService(
3331 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.USER_CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003332 mScreenshotConnection = conn;
3333 mHandler.postDelayed(mScreenshotTimeout, 10000);
3334 }
3335 }
Winson Chung9112ec32011-06-27 13:15:32 -07003336 }
3337
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003338 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003339 @Override
Jeff Brown1f245102010-11-18 20:53:46 -08003340 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
Jeff Brown96307042012-07-27 15:51:34 -07003341 if (!mSystemBooted) {
3342 // If we have not yet booted, don't let key events do anything.
3343 return 0;
3344 }
3345
Jeff Brown1f245102010-11-18 20:53:46 -08003346 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3347 final boolean canceled = event.isCanceled();
3348 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07003349
Jeff Brown3122e442010-10-11 23:32:49 -07003350 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07003351
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05003352 // If screen is off then we treat the case where the keyguard is open but hidden
3353 // the same as if it were open and in front.
3354 // This will prevent any keys other than the power button from waking the screen
3355 // when the keyguard is hidden by another activity.
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003356 final boolean keyguardActive = (mKeyguardMediator == null ? false :
3357 (isScreenOn ?
3358 mKeyguardMediator.isShowingAndNotHidden() :
3359 mKeyguardMediator.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003360
Jeff Brown96307042012-07-27 15:51:34 -07003361 if (keyCode == KeyEvent.KEYCODE_POWER) {
3362 policyFlags |= WindowManagerPolicy.FLAG_WAKE;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003363 }
Jeff Brown96307042012-07-27 15:51:34 -07003364 final boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE
3365 | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003366
Jeff Brown40013652012-05-16 21:22:36 -07003367 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003368 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown96307042012-07-27 15:51:34 -07003369 + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive
3370 + " policyFlags=" + Integer.toHexString(policyFlags)
3371 + " isWakeKey=" + isWakeKey);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003372 }
3373
Jeff Brown98392ef2011-09-12 18:24:59 -07003374 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
3375 && event.getRepeatCount() == 0) {
Jeff Brown4d396052010-10-29 21:50:21 -07003376 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
3377 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003378
Jeff Brown4d396052010-10-29 21:50:21 -07003379 // Basic policy based on screen state and keyguard.
3380 // FIXME: This policy isn't quite correct. We shouldn't care whether the screen
3381 // is on or off, really. We should care about whether the device is in an
3382 // interactive state or is in suspend pretending to be "off".
3383 // The primary screen might be turned off due to proximity sensor or
3384 // because we are presenting media on an auxiliary screen or remotely controlling
3385 // the device some other way (which is why we have an exemption here for injected
3386 // events).
3387 int result;
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003388 if ((isScreenOn && !mHeadless) || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003389 // When the screen is on or if the key is injected pass the key to the application.
3390 result = ACTION_PASS_TO_USER;
3391 } else {
3392 // When the screen is off and the key is not injected, determine whether
3393 // to wake the device but don't pass the key to the application.
3394 result = 0;
Jeff Brown1c2e4942012-11-06 16:32:01 -08003395 if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003396 if (keyguardActive) {
Jeff Brown1c2e4942012-11-06 16:32:01 -08003397 // If the keyguard is showing, let it wake the device when ready.
3398 mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode);
Jeff Brown4d396052010-10-29 21:50:21 -07003399 } else {
3400 // Otherwise, wake the device ourselves.
Jeff Brown96307042012-07-27 15:51:34 -07003401 result |= ACTION_WAKE_UP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003402 }
3403 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003404 }
3405
Jeff Brown4d396052010-10-29 21:50:21 -07003406 // Handle special keys.
3407 switch (keyCode) {
3408 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07003409 case KeyEvent.KEYCODE_VOLUME_UP:
3410 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003411 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
3412 if (down) {
3413 if (isScreenOn && !mVolumeDownKeyTriggered
3414 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3415 mVolumeDownKeyTriggered = true;
3416 mVolumeDownKeyTime = event.getDownTime();
3417 mVolumeDownKeyConsumedByScreenshotChord = false;
3418 cancelPendingPowerKeyAction();
3419 interceptScreenshotChord();
3420 }
3421 } else {
3422 mVolumeDownKeyTriggered = false;
3423 cancelPendingScreenshotChordAction();
3424 }
3425 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
3426 if (down) {
3427 if (isScreenOn && !mVolumeUpKeyTriggered
3428 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3429 mVolumeUpKeyTriggered = true;
3430 cancelPendingPowerKeyAction();
3431 cancelPendingScreenshotChordAction();
3432 }
3433 } else {
3434 mVolumeUpKeyTriggered = false;
3435 cancelPendingScreenshotChordAction();
3436 }
3437 }
Jeff Brown4d396052010-10-29 21:50:21 -07003438 if (down) {
3439 ITelephony telephonyService = getTelephonyService();
3440 if (telephonyService != null) {
3441 try {
3442 if (telephonyService.isRinging()) {
3443 // If an incoming call is ringing, either VOLUME key means
3444 // "silence ringer". We handle these keys here, rather than
3445 // in the InCallScreen, to make sure we'll respond to them
3446 // even if the InCallScreen hasn't come to the foreground yet.
3447 // Look for the DOWN event here, to agree with the "fallback"
3448 // behavior in the InCallScreen.
3449 Log.i(TAG, "interceptKeyBeforeQueueing:"
3450 + " VOLUME key-down while ringing: Silence ringer!");
3451
3452 // Silence the ringer. (It's safe to call this
3453 // even if the ringer has already been silenced.)
3454 telephonyService.silenceRinger();
3455
3456 // And *don't* pass this key thru to the current activity
3457 // (which is probably the InCallScreen.)
3458 result &= ~ACTION_PASS_TO_USER;
3459 break;
3460 }
3461 if (telephonyService.isOffhook()
3462 && (result & ACTION_PASS_TO_USER) == 0) {
3463 // If we are in call but we decided not to pass the key to
3464 // the application, handle the volume change here.
3465 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
3466 break;
3467 }
3468 } catch (RemoteException ex) {
3469 Log.w(TAG, "ITelephony threw RemoteException", ex);
3470 }
3471 }
3472
3473 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
3474 // If music is playing but we decided not to pass the key to the
3475 // application, handle the volume change here.
3476 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
3477 break;
3478 }
3479 }
3480 break;
3481 }
3482
3483 case KeyEvent.KEYCODE_ENDCALL: {
3484 result &= ~ACTION_PASS_TO_USER;
3485 if (down) {
3486 ITelephony telephonyService = getTelephonyService();
3487 boolean hungUp = false;
3488 if (telephonyService != null) {
3489 try {
3490 hungUp = telephonyService.endCall();
3491 } catch (RemoteException ex) {
3492 Log.w(TAG, "ITelephony threw RemoteException", ex);
3493 }
3494 }
3495 interceptPowerKeyDown(!isScreenOn || hungUp);
3496 } else {
3497 if (interceptPowerKeyUp(canceled)) {
3498 if ((mEndcallBehavior
3499 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
3500 if (goHome()) {
3501 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07003502 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003503 }
Jeff Brown4d396052010-10-29 21:50:21 -07003504 if ((mEndcallBehavior
3505 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown96307042012-07-27 15:51:34 -07003506 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
Jeff Brown4d396052010-10-29 21:50:21 -07003507 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003508 }
Jeff Brown4d396052010-10-29 21:50:21 -07003509 }
3510 break;
3511 }
3512
3513 case KeyEvent.KEYCODE_POWER: {
3514 result &= ~ACTION_PASS_TO_USER;
3515 if (down) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003516 if (isScreenOn && !mPowerKeyTriggered
3517 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3518 mPowerKeyTriggered = true;
3519 mPowerKeyTime = event.getDownTime();
3520 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07003521 }
Winson Chung9112ec32011-06-27 13:15:32 -07003522
Jeff Brown4d396052010-10-29 21:50:21 -07003523 ITelephony telephonyService = getTelephonyService();
3524 boolean hungUp = false;
3525 if (telephonyService != null) {
3526 try {
3527 if (telephonyService.isRinging()) {
3528 // Pressing Power while there's a ringing incoming
3529 // call should silence the ringer.
3530 telephonyService.silenceRinger();
3531 } else if ((mIncallPowerBehavior
3532 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
3533 && telephonyService.isOffhook()) {
3534 // Otherwise, if "Power button ends call" is enabled,
3535 // the Power button will hang up any current active call.
3536 hungUp = telephonyService.endCall();
3537 }
3538 } catch (RemoteException ex) {
3539 Log.w(TAG, "ITelephony threw RemoteException", ex);
3540 }
3541 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003542 interceptPowerKeyDown(!isScreenOn || hungUp
3543 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003544 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003545 mPowerKeyTriggered = false;
3546 cancelPendingScreenshotChordAction();
3547 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown96307042012-07-27 15:51:34 -07003548 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003549 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003550 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07003551 }
3552 break;
3553 }
3554
3555 case KeyEvent.KEYCODE_MEDIA_PLAY:
3556 case KeyEvent.KEYCODE_MEDIA_PAUSE:
3557 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3558 if (down) {
3559 ITelephony telephonyService = getTelephonyService();
3560 if (telephonyService != null) {
3561 try {
3562 if (!telephonyService.isIdle()) {
3563 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
3564 // to avoid music playback.
3565 break;
3566 }
3567 } catch (RemoteException ex) {
3568 Log.w(TAG, "ITelephony threw RemoteException", ex);
Jeff Brown3122e442010-10-11 23:32:49 -07003569 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003570 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003571 }
Jeff Brown4d396052010-10-29 21:50:21 -07003572 case KeyEvent.KEYCODE_HEADSETHOOK:
3573 case KeyEvent.KEYCODE_MUTE:
3574 case KeyEvent.KEYCODE_MEDIA_STOP:
3575 case KeyEvent.KEYCODE_MEDIA_NEXT:
3576 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
3577 case KeyEvent.KEYCODE_MEDIA_REWIND:
3578 case KeyEvent.KEYCODE_MEDIA_RECORD:
3579 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: {
3580 if ((result & ACTION_PASS_TO_USER) == 0) {
3581 // Only do this if we would otherwise not pass it to the user. In that
3582 // case, the PhoneWindow class will do the same thing, except it will
3583 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07003584 // Note that we need to make a copy of the key event here because the
3585 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07003586 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07003587 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
3588 new KeyEvent(event));
3589 msg.setAsynchronous(true);
3590 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07003591 }
3592 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003593 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003594
Jeff Brown4d396052010-10-29 21:50:21 -07003595 case KeyEvent.KEYCODE_CALL: {
3596 if (down) {
3597 ITelephony telephonyService = getTelephonyService();
3598 if (telephonyService != null) {
3599 try {
3600 if (telephonyService.isRinging()) {
3601 Log.i(TAG, "interceptKeyBeforeQueueing:"
3602 + " CALL key-down while ringing: Answer the call!");
3603 telephonyService.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003604
Jeff Brown4d396052010-10-29 21:50:21 -07003605 // And *don't* pass this key thru to the current activity
3606 // (which is presumably the InCallScreen.)
3607 result &= ~ACTION_PASS_TO_USER;
3608 }
3609 } catch (RemoteException ex) {
3610 Log.w(TAG, "ITelephony threw RemoteException", ex);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003611 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003612 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003613 }
Jeff Brown4d396052010-10-29 21:50:21 -07003614 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003615 }
3616 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003617 return result;
3618 }
3619
Jeff Brown1c2e4942012-11-06 16:32:01 -08003620 /**
3621 * When the screen is off we ignore some keys that might otherwise typically
3622 * be considered wake keys. We filter them out here.
3623 *
3624 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
3625 * is always considered a wake key.
3626 */
3627 private boolean isWakeKeyWhenScreenOff(int keyCode) {
3628 switch (keyCode) {
3629 // ignore volume keys unless docked
3630 case KeyEvent.KEYCODE_VOLUME_UP:
3631 case KeyEvent.KEYCODE_VOLUME_DOWN:
3632 case KeyEvent.KEYCODE_VOLUME_MUTE:
3633 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
3634
3635 // ignore media and camera keys
3636 case KeyEvent.KEYCODE_MUTE:
3637 case KeyEvent.KEYCODE_HEADSETHOOK:
3638 case KeyEvent.KEYCODE_MEDIA_PLAY:
3639 case KeyEvent.KEYCODE_MEDIA_PAUSE:
3640 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3641 case KeyEvent.KEYCODE_MEDIA_STOP:
3642 case KeyEvent.KEYCODE_MEDIA_NEXT:
3643 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
3644 case KeyEvent.KEYCODE_MEDIA_REWIND:
3645 case KeyEvent.KEYCODE_MEDIA_RECORD:
3646 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
3647 case KeyEvent.KEYCODE_CAMERA:
3648 return false;
3649 }
3650 return true;
3651 }
3652
3653
Jeff Brown56194eb2011-03-02 19:23:13 -08003654 /** {@inheritDoc} */
3655 @Override
3656 public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
3657 int result = 0;
3658
3659 final boolean isWakeMotion = (policyFlags
3660 & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
3661 if (isWakeMotion) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003662 if (mKeyguardMediator != null && mKeyguardMediator.isShowing()) {
Jeff Brown56194eb2011-03-02 19:23:13 -08003663 // If the keyguard is showing, let it decide what to do with the wake motion.
3664 mKeyguardMediator.onWakeMotionWhenKeyguardShowingTq();
3665 } else {
3666 // Otherwise, wake the device ourselves.
Jeff Brown96307042012-07-27 15:51:34 -07003667 result |= ACTION_WAKE_UP;
Jeff Brown56194eb2011-03-02 19:23:13 -08003668 }
3669 }
3670 return result;
3671 }
3672
Jeff Brown40013652012-05-16 21:22:36 -07003673 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
3674 if (DEBUG_INPUT) {
3675 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003676 }
3677
Jeff Brown40013652012-05-16 21:22:36 -07003678 if (mHavePendingMediaKeyRepeatWithWakeLock) {
3679 if (DEBUG_INPUT) {
3680 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
3681 }
3682
3683 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
3684 mHavePendingMediaKeyRepeatWithWakeLock = false;
3685 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
3686 }
3687
3688 dispatchMediaKeyWithWakeLockToAudioService(event);
3689
3690 if (event.getAction() == KeyEvent.ACTION_DOWN
3691 && event.getRepeatCount() == 0) {
3692 mHavePendingMediaKeyRepeatWithWakeLock = true;
3693
3694 Message msg = mHandler.obtainMessage(
3695 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
3696 msg.setAsynchronous(true);
3697 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
3698 } else {
3699 mBroadcastWakeLock.release();
3700 }
3701 }
3702
3703 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
3704 mHavePendingMediaKeyRepeatWithWakeLock = false;
3705
3706 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
3707 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
3708 if (DEBUG_INPUT) {
3709 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
3710 }
3711
3712 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
3713 mBroadcastWakeLock.release();
3714 }
3715
3716 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
3717 if (ActivityManagerNative.isSystemReady()) {
3718 IAudioService audioService = getAudioService();
3719 if (audioService != null) {
3720 try {
3721 audioService.dispatchMediaKeyEventUnderWakelock(event);
3722 } catch (RemoteException e) {
3723 Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
Jean-Michel Trivic6802222012-04-30 11:15:03 -07003724 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003725 }
3726 }
3727 }
3728
Mike Lockwood1753f7f2009-08-24 14:49:07 -07003729 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
3730 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07003731 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
3732 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
3733 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Dianne Hackborn80fa1662009-10-07 14:02:10 -07003734 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003735 updateRotation(true);
Mike Lockwoode9867d22009-09-20 01:59:02 -04003736 updateOrientationListenerLp();
Mike Lockwood1753f7f2009-08-24 14:49:07 -07003737 }
3738 };
3739
Jeff Brown6aaf2952012-10-05 16:01:08 -07003740 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
3741 @Override
3742 public void onReceive(Context context, Intent intent) {
3743 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
3744 if (mKeyguardMediator != null) {
3745 mKeyguardMediator.onDreamingStarted();
3746 }
3747 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
3748 if (mKeyguardMediator != null) {
3749 mKeyguardMediator.onDreamingStopped();
3750 }
3751 }
3752 }
3753 };
3754
Christopher Tate5e08af02012-09-21 17:17:22 -07003755 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
3756 @Override
3757 public void onReceive(Context context, Intent intent) {
3758 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
3759 // tickle the settings observer: this first ensures that we're
3760 // observing the relevant settings for the newly-active user,
3761 // and then updates our own bookkeeping based on the now-
3762 // current user.
3763 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05003764
3765 // force a re-application of focused window sysui visibility.
3766 // the window may never have been shown for this user
3767 // e.g. the keyguard when going through the new-user setup flow
3768 synchronized(mLock) {
3769 mLastSystemUiFlags = 0;
3770 updateSystemUiVisibilityLw();
3771 }
Christopher Tate5e08af02012-09-21 17:17:22 -07003772 }
3773 }
3774 };
3775
Jeff Brownc38c9be2012-10-04 13:16:19 -07003776 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003777 public void screenTurnedOff(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07003778 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07003779 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003780 mScreenOnEarly = false;
3781 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07003782 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003783 if (mKeyguardMediator != null) {
3784 mKeyguardMediator.onScreenTurnedOff(why);
3785 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07003786 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07003787 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05003788 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07003789 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003790 }
3791
Jeff Brownc38c9be2012-10-04 13:16:19 -07003792 @Override
Dianne Hackborn38e29a62011-09-18 14:43:08 -07003793 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07003794 EventLog.writeEvent(70000, 1);
Dianne Hackborn40011092011-09-22 13:37:48 -07003795 if (false) {
3796 RuntimeException here = new RuntimeException("here");
3797 here.fillInStackTrace();
3798 Slog.i(TAG, "Screen turning on...", here);
3799 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07003800
The Android Open Source Project0727d222009-03-11 12:11:58 -07003801 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003802 mScreenOnEarly = true;
The Android Open Source Project0727d222009-03-11 12:11:58 -07003803 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05003804 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07003805 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07003806
Jeff Brownc38c9be2012-10-04 13:16:19 -07003807 waitForKeyguard(screenOnListener);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003808 }
3809
Jeff Brownc38c9be2012-10-04 13:16:19 -07003810 private void waitForKeyguard(final ScreenOnListener screenOnListener) {
3811 if (mKeyguardMediator != null) {
3812 if (screenOnListener != null) {
3813 mKeyguardMediator.onScreenTurnedOn(new KeyguardViewManager.ShowListener() {
3814 @Override
3815 public void onShown(IBinder windowToken) {
3816 waitForKeyguardWindowDrawn(windowToken, screenOnListener);
3817 }
3818 });
3819 return;
3820 } else {
3821 mKeyguardMediator.onScreenTurnedOn(null);
3822 }
3823 } else {
3824 Slog.i(TAG, "No keyguard mediator!");
3825 }
3826 finishScreenTurningOn(screenOnListener);
3827 }
3828
3829 private void waitForKeyguardWindowDrawn(IBinder windowToken,
3830 final ScreenOnListener screenOnListener) {
3831 if (windowToken != null) {
3832 try {
3833 if (mWindowManager.waitForWindowDrawn(
3834 windowToken, new IRemoteCallback.Stub() {
3835 @Override
3836 public void sendResult(Bundle data) {
3837 Slog.i(TAG, "Lock screen displayed!");
3838 finishScreenTurningOn(screenOnListener);
3839 }
3840 })) {
3841 return;
3842 }
3843 } catch (RemoteException ex) {
3844 // Can't happen in system process.
3845 }
3846 }
3847
3848 Slog.i(TAG, "No lock screen!");
3849 finishScreenTurningOn(screenOnListener);
3850 }
3851
3852 private void finishScreenTurningOn(ScreenOnListener screenOnListener) {
3853 synchronized (mLock) {
3854 mScreenOnFully = true;
3855 }
3856
Jeff Brown4fc45272012-10-10 18:28:14 -07003857 try {
3858 mWindowManager.setEventDispatching(true);
3859 } catch (RemoteException unhandled) {
3860 }
3861
Jeff Brownc38c9be2012-10-04 13:16:19 -07003862 if (screenOnListener != null) {
3863 screenOnListener.onScreenOn();
3864 }
3865 }
3866
3867 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003868 public boolean isScreenOnEarly() {
3869 return mScreenOnEarly;
3870 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07003871
3872 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003873 public boolean isScreenOnFully() {
3874 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08003875 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07003876
Dianne Hackborn08743722009-12-21 12:16:51 -08003877 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003878 public void enableKeyguard(boolean enabled) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003879 if (mKeyguardMediator != null) {
3880 mKeyguardMediator.setKeyguardEnabled(enabled);
3881 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003882 }
3883
3884 /** {@inheritDoc} */
3885 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003886 if (mKeyguardMediator != null) {
3887 mKeyguardMediator.verifyUnlock(callback);
3888 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003889 }
3890
Mike Lockwoodf7913302009-11-28 22:27:10 -05003891 private boolean keyguardIsShowingTq() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003892 if (mKeyguardMediator == null) return false;
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -08003893 return mKeyguardMediator.isShowingAndNotHidden();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003894 }
3895
Mike Lockwood520d8bc2011-02-18 13:23:13 -05003896
3897 /** {@inheritDoc} */
3898 public boolean isKeyguardLocked() {
3899 return keyguardOn();
3900 }
3901
3902 /** {@inheritDoc} */
3903 public boolean isKeyguardSecure() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003904 if (mKeyguardMediator == null) return false;
Mike Lockwood520d8bc2011-02-18 13:23:13 -05003905 return mKeyguardMediator.isSecure();
3906 }
3907
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003908 /** {@inheritDoc} */
3909 public boolean inKeyguardRestrictedKeyInputMode() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003910 if (mKeyguardMediator == null) return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003911 return mKeyguardMediator.isInputRestricted();
3912 }
3913
Dianne Hackborn90c52de2011-09-23 12:57:44 -07003914 public void dismissKeyguardLw() {
Daniel Sandler1ce804392012-11-07 15:07:12 -05003915 if (mKeyguardMediator.isShowing()) {
3916 mHandler.post(new Runnable() {
3917 public void run() {
3918 if (mKeyguardMediator.isDismissable()) {
3919 // Can we just finish the keyguard straight away?
Dianne Hackborn90c52de2011-09-23 12:57:44 -07003920 mKeyguardMediator.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05003921 } else {
3922 // ask the keyguard to prompt the user to authenticate if necessary
3923 mKeyguardMediator.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07003924 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05003925 }
3926 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07003927 }
3928 }
3929
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003930 void sendCloseSystemWindows() {
3931 sendCloseSystemWindows(mContext, null);
3932 }
3933
3934 void sendCloseSystemWindows(String reason) {
3935 sendCloseSystemWindows(mContext, reason);
3936 }
3937
3938 static void sendCloseSystemWindows(Context context, String reason) {
3939 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07003940 try {
3941 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
3942 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003943 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003944 }
3945 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07003946
Jeff Brown01a98dd2011-09-20 15:08:29 -07003947 @Override
3948 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05003949 if (false) {
3950 Slog.v(TAG, "rotationForOrientationLw(orient="
3951 + orientation + ", last=" + lastRotation
3952 + "); user=" + mUserRotation + " "
3953 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
3954 ? "USER_ROTATION_LOCKED" : "")
3955 );
3956 }
3957
The Android Open Source Project0727d222009-03-11 12:11:58 -07003958 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07003959 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
3960 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07003961 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07003962 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003963
Jeff Browndec6cf42011-11-15 14:08:20 -08003964 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07003965 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07003966 // Ignore sensor when lid switch is open and rotation is forced.
3967 preferredRotation = mLidOpenRotation;
3968 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07003969 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07003970 // Ignore sensor when in car dock unless explicitly enabled.
3971 // This case can override the behavior of NOSENSOR, and can also
3972 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07003973 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07003974 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08003975 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
3976 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
3977 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07003978 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07003979 // Ignore sensor when in desk dock unless explicitly enabled.
3980 // This case can override the behavior of NOSENSOR, and can also
3981 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07003982 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07003983 ? sensorRotation : mDeskDockRotation;
Jeff Brown27f1d672012-10-17 18:32:34 -07003984 } else if (mHdmiPlugged && mHdmiRotationLock) {
Jeff Browneb3e4b92011-12-06 19:54:24 -08003985 // Ignore sensor when plugged into HDMI.
3986 // Note that the dock orientation overrides the HDMI orientation.
3987 preferredRotation = mHdmiRotation;
Jeff Brown207673cd2012-06-05 17:47:11 -07003988 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07003989 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
3990 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED))
3991 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
3992 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
3993 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
3994 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
3995 // Otherwise, use sensor only if requested by the application or enabled
3996 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07003997 if (mAllowAllRotations < 0) {
3998 // Can't read this during init() because the context doesn't
3999 // have display metrics at that time so we cannot determine
4000 // tablet vs. phone then.
4001 mAllowAllRotations = mContext.getResources().getBoolean(
4002 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4003 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004004 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004005 || mAllowAllRotations == 1
Jeff Brown01a98dd2011-09-20 15:08:29 -07004006 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR) {
4007 preferredRotation = sensorRotation;
4008 } else {
4009 preferredRotation = lastRotation;
4010 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004011 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4012 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4013 // Apply rotation lock. Does not apply to NOSENSOR.
4014 // The idea is that the user rotation expresses a weak preference for the direction
4015 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4016 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004017 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004018 } else {
4019 // No overriding preference.
4020 // We will do exactly what the application asked us to do.
4021 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004022 }
4023
Dianne Hackborne5439f22010-10-02 16:53:50 -07004024 switch (orientation) {
4025 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004026 // Return portrait unless overridden.
4027 if (isAnyPortrait(preferredRotation)) {
4028 return preferredRotation;
4029 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004030 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004031
Jeff Brown01a98dd2011-09-20 15:08:29 -07004032 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004033 // Return landscape unless overridden.
4034 if (isLandscapeOrSeascape(preferredRotation)) {
4035 return preferredRotation;
4036 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004037 return mLandscapeRotation;
4038
4039 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004040 // Return reverse portrait unless overridden.
4041 if (isAnyPortrait(preferredRotation)) {
4042 return preferredRotation;
4043 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004044 return mUpsideDownRotation;
4045
4046 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004047 // Return seascape unless overridden.
4048 if (isLandscapeOrSeascape(preferredRotation)) {
4049 return preferredRotation;
4050 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004051 return mSeascapeRotation;
4052
4053 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4054 // Return either landscape rotation.
4055 if (isLandscapeOrSeascape(preferredRotation)) {
4056 return preferredRotation;
4057 }
4058 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004059 return lastRotation;
4060 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004061 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004062
Jeff Brown01a98dd2011-09-20 15:08:29 -07004063 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4064 // Return either portrait rotation.
4065 if (isAnyPortrait(preferredRotation)) {
4066 return preferredRotation;
4067 }
4068 if (isAnyPortrait(lastRotation)) {
4069 return lastRotation;
4070 }
4071 return mPortraitRotation;
4072
4073 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004074 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4075 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004076 if (preferredRotation >= 0) {
4077 return preferredRotation;
4078 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004079 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004080 }
4081 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004082 }
4083
Jeff Brown01a98dd2011-09-20 15:08:29 -07004084 @Override
4085 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4086 switch (orientation) {
4087 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4088 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4089 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4090 return isAnyPortrait(rotation);
4091
4092 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4093 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4094 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4095 return isLandscapeOrSeascape(rotation);
4096
4097 default:
4098 return true;
4099 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004100 }
4101
Jeff Brownc0347aa2011-09-23 17:26:09 -07004102 @Override
4103 public void setRotationLw(int rotation) {
4104 mOrientationListener.setCurrentRotation(rotation);
4105 }
4106
Jeff Brown01a98dd2011-09-20 15:08:29 -07004107 private boolean isLandscapeOrSeascape(int rotation) {
4108 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004109 }
4110
Jeff Brown01a98dd2011-09-20 15:08:29 -07004111 private boolean isAnyPortrait(int rotation) {
4112 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004113 }
4114
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004115
4116 // User rotation: to be used when all else fails in assigning an orientation to the device
4117 public void setUserRotationMode(int mode, int rot) {
4118 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004119
4120 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004121 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004122 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004123 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004124 rot,
4125 UserHandle.USER_CURRENT);
4126 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004127 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004128 0,
4129 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004130 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004131 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004132 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004133 1,
4134 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004135 }
4136 }
4137
Jeff Brownac143512012-04-05 18:57:33 -07004138 public void setSafeMode(boolean safeMode) {
4139 mSafeMode = safeMode;
4140 performHapticFeedbackLw(null, safeMode
4141 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4142 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004143 }
4144
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004145 static long[] getLongIntArray(Resources r, int resid) {
4146 int[] ar = r.getIntArray(resid);
4147 if (ar == null) {
4148 return null;
4149 }
4150 long[] out = new long[ar.length];
4151 for (int i=0; i<ar.length; i++) {
4152 out[i] = ar[i];
4153 }
4154 return out;
4155 }
4156
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004157 /** {@inheritDoc} */
4158 public void systemReady() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004159 if (mKeyguardMediator != null) {
4160 // tell the keyguard
4161 mKeyguardMediator.onSystemReady();
4162 }
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004163 synchronized (mLock) {
4164 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08004165 mSystemReady = true;
4166 mHandler.post(new Runnable() {
4167 public void run() {
4168 updateSettings();
4169 }
4170 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004171 }
4172 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07004173
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004174 /** {@inheritDoc} */
4175 public void systemBooted() {
4176 synchronized (mLock) {
4177 mSystemBooted = true;
4178 }
4179 }
4180
Dianne Hackborn661cd522011-08-22 00:26:20 -07004181 ProgressDialog mBootMsgDialog = null;
4182
4183 /** {@inheritDoc} */
4184 public void showBootMessage(final CharSequence msg, final boolean always) {
Mike Lockwoodaa5bf142011-09-21 13:03:40 -04004185 if (mHeadless) return;
Dianne Hackborn661cd522011-08-22 00:26:20 -07004186 mHandler.post(new Runnable() {
4187 @Override public void run() {
4188 if (mBootMsgDialog == null) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07004189 mBootMsgDialog = new ProgressDialog(mContext) {
4190 // This dialog will consume all events coming in to
4191 // it, to avoid it trying to do things too early in boot.
4192 @Override public boolean dispatchKeyEvent(KeyEvent event) {
4193 return true;
4194 }
4195 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
4196 return true;
4197 }
4198 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
4199 return true;
4200 }
4201 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
4202 return true;
4203 }
4204 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
4205 return true;
4206 }
4207 @Override public boolean dispatchPopulateAccessibilityEvent(
4208 AccessibilityEvent event) {
4209 return true;
4210 }
4211 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07004212 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
4213 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
4214 mBootMsgDialog.setIndeterminate(true);
4215 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004216 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004217 mBootMsgDialog.getWindow().addFlags(
4218 WindowManager.LayoutParams.FLAG_DIM_BEHIND
4219 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
4220 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08004221 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
4222 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
4223 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004224 mBootMsgDialog.setCancelable(false);
4225 mBootMsgDialog.show();
4226 }
4227 mBootMsgDialog.setMessage(msg);
4228 }
4229 });
4230 }
4231
4232 /** {@inheritDoc} */
4233 public void hideBootMessages() {
4234 mHandler.post(new Runnable() {
4235 @Override public void run() {
4236 if (mBootMsgDialog != null) {
4237 mBootMsgDialog.dismiss();
4238 mBootMsgDialog = null;
4239 }
4240 }
4241 });
4242 }
4243
Mike Lockwood28569302010-01-28 11:54:40 -05004244 /** {@inheritDoc} */
4245 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004246 // ***************************************
4247 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
4248 // ***************************************
4249 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
4250 // WITH ITS LOCKS HELD.
4251 //
4252 // This code must be VERY careful about the locks
4253 // it acquires.
4254 // In fact, the current code acquires way too many,
4255 // and probably has lurking deadlocks.
4256
Mike Lockwood28569302010-01-28 11:54:40 -05004257 synchronized (mScreenLockTimeout) {
4258 if (mLockScreenTimerActive) {
4259 // reset the timer
4260 mHandler.removeCallbacks(mScreenLockTimeout);
4261 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4262 }
4263 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04004264 }
4265
Adam Cohenf7522022012-10-03 20:03:18 -07004266 class ScreenLockTimeout implements Runnable {
4267 Bundle options;
4268
4269 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05004270 public void run() {
4271 synchronized (this) {
4272 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004273 if (mKeyguardMediator != null) {
Adam Cohenf7522022012-10-03 20:03:18 -07004274 mKeyguardMediator.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004275 }
Mike Lockwood28569302010-01-28 11:54:40 -05004276 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07004277 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05004278 }
4279 }
Mike Lockwood28569302010-01-28 11:54:40 -05004280
Adam Cohenf7522022012-10-03 20:03:18 -07004281 public void setLockOptions(Bundle options) {
4282 this.options = options;
4283 }
4284 }
4285
4286 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
4287
4288 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08004289 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
4290 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07004291 if (options != null) {
4292 // In case multiple calls are made to lockNow, we don't wipe out the options
4293 // until the runnable actually executes.
4294 mScreenLockTimeout.setLockOptions(options);
4295 }
Jim Miller93c518e2012-01-17 15:55:31 -08004296 mHandler.post(mScreenLockTimeout);
4297 }
4298
Mike Lockwood28569302010-01-28 11:54:40 -05004299 private void updateLockScreenTimeout() {
4300 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004301 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
4302 mKeyguardMediator != null && mKeyguardMediator.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05004303 if (mLockScreenTimerActive != enable) {
4304 if (enable) {
4305 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
4306 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4307 } else {
4308 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
4309 mHandler.removeCallbacks(mScreenLockTimeout);
4310 }
4311 mLockScreenTimerActive = enable;
4312 }
4313 }
4314 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004315
4316 /** {@inheritDoc} */
4317 public void enableScreenAfterBoot() {
4318 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07004319 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004320 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004321 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07004322
Jeff Brownc458ce92012-04-30 14:58:40 -07004323 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07004324 if (mLidState == LID_CLOSED && mLidControlsSleep) {
4325 mPowerManager.goToSleep(SystemClock.uptimeMillis());
4326 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004327 }
4328
4329 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004330 try {
4331 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004332 mWindowManager.updateRotation(alwaysSendConfiguration, false);
4333 } catch (RemoteException e) {
4334 // Ignore
4335 }
4336 }
4337
4338 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
4339 try {
4340 //set orientation on WindowManager
4341 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004342 } catch (RemoteException e) {
4343 // Ignore
4344 }
4345 }
4346
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004347 void startDockOrHome() {
Daniel Sandler7c135202012-09-28 14:04:59 -04004348 // 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 -07004349 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004350 }
4351
4352 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004353 * goes to the home screen
4354 * @return whether it did anything
4355 */
4356 boolean goHome() {
4357 if (false) {
4358 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07004359 try {
4360 ActivityManagerNative.getDefault().stopAppSwitches();
4361 } catch (RemoteException e) {
4362 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004363 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004364 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004365 } else {
4366 // This code brings home to the front or, if it is already
4367 // at the front, puts the device to sleep.
4368 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08004369 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
4370 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
4371 Log.d(TAG, "UTS-TEST-MODE");
4372 } else {
4373 ActivityManagerNative.getDefault().stopAppSwitches();
4374 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004375 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004376 int result = ActivityManagerNative.getDefault()
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004377 .startActivityAsUser(null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004378 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07004379 null, null, 0,
4380 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004381 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07004382 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004383 return false;
4384 }
4385 } catch (RemoteException ex) {
4386 // bummer, the activity manager, which is in this process, is dead
4387 }
4388 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004389 return true;
4390 }
4391
The Android Open Source Project0727d222009-03-11 12:11:58 -07004392 public void setCurrentOrientationLw(int newOrientation) {
4393 synchronized (mLock) {
4394 if (newOrientation != mCurrentAppOrientation) {
4395 mCurrentAppOrientation = newOrientation;
4396 updateOrientationListenerLp();
4397 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004398 }
4399 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004400
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07004401 private void performAuditoryFeedbackForAccessibilityIfNeed() {
4402 if (!isGlobalAccessibilityGestureEnabled()) {
4403 return;
4404 }
4405 AudioManager audioManager = (AudioManager) mContext.getSystemService(
4406 Context.AUDIO_SERVICE);
4407 if (audioManager.isSilentMode()) {
4408 return;
4409 }
4410 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
4411 Settings.System.DEFAULT_NOTIFICATION_URI);
4412 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
4413 ringTone.play();
4414 }
4415 private boolean isGlobalAccessibilityGestureEnabled() {
4416 return Settings.Global.getInt(mContext.getContentResolver(),
4417 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
4418 }
4419
The Android Open Source Project0727d222009-03-11 12:11:58 -07004420 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07004421 if (!mVibrator.hasVibrator()) {
4422 return false;
4423 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004424 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
4425 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -08004426 if (!always && (hapticsDisabled || mKeyguardMediator.isShowingAndNotHidden())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004427 return false;
4428 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004429 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004430 switch (effectId) {
4431 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004432 pattern = mLongPressVibePattern;
4433 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004434 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004435 pattern = mVirtualKeyVibePattern;
4436 break;
4437 case HapticFeedbackConstants.KEYBOARD_TAP:
4438 pattern = mKeyboardTapVibePattern;
4439 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004440 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004441 pattern = mSafeModeDisabledVibePattern;
4442 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004443 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004444 pattern = mSafeModeEnabledVibePattern;
4445 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08004446 default:
4447 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004448 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004449 if (pattern.length == 1) {
4450 // One-shot vibration
4451 mVibrator.vibrate(pattern[0]);
4452 } else {
4453 // Pattern vibration
4454 mVibrator.vibrate(pattern, -1);
4455 }
4456 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004457 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004458
4459 @Override
4460 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04004461 }
4462
Jeff Brownc38c9be2012-10-04 13:16:19 -07004463 @Override
4464 public void keepScreenOnStoppedLw() {
4465 if (mKeyguardMediator != null && !mKeyguardMediator.isShowingAndNotHidden()) {
4466 long curTime = SystemClock.uptimeMillis();
4467 mPowerManager.userActivity(curTime, false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004468 }
4469 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04004470
Dianne Hackborndf89e652011-10-06 22:35:11 -07004471 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08004472 // If there is no window focused, there will be nobody to handle the events
4473 // anyway, so just hang on in whatever state we're in until things settle down.
Dianne Hackborndf89e652011-10-06 22:35:11 -07004474 if (mFocusedWindow == null) {
4475 return 0;
4476 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004477 if (mFocusedWindow.getAttrs().type == TYPE_KEYGUARD && mHideLockScreen == true) {
4478 // We are updating at a point where the keyguard has gotten
4479 // focus, but we were last in a state where the top window is
4480 // hiding it. This is probably because the keyguard as been
4481 // shown while the top window was displayed, so we want to ignore
4482 // it here because this is just a very transient change and it
4483 // will quickly lose focus once it correctly gets hidden.
4484 return 0;
4485 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07004486 final int visibility = mFocusedWindow.getSystemUiVisibility()
Dianne Hackborne26ab702011-10-16 13:21:33 -07004487 & ~mResettingSystemUiFlags
4488 & ~mForceClearedSystemUiFlags;
4489 int diff = visibility ^ mLastSystemUiFlags;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08004490 final boolean needsMenu = mFocusedWindow.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08004491 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
4492 && mFocusedApp == mFocusedWindow.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004493 return 0;
4494 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07004495 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08004496 mLastFocusNeedsMenu = needsMenu;
Dianne Hackborne0f085d2011-11-30 18:41:15 -08004497 mFocusedApp = mFocusedWindow.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07004498 mHandler.post(new Runnable() {
4499 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07004500 try {
4501 IStatusBarService statusbar = getStatusBarService();
4502 if (statusbar != null) {
4503 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
4504 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08004505 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07004506 } catch (RemoteException e) {
4507 // re-acquire status bar service next time it is needed.
4508 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08004509 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07004510 }
4511 });
4512 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08004513 }
4514
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04004515 // Use this instead of checking config_showNavigationBar so that it can be consistently
4516 // overridden by qemu.hw.mainkeys in the emulator.
4517 public boolean hasNavigationBar() {
4518 return mHasNavigationBar;
4519 }
4520
satok1bc0a492012-04-25 22:47:12 +09004521 @Override
4522 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
4523 mLastInputMethodWindow = ime;
4524 mLastInputMethodTargetWindow = target;
4525 }
4526
Craig Mautnerf1b67412012-09-19 13:18:29 -07004527 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07004528 public void setCurrentUserLw(int newUserId) {
4529 if (mKeyguardMediator != null) {
4530 mKeyguardMediator.setCurrentUser(newUserId);
4531 }
John Spurlock13451a22012-09-28 14:40:41 -04004532 if (mStatusBarService != null) {
4533 try {
4534 mStatusBarService.setCurrentUser(newUserId);
4535 } catch (RemoteException e) {
4536 // oh well
4537 }
4538 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07004539 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07004540 }
4541
4542 @Override
Jim Miller4eeb4f62012-11-08 00:04:29 -08004543 public void showAssistant() {
4544 mKeyguardMediator.showAssistant();
4545 }
4546
Svetoslav Ganov152e9bb2012-10-12 20:15:29 -07004547 /**
4548 * Returns the human readable name of a window transition.
4549 *
4550 * @param transition The window transition.
4551 * @return The transition symbolic name.
4552 */
4553 public static String windowTransitionToString(int transition) {
4554 switch (transition) {
4555 case WindowManagerPolicy.TRANSIT_UNSET: {
4556 return "TRANSIT_UNSET";
4557 }
4558 case WindowManagerPolicy.TRANSIT_NONE: {
4559 return "TRANSIT_NONE";
4560 }
4561 case WindowManagerPolicy.TRANSIT_ENTER: {
4562 return "TRANSIT_ENTER";
4563 }
4564 case WindowManagerPolicy.TRANSIT_EXIT: {
4565 return "TRANSIT_EXIT";
4566 }
4567 case WindowManagerPolicy.TRANSIT_SHOW: {
4568 return "TRANSIT_SHOW";
4569 }
4570 case WindowManagerPolicy.TRANSIT_EXIT_MASK: {
4571 return "TRANSIT_EXIT_MASK";
4572 }
4573 case WindowManagerPolicy.TRANSIT_PREVIEW_DONE: {
4574 return "TRANSIT_PREVIEW_DONE";
4575 }
4576 case WindowManagerPolicy.TRANSIT_ACTIVITY_OPEN: {
4577 return "TRANSIT_ACTIVITY_OPEN";
4578 }
4579 case WindowManagerPolicy.TRANSIT_ACTIVITY_CLOSE: {
4580 return "TRANSIT_ACTIVITY_CLOSE";
4581 }
4582 case WindowManagerPolicy.TRANSIT_TASK_OPEN: {
4583 return "TRANSIT_TASK_OPEN";
4584 }
4585 case WindowManagerPolicy.TRANSIT_TASK_CLOSE: {
4586 return "TRANSIT_TASK_CLOSE";
4587 }
4588 case WindowManagerPolicy.TRANSIT_TASK_TO_FRONT: {
4589 return "TRANSIT_TASK_TO_FRONT";
4590 }
4591 case WindowManagerPolicy.TRANSIT_TASK_TO_BACK: {
4592 return "TRANSIT_TASK_TO_BACK";
4593 }
4594 case WindowManagerPolicy.TRANSIT_WALLPAPER_CLOSE: {
4595 return "TRANSIT_WALLPAPER_CLOSE";
4596 }
4597 case WindowManagerPolicy.TRANSIT_WALLPAPER_OPEN: {
4598 return "TRANSIT_WALLPAPER_OPEN";
4599 }
4600 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_OPEN: {
4601 return "TRANSIT_WALLPAPER_INTRA_OPEN";
4602 }
4603 case WindowManagerPolicy.TRANSIT_WALLPAPER_INTRA_CLOSE: {
4604 return "TRANSIT_WALLPAPER_INTRA_CLOSE";
4605 }
4606 default: {
4607 return "<UNKNOWN>";
4608 }
4609 }
4610 }
4611
Jim Miller4eeb4f62012-11-08 00:04:29 -08004612 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07004613 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004614 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004615 pw.print(" mSystemReady="); pw.print(mSystemReady);
4616 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07004617 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004618 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
4619 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07004620 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
4621 || mForceClearedSystemUiFlags != 0) {
4622 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
4623 pw.print(Integer.toHexString(mLastSystemUiFlags));
4624 pw.print(" mResettingSystemUiFlags=0x");
4625 pw.print(Integer.toHexString(mResettingSystemUiFlags));
4626 pw.print(" mForceClearedSystemUiFlags=0x");
4627 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07004628 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08004629 if (mLastFocusNeedsMenu) {
4630 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
4631 pw.println(mLastFocusNeedsMenu);
4632 }
Daniel Sandler7c135202012-09-28 14:04:59 -04004633 pw.print(prefix); pw.print("mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004634 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
4635 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
4636 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
4637 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004638 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07004639 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004640 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
4641 pw.print(mCarDockEnablesAccelerometer);
4642 pw.print(" mDeskDockEnablesAccelerometer=");
4643 pw.println(mDeskDockEnablesAccelerometer);
4644 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
4645 pw.print(mLidKeyboardAccessibility);
4646 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07004647 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
4648 pw.print(prefix); pw.print("mLongPressOnPowerBehavior=");
4649 pw.print(mLongPressOnPowerBehavior);
4650 pw.print(" mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004651 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
4652 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07004653 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004654 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
4655 pw.print(","); pw.print(mUnrestrictedScreenTop);
4656 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
4657 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
4658 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
4659 pw.print(","); pw.print(mRestrictedScreenTop);
4660 pw.print(") "); pw.print(mRestrictedScreenWidth);
4661 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004662 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
4663 pw.print(","); pw.print(mStableFullscreenTop);
4664 pw.print(")-("); pw.print(mStableFullscreenRight);
4665 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004666 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
4667 pw.print(","); pw.print(mStableTop);
4668 pw.print(")-("); pw.print(mStableRight);
4669 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07004670 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
4671 pw.print(","); pw.print(mSystemTop);
4672 pw.print(")-("); pw.print(mSystemRight);
4673 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004674 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
4675 pw.print(","); pw.print(mCurTop);
4676 pw.print(")-("); pw.print(mCurRight);
4677 pw.print(","); pw.print(mCurBottom); pw.println(")");
4678 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
4679 pw.print(","); pw.print(mContentTop);
4680 pw.print(")-("); pw.print(mContentRight);
4681 pw.print(","); pw.print(mContentBottom); pw.println(")");
4682 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
4683 pw.print(","); pw.print(mDockTop);
4684 pw.print(")-("); pw.print(mDockRight);
4685 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07004686 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
4687 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004688 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
4689 pw.print(" mShowingDream="); pw.print(mShowingDream);
4690 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07004691 if (mLastInputMethodWindow != null) {
4692 pw.print(prefix); pw.print("mLastInputMethodWindow=");
4693 pw.println(mLastInputMethodWindow);
4694 }
4695 if (mLastInputMethodTargetWindow != null) {
4696 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
4697 pw.println(mLastInputMethodTargetWindow);
4698 }
4699 if (mStatusBar != null) {
4700 pw.print(prefix); pw.print("mStatusBar=");
4701 pw.println(mStatusBar);
4702 }
4703 if (mNavigationBar != null) {
4704 pw.print(prefix); pw.print("mNavigationBar=");
4705 pw.println(mNavigationBar);
4706 }
4707 if (mKeyguard != null) {
4708 pw.print(prefix); pw.print("mKeyguard=");
4709 pw.println(mKeyguard);
4710 }
4711 if (mFocusedWindow != null) {
4712 pw.print(prefix); pw.print("mFocusedWindow=");
4713 pw.println(mFocusedWindow);
4714 }
4715 if (mFocusedApp != null) {
4716 pw.print(prefix); pw.print("mFocusedApp=");
4717 pw.println(mFocusedApp);
4718 }
4719 if (mWinDismissingKeyguard != null) {
4720 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
4721 pw.println(mWinDismissingKeyguard);
4722 }
4723 if (mTopFullscreenOpaqueWindowState != null) {
4724 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
4725 pw.println(mTopFullscreenOpaqueWindowState);
4726 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004727 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004728 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004729 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
4730 pw.print(" mForceStatusBarFromKeyguard=");
4731 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004732 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004733 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004734 pw.print(" mHomePressed="); pw.println(mHomePressed);
4735 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
4736 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
4737 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
4738 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
4739 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
4740 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
4741 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
4742 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
4743 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
4744 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brown27f1d672012-10-17 18:32:34 -07004745 pw.print(prefix); pw.print("mHdmiRotation="); pw.print(mHdmiRotation);
4746 pw.print(" mHdmiRotationLock="); pw.println(mHdmiRotationLock);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004747 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004748}