blob: 54bf20dafb8046818a133094aa50adad187d5142 [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;
61
Jim Millere6ad1a82010-08-20 19:25:39 -070062import com.android.internal.R;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080063import com.android.internal.policy.PolicyManager;
Jim Miller9c7e6302012-08-29 13:48:34 -070064import com.android.internal.policy.impl.keyguard.KeyguardViewManager;
65import com.android.internal.policy.impl.keyguard.KeyguardViewMediator;
Joe Onorato0cbda992010-05-02 16:28:15 -070066import com.android.internal.statusbar.IStatusBarService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080067import com.android.internal.telephony.ITelephony;
Dianne Hackborn6019c9d2010-03-01 21:43:11 -080068import com.android.internal.widget.PointerLocationView;
69
Dianne Hackborn81e56d52011-05-26 00:55:58 -070070import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080071import android.util.EventLog;
72import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070073import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080074import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070075import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080076import android.view.Gravity;
77import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080078import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080079import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070080import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070081import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080082import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080083import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080084import android.view.KeyCharacterMap;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080085import android.view.KeyEvent;
86import android.view.MotionEvent;
Jeff Brown98365d72012-08-19 20:30:52 -070087import android.view.WindowManagerGlobal;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080088import android.view.WindowOrientationListener;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080089import android.view.Surface;
90import android.view.View;
91import android.view.ViewConfiguration;
92import android.view.Window;
93import android.view.WindowManager;
94import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
95import static android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN;
96import static android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN;
97import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
98import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
99import static android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -0700100import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700101import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
Mike Lockwood28569302010-01-28 11:54:40 -0500102import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
Craig Mautner88400d32012-09-30 12:35:45 -0700103import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800104import static android.view.WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
105import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
Dianne Hackborndea3ef72010-10-28 14:24:22 -0700106import static android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800107import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
108import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700109import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800110import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
Craig Mautner88400d32012-09-30 12:35:45 -0700111import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800112import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
113import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
Jeff Brownbd6e1502012-08-28 03:27:37 -0700114import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY;
Christopher Tatea53146c2010-09-07 11:57:52 -0700115import static android.view.WindowManager.LayoutParams.TYPE_DRAG;
Daniel Sandler7d276c32012-01-30 14:33:52 -0500116import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700117import static android.view.WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800118import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD;
119import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -0700120import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800121import static android.view.WindowManager.LayoutParams.TYPE_PHONE;
122import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
Craig Mautner88400d32012-09-30 12:35:45 -0700123import static android.view.WindowManager.LayoutParams.TYPE_RECENTS_OVERLAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800124import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR;
Jeff Brown3b2b3542010-10-15 00:54:27 -0700125import static android.view.WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800126import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
127import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL;
Joe Onorato29fc2c92010-11-24 10:26:50 -0800128import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
Dianne Hackborn6a294ce2009-12-03 11:37:44 -0800129import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800130import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
131import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
132import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
133import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG;
134import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
135import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -0700136import static android.view.WindowManager.LayoutParams.TYPE_UNIVERSE_BACKGROUND;
Dianne Hackborne8ecde12011-08-03 18:55:19 -0700137import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY;
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -0700138import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
Jeff Brown83c09682010-12-23 17:50:18 -0800139import static android.view.WindowManager.LayoutParams.TYPE_POINTER;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400140import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
Jim Millere898ac52012-04-06 17:10:57 -0700141import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -0700142import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800143import android.view.WindowManagerPolicy;
Jeff Brownac143512012-04-05 18:57:33 -0700144import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
145import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
146import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800147import android.view.KeyCharacterMap.FallbackAction;
Dianne Hackborn295e3c22011-08-25 13:19:08 -0700148import android.view.accessibility.AccessibilityEvent;
Dianne Hackborn01ad2f42009-09-24 19:24:56 -0700149import android.view.animation.Animation;
150import android.view.animation.AnimationUtils;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800151
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800152import java.io.File;
Joe Onoratodc100302011-01-11 17:07:41 -0800153import java.io.FileReader;
154import java.io.IOException;
Dianne Hackbornf99f9c52011-01-12 15:49:25 -0800155import java.io.PrintWriter;
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
Winson Chung1cea2f32012-10-08 20:42:01 -0700687 mHandler.postDelayed(mScreenshotChordLongPress, 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() {
703 mHandler.removeCallbacks(mScreenshotChordLongPress);
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
741 private final Runnable mScreenshotChordLongPress = new Runnable() {
742 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 Brown27f1d672012-10-17 18:32:34 -07001058 mHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", true);
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;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001978 }
Jeff Browncaab4d02010-12-09 22:13:41 -08001979
Jeff Brownc1fb48d2010-12-08 16:52:09 -08001980 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08001981 // Any printing key that is chorded with Search should be consumed
1982 // even if no shortcut was invoked. This prevents text from being
1983 // inadvertently inserted when using a keyboard that has built-in macro
1984 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001985 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08001986 final KeyCharacterMap kcm = event.getKeyCharacterMap();
1987 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001988 mConsumeSearchKeyUp = true;
1989 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08001990 if (down && repeatCount == 0 && !keyguardOn) {
1991 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
1992 if (shortcutIntent != null) {
1993 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08001994 try {
1995 mContext.startActivity(shortcutIntent);
1996 } catch (ActivityNotFoundException ex) {
1997 Slog.w(TAG, "Dropping shortcut key combination because "
1998 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001999 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002000 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002001 } else {
2002 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002003 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002004 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002005 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002006 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002007 }
2008 }
2009
Jeff Brown68b909d2011-12-07 16:36:01 -08002010 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002011 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002012 && (metaState & KeyEvent.META_META_ON) != 0) {
2013 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002014 if (kcm.isPrintingKey(keyCode)) {
2015 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2016 metaState & ~(KeyEvent.META_META_ON
2017 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2018 if (shortcutIntent != null) {
2019 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2020 try {
2021 mContext.startActivity(shortcutIntent);
2022 } catch (ActivityNotFoundException ex) {
2023 Slog.w(TAG, "Dropping shortcut key combination because "
2024 + "the activity to which it is registered was not found: "
2025 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2026 }
2027 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002028 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002029 }
2030 }
2031
Jeff Brown6651a632011-11-28 12:59:11 -08002032 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002033 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002034 String category = sApplicationLaunchKeyCategories.get(keyCode);
2035 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002036 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002037 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2038 try {
2039 mContext.startActivity(intent);
2040 } catch (ActivityNotFoundException ex) {
2041 Slog.w(TAG, "Dropping application launch key because "
2042 + "the activity to which it is registered was not found: "
2043 + "keyCode=" + keyCode + ", category=" + category, ex);
2044 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002045 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002046 }
2047 }
2048
Jeff Brown68b909d2011-12-07 16:36:01 -08002049 // Display task switcher for ALT-TAB or Meta-TAB.
2050 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Jeff Brown602ab322012-05-16 13:33:47 -07002051 if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002052 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
2053 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2054 || KeyEvent.metaStateHasModifiers(
2055 shiftlessModifiers, KeyEvent.META_META_ON)) {
2056 mRecentAppsDialogHeldModifiers = shiftlessModifiers;
2057 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW);
2058 return -1;
2059 }
2060 }
2061 } else if (!down && mRecentAppsDialogHeldModifiers != 0
2062 && (metaState & mRecentAppsDialogHeldModifiers) == 0) {
2063 mRecentAppsDialogHeldModifiers = 0;
Jeff Brown602ab322012-05-16 13:33:47 -07002064 showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS :
2065 RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH);
Jeff Brown68b909d2011-12-07 16:36:01 -08002066 }
2067
Jeff Browncf39bdf2012-05-18 14:41:19 -07002068 // Handle keyboard language switching.
2069 if (down && repeatCount == 0
2070 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2071 || (keyCode == KeyEvent.KEYCODE_SPACE
2072 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2073 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2074 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2075 return -1;
2076 }
2077 if (mLanguageSwitchKeyPressed && !down
2078 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2079 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2080 mLanguageSwitchKeyPressed = false;
2081 return -1;
2082 }
2083
Jeff Brown68b909d2011-12-07 16:36:01 -08002084 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002085 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002086 }
2087
Jeff Brown3915bb82010-11-05 15:02:16 -07002088 /** {@inheritDoc} */
2089 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002090 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002091 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002092 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002093 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2094 + ", flags=" + event.getFlags()
2095 + ", keyCode=" + event.getKeyCode()
2096 + ", scanCode=" + event.getScanCode()
2097 + ", metaState=" + event.getMetaState()
2098 + ", repeatCount=" + event.getRepeatCount()
2099 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002100 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002101
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002102 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002103 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2104 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002105 final int keyCode = event.getKeyCode();
2106 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002107 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2108 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002109
Jeff Brown54875002011-04-06 15:33:01 -07002110 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002111 final FallbackAction fallbackAction;
2112 if (initialDown) {
2113 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2114 } else {
2115 fallbackAction = mFallbackActions.get(keyCode);
2116 }
2117
2118 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002119 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002120 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2121 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002122 }
2123
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002124 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2125 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002126 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002127 event.getAction(), fallbackAction.keyCode,
2128 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002129 event.getDeviceId(), event.getScanCode(),
2130 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002131
2132 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2133 fallbackEvent.recycle();
2134 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002135 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002136
2137 if (initialDown) {
2138 mFallbackActions.put(keyCode, fallbackAction);
2139 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2140 mFallbackActions.remove(keyCode);
2141 fallbackAction.recycle();
2142 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002143 }
2144 }
2145
Jeff Brown40013652012-05-16 21:22:36 -07002146 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002147 if (fallbackEvent == null) {
2148 Slog.d(TAG, "No fallback.");
2149 } else {
2150 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2151 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002152 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002153 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002154 }
2155
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002156 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
2157 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true);
2158 if ((actions & ACTION_PASS_TO_USER) != 0) {
2159 long delayMillis = interceptKeyBeforeDispatching(
2160 win, fallbackEvent, policyFlags);
2161 if (delayMillis == 0) {
2162 return true;
2163 }
2164 }
2165 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002166 }
2167
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002168 private void launchAssistLongPressAction() {
2169 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2170 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2171
2172 // launch the search activity
2173 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2174 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2175 try {
Jim Miller45308b12012-06-18 19:23:39 -07002176 // TODO: This only stops the factory-installed search manager.
2177 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002178 SearchManager searchManager = getSearchManager();
2179 if (searchManager != null) {
2180 searchManager.stopSearch();
2181 }
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002182 mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002183 } catch (ActivityNotFoundException e) {
2184 Slog.w(TAG, "No activity to handle assist long press action.", e);
2185 }
2186 }
2187
2188 private void launchAssistAction() {
2189 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002190 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf02b60a2012-08-16 10:48:27 -07002191 .getAssistIntent(mContext, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002192 if (intent != null) {
2193 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2194 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2195 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2196 try {
Dianne Hackborn79af1dd2012-08-16 16:42:52 -07002197 mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
Jim Miller45308b12012-06-18 19:23:39 -07002198 } catch (ActivityNotFoundException e) {
2199 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002200 }
2201 }
2202 }
2203
2204 private SearchManager getSearchManager() {
2205 if (mSearchManager == null) {
2206 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2207 }
2208 return mSearchManager;
2209 }
2210
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002211 /**
2212 * A home key -> launch home action was detected. Take the appropriate action
2213 * given the situation with the keyguard.
2214 */
2215 void launchHomeFromHotKey() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07002216 if (mKeyguardMediator != null && mKeyguardMediator.isShowingAndNotHidden()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002217 // don't launch home if keyguard showing
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002218 } else if (!mHideLockScreen && mKeyguardMediator.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002219 // when in keyguard restricted mode, must first verify unlock
2220 // before launching home
2221 mKeyguardMediator.verifyUnlock(new OnKeyguardExitResult() {
2222 public void onKeyguardExitResult(boolean success) {
2223 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002224 try {
2225 ActivityManagerNative.getDefault().stopAppSwitches();
2226 } catch (RemoteException e) {
2227 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002228 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002229 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002230 }
2231 }
2232 });
2233 } else {
2234 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002235 try {
2236 ActivityManagerNative.getDefault().stopAppSwitches();
2237 } catch (RemoteException e) {
2238 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002239 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002240 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002241 }
2242 }
2243
Dianne Hackborne26ab702011-10-16 13:21:33 -07002244 /**
2245 * A delayed callback use to determine when it is okay to re-allow applications
2246 * to use certain system UI flags. This is used to prevent applications from
2247 * spamming system UI changes that prevent the navigation bar from being shown.
2248 */
2249 final Runnable mAllowSystemUiDelay = new Runnable() {
2250 @Override public void run() {
2251 }
2252 };
2253
2254 /**
2255 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2256 * to determine when the nav bar should be shown and prevent applications from
2257 * receiving those touches.
2258 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002259 final class HideNavInputEventReceiver extends InputEventReceiver {
2260 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2261 super(inputChannel, looper);
2262 }
2263
Dianne Hackborndf89e652011-10-06 22:35:11 -07002264 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002265 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002266 boolean handled = false;
2267 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002268 if (event instanceof MotionEvent
2269 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2270 final MotionEvent motionEvent = (MotionEvent)event;
2271 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002272 // When the user taps down, we re-show the nav bar.
2273 boolean changed = false;
2274 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002275 // Any user activity always causes us to show the
2276 // navigation controls, if they had been hidden.
2277 // We also clear the low profile and only content
2278 // flags so that tapping on the screen will atomically
2279 // restore all currently hidden screen decorations.
2280 int newVal = mResettingSystemUiFlags |
2281 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2282 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2283 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002284 if (mResettingSystemUiFlags != newVal) {
2285 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002286 changed = true;
2287 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002288 // We don't allow the system's nav bar to be hidden
2289 // again for 1 second, to prevent applications from
2290 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002291 newVal = mForceClearedSystemUiFlags |
2292 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002293 if (mForceClearedSystemUiFlags != newVal) {
2294 mForceClearedSystemUiFlags = newVal;
2295 changed = true;
2296 mHandler.postDelayed(new Runnable() {
2297 @Override public void run() {
2298 synchronized (mLock) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002299 // Clear flags.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002300 mForceClearedSystemUiFlags &=
2301 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2302 }
2303 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2304 }
2305 }, 1000);
2306 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002307 }
2308 if (changed) {
2309 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2310 }
2311 }
2312 }
2313 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002314 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002315 }
2316 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002317 }
2318 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2319 new InputEventReceiver.Factory() {
2320 @Override
2321 public InputEventReceiver createInputEventReceiver(
2322 InputChannel inputChannel, Looper looper) {
2323 return new HideNavInputEventReceiver(inputChannel, looper);
2324 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002325 };
2326
2327 @Override
2328 public int adjustSystemUiVisibilityLw(int visibility) {
2329 // Reset any bits in mForceClearingStatusBarVisibility that
2330 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002331 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002332 // Clear any bits in the new visibility that are currently being
2333 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002334 return visibility & ~mResettingSystemUiFlags
2335 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002336 }
2337
Craig Mautner69b08182012-09-05 13:07:13 -07002338 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002339 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
2340 final int fl = attrs.flags;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002341 final int systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002342
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002343 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002344 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002345 int availRight, availBottom;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002346 if (mCanHideNavigationBar &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002347 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002348 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2349 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2350 } else {
2351 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2352 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2353 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002354 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2355 if ((fl & FLAG_FULLSCREEN) != 0) {
2356 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2357 availRight - mStableFullscreenRight,
2358 availBottom - mStableFullscreenBottom);
2359 } else {
2360 contentInset.set(mStableLeft, mStableTop,
2361 availRight - mStableRight, availBottom - mStableBottom);
2362 }
2363 } else if ((fl & FLAG_FULLSCREEN) != 0) {
2364 contentInset.setEmpty();
2365 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002366 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2367 contentInset.set(mCurLeft, mCurTop,
2368 availRight - mCurRight, availBottom - mCurBottom);
2369 } else {
2370 contentInset.set(mCurLeft, mCurTop,
2371 availRight - mCurRight, availBottom - mCurBottom);
2372 }
2373 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002374 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002375 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002376 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002377
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002378 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002379 @Override
2380 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2381 int displayRotation) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08002382 mUnrestrictedScreenLeft = mUnrestrictedScreenTop = 0;
2383 mUnrestrictedScreenWidth = displayWidth;
2384 mUnrestrictedScreenHeight = displayHeight;
2385 mRestrictedScreenLeft = mRestrictedScreenTop = 0;
2386 mRestrictedScreenWidth = displayWidth;
2387 mRestrictedScreenHeight = displayHeight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002388 mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft
2389 = mSystemLeft = mCurLeft = 0;
2390 mDockTop = mContentTop = mStableTop = mStableFullscreenTop
2391 = mSystemTop = mCurTop = 0;
2392 mDockRight = mContentRight = mStableRight = mStableFullscreenRight
2393 = mSystemRight = mCurRight = displayWidth;
2394 mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom
2395 = mSystemBottom = mCurBottom = displayHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002396 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002397 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002398
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002399 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2400 final Rect pf = mTmpParentFrame;
2401 final Rect df = mTmpDisplayFrame;
2402 final Rect vf = mTmpVisibleFrame;
2403 pf.left = df.left = vf.left = mDockLeft;
2404 pf.top = df.top = vf.top = mDockTop;
2405 pf.right = df.right = vf.right = mDockRight;
2406 pf.bottom = df.bottom = vf.bottom = mDockBottom;
2407
Craig Mautner69b08182012-09-05 13:07:13 -07002408 if (isDefaultDisplay) {
2409 // For purposes of putting out fake window up to steal focus, we will
2410 // drive nav being hidden only by whether it is requested.
2411 boolean navVisible = (mLastSystemUiFlags&View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002412
Craig Mautner69b08182012-09-05 13:07:13 -07002413 // When the navigation bar isn't visible, we put up a fake
2414 // input window to catch all touch events. This way we can
2415 // detect when the user presses anywhere to bring back the nav
2416 // bar and ensure the application doesn't see the event.
2417 if (navVisible) {
2418 if (mHideNavFakeWindow != null) {
2419 mHideNavFakeWindow.dismiss();
2420 mHideNavFakeWindow = null;
2421 }
2422 } else if (mHideNavFakeWindow == null) {
2423 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2424 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
2425 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER,
2426 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002427 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002428
Craig Mautner69b08182012-09-05 13:07:13 -07002429 // For purposes of positioning and showing the nav bar, if we have
2430 // decided that it can't be hidden (because of the screen aspect ratio),
2431 // then take that into account.
2432 navVisible |= !mCanHideNavigationBar;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002433
Craig Mautner69b08182012-09-05 13:07:13 -07002434 if (mNavigationBar != null) {
2435 // Force the navigation bar to its appropriate place and
2436 // size. We need to do this directly, instead of relying on
2437 // it to bubble up from the nav bar, because this needs to
2438 // change atomically with screen rotations.
2439 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2440 if (mNavigationBarOnBottom) {
2441 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
2442 int top = displayHeight - mNavigationBarHeightForRotation[displayRotation];
2443 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight);
2444 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
2445 if (navVisible) {
2446 mNavigationBar.showLw(true);
2447 mDockBottom = mTmpNavigationFrame.top;
2448 mRestrictedScreenHeight = mDockBottom - mDockTop;
2449 } else {
2450 // We currently want to hide the navigation UI.
2451 mNavigationBar.hideLw(true);
2452 }
2453 if (navVisible && !mNavigationBar.isAnimatingLw()) {
2454 // If the nav bar is currently requested to be visible,
2455 // and not in the process of animating on or off, then
2456 // we can tell the app that it is covered by it.
2457 mSystemBottom = mTmpNavigationFrame.top;
2458 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002459 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002460 // Landscape screen; nav bar goes to the right.
2461 int left = displayWidth - mNavigationBarWidthForRotation[displayRotation];
2462 mTmpNavigationFrame.set(left, 0, displayWidth, displayHeight);
2463 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
2464 if (navVisible) {
2465 mNavigationBar.showLw(true);
2466 mDockRight = mTmpNavigationFrame.left;
2467 mRestrictedScreenWidth = mDockRight - mDockLeft;
2468 } else {
2469 // We currently want to hide the navigation UI.
2470 mNavigationBar.hideLw(true);
2471 }
2472 if (navVisible && !mNavigationBar.isAnimatingLw()) {
2473 // If the nav bar is currently requested to be visible,
2474 // and not in the process of animating on or off, then
2475 // we can tell the app that it is covered by it.
2476 mSystemRight = mTmpNavigationFrame.left;
2477 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002478 }
Craig Mautner69b08182012-09-05 13:07:13 -07002479 // Make sure the content and current rectangles are updated to
2480 // account for the restrictions from the navigation bar.
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002481 mContentTop = mCurTop = mDockTop;
2482 mContentBottom = mCurBottom = mDockBottom;
2483 mContentLeft = mCurLeft = mDockLeft;
2484 mContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002485 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2486 // And compute the final frame.
2487 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
2488 mTmpNavigationFrame, mTmpNavigationFrame);
2489 if (DEBUG_LAYOUT) Log.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002490 }
Craig Mautner69b08182012-09-05 13:07:13 -07002491 if (DEBUG_LAYOUT) Log.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
2492 mDockLeft, mDockTop, mDockRight, mDockBottom));
2493
2494 // decide where the status bar goes ahead of time
2495 if (mStatusBar != null) {
2496 // apply any navigation bar insets
2497 pf.left = df.left = mUnrestrictedScreenLeft;
2498 pf.top = df.top = mUnrestrictedScreenTop;
2499 pf.right = df.right = mUnrestrictedScreenWidth - mUnrestrictedScreenLeft;
2500 pf.bottom = df.bottom = mUnrestrictedScreenHeight - mUnrestrictedScreenTop;
2501 vf.left = mStableLeft;
2502 vf.top = mStableTop;
2503 vf.right = mStableRight;
2504 vf.bottom = mStableBottom;
2505
2506 mStatusBarLayer = mStatusBar.getSurfaceLayer();
2507
2508 // Let the status bar determine its size.
2509 mStatusBar.computeFrameLw(pf, df, vf, vf);
2510
2511 // For layout, the status bar is always at the top with our fixed height.
2512 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
2513
2514 // If the status bar is hidden, we don't want to cause
2515 // windows behind it to scroll.
2516 if (mStatusBar.isVisibleLw()) {
2517 // Status bar may go away, so the screen area it occupies
2518 // is available to apps but just covering them when the
2519 // status bar is visible.
2520 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
2521
2522 mContentTop = mCurTop = mDockTop;
2523 mContentBottom = mCurBottom = mDockBottom;
2524 mContentLeft = mCurLeft = mDockLeft;
2525 mContentRight = mCurRight = mDockRight;
2526
2527 if (DEBUG_LAYOUT) Log.v(TAG, "Status bar: " +
2528 String.format(
2529 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
2530 mDockLeft, mDockTop, mDockRight, mDockBottom,
2531 mContentLeft, mContentTop, mContentRight, mContentBottom,
2532 mCurLeft, mCurTop, mCurRight, mCurBottom));
2533 }
2534 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()) {
2535 // If the status bar is currently requested to be visible,
2536 // and not in the process of animating on or off, then
2537 // we can tell the app that it is covered by it.
2538 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
2539 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002540 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002541 }
2542 }
2543
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002544 /** {@inheritDoc} */
2545 public int getSystemDecorRectLw(Rect systemRect) {
2546 systemRect.left = mSystemLeft;
2547 systemRect.top = mSystemTop;
2548 systemRect.right = mSystemRight;
2549 systemRect.bottom = mSystemBottom;
2550 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
2551 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
2552 return 0;
2553 }
2554
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002555 void setAttachedWindowFrames(WindowState win, int fl, int adjust,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002556 WindowState attached, boolean insetDecors, Rect pf, Rect df, Rect cf, Rect vf) {
2557 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
2558 // Here's a special case: if this attached window is a panel that is
2559 // above the dock window, and the window it is attached to is below
2560 // the dock window, then the frames we computed for the window it is
2561 // attached to can not be used because the dock is effectively part
2562 // of the underlying window and the attached window is floating on top
2563 // of the whole thing. So, we ignore the attached window and explicitly
2564 // compute the frames that would be appropriate without the dock.
2565 df.left = cf.left = vf.left = mDockLeft;
2566 df.top = cf.top = vf.top = mDockTop;
2567 df.right = cf.right = vf.right = mDockRight;
2568 df.bottom = cf.bottom = vf.bottom = mDockBottom;
2569 } else {
2570 // The effective display frame of the attached window depends on
2571 // whether it is taking care of insetting its content. If not,
2572 // we need to use the parent's content frame so that the entire
2573 // window is positioned within that content. Otherwise we can use
2574 // the display frame and let the attached window take care of
2575 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002576 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002577 cf.set(attached.getDisplayFrameLw());
2578 } else {
2579 // If the window is resizing, then we want to base the content
2580 // frame on our attached content frame to resize... however,
2581 // things can be tricky if the attached window is NOT in resize
2582 // mode, in which case its content frame will be larger.
2583 // Ungh. So to deal with that, make sure the content frame
2584 // we end up using is not covering the IM dock.
2585 cf.set(attached.getContentFrameLw());
2586 if (attached.getSurfaceLayer() < mDockLayer) {
2587 if (cf.left < mContentLeft) cf.left = mContentLeft;
2588 if (cf.top < mContentTop) cf.top = mContentTop;
2589 if (cf.right > mContentRight) cf.right = mContentRight;
2590 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
2591 }
2592 }
2593 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
2594 vf.set(attached.getVisibleFrameLw());
2595 }
2596 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
2597 // window should be positioned relative to its parent or the entire
2598 // screen.
2599 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
2600 ? attached.getFrameLw() : df);
2601 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002602
2603 private void applyStableConstraints(int sysui, int fl, Rect r) {
2604 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2605 // If app is requesting a stable layout, don't let the
2606 // content insets go below the stable values.
2607 if ((fl & FLAG_FULLSCREEN) != 0) {
2608 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
2609 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
2610 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
2611 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
2612 } else {
2613 if (r.left < mStableLeft) r.left = mStableLeft;
2614 if (r.top < mStableTop) r.top = mStableTop;
2615 if (r.right > mStableRight) r.right = mStableRight;
2616 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
2617 }
2618 }
2619 }
2620
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002621 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002622 @Override
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07002623 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
2624 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002625 // we've already done the status bar
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002626 if (win == mStatusBar || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002627 return;
2628 }
Craig Mautner69b08182012-09-05 13:07:13 -07002629 final boolean isDefaultDisplay = win.isDefaultDisplay();
2630 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09002631 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
2632 if (needsToOffsetInputMethodTarget) {
2633 if (DEBUG_LAYOUT) {
2634 Slog.i(TAG, "Offset ime target window by the last ime window state");
2635 }
2636 offsetInputMethodWindowLw(mLastInputMethodWindow);
2637 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002638
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002639 final int fl = attrs.flags;
2640 final int sim = attrs.softInputMode;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002641 final int sysUiFl = win.getSystemUiVisibility();
2642
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002643 final Rect pf = mTmpParentFrame;
2644 final Rect df = mTmpDisplayFrame;
2645 final Rect cf = mTmpContentFrame;
2646 final Rect vf = mTmpVisibleFrame;
Craig Mautner69b08182012-09-05 13:07:13 -07002647
2648 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04002649 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002650
Craig Mautnerf683b562012-10-02 11:10:57 -07002651 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
2652
Craig Mautner69b08182012-09-05 13:07:13 -07002653 if (!isDefaultDisplay) {
2654 if (attached != null) {
2655 // If this window is attached to another, our display
2656 // frame is the same as the one we are attached to.
Craig Mautnerf683b562012-10-02 11:10:57 -07002657 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002658 } else {
2659 // Give the window full screen.
2660 pf.left = df.left = cf.left = mUnrestrictedScreenLeft;
2661 pf.top = df.top = cf.top = mUnrestrictedScreenTop;
2662 pf.right = df.right = cf.right
2663 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2664 pf.bottom = df.bottom = cf.bottom
2665 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2666 }
2667 } else if (attrs.type == TYPE_INPUT_METHOD) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002668 pf.left = df.left = cf.left = vf.left = mDockLeft;
2669 pf.top = df.top = cf.top = vf.top = mDockTop;
2670 pf.right = df.right = cf.right = vf.right = mDockRight;
2671 pf.bottom = df.bottom = cf.bottom = vf.bottom = mDockBottom;
2672 // IM dock windows always go to the bottom of the screen.
2673 attrs.gravity = Gravity.BOTTOM;
2674 mDockLayer = win.getSurfaceLayer();
2675 } else {
Dianne Hackborn82de1ae2010-10-28 11:28:39 -07002676 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_FULLSCREEN | FLAG_LAYOUT_INSET_DECOR))
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002677 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)
2678 && (sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002679 if (DEBUG_LAYOUT)
2680 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle()
2681 + "): IN_SCREEN, INSET_DECOR, !FULLSCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002682 // This is the case for a normal activity window: we want it
2683 // to cover all of the screen space, and it can take care of
2684 // moving its contents to account for screen decorations that
2685 // intrude into that space.
2686 if (attached != null) {
2687 // If this window is attached to another, our display
2688 // frame is the same as the one we are attached to.
Craig Mautnerf683b562012-10-02 11:10:57 -07002689 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002690 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002691 if (attrs.type == TYPE_STATUS_BAR_PANEL
2692 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08002693 // Status bar panels are the only windows who can go on top of
2694 // the status bar. They are protected by the STATUS_BAR_SERVICE
2695 // permission, so they have the same privileges as the status
2696 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002697 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002698 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002699
2700 pf.left = df.left = hasNavBar ? mDockLeft : mUnrestrictedScreenLeft;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002701 pf.top = df.top = mUnrestrictedScreenTop;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002702 pf.right = df.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002703 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002704 : mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2705 pf.bottom = df.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002706 ? mRestrictedScreenTop+mRestrictedScreenHeight
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002707 : mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
2708
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002709 if (DEBUG_LAYOUT) {
2710 Log.v(TAG, String.format(
2711 "Laying out status bar window: (%d,%d - %d,%d)",
2712 pf.left, pf.top, pf.right, pf.bottom));
2713 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002714 } else if (mCanHideNavigationBar
2715 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002716 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
2717 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
2718 // Asking for layout as if the nav bar is hidden, lets the
2719 // application extend into the unrestricted screen area. We
2720 // only do this for application windows to ensure no window that
2721 // can be above the nav bar can do this.
2722 pf.left = df.left = mUnrestrictedScreenLeft;
2723 pf.top = df.top = mUnrestrictedScreenTop;
2724 pf.right = df.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2725 pf.bottom = df.bottom = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002726 } else {
2727 pf.left = df.left = mRestrictedScreenLeft;
2728 pf.top = df.top = mRestrictedScreenTop;
2729 pf.right = df.right = mRestrictedScreenLeft+mRestrictedScreenWidth;
2730 pf.bottom = df.bottom = mRestrictedScreenTop+mRestrictedScreenHeight;
2731 }
Craig Mautner69b08182012-09-05 13:07:13 -07002732
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002733 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002734 cf.left = mDockLeft;
2735 cf.top = mDockTop;
2736 cf.right = mDockRight;
2737 cf.bottom = mDockBottom;
2738 } else {
2739 cf.left = mContentLeft;
2740 cf.top = mContentTop;
2741 cf.right = mContentRight;
2742 cf.bottom = mContentBottom;
2743 }
Craig Mautner69b08182012-09-05 13:07:13 -07002744
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002745 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002746 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
2747 vf.left = mCurLeft;
2748 vf.top = mCurTop;
2749 vf.right = mCurRight;
2750 vf.bottom = mCurBottom;
2751 } else {
2752 vf.set(cf);
2753 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002754 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002755 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
2756 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
2757 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002758 if (DEBUG_LAYOUT)
2759 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002760 // A window that has requested to fill the entire screen just
2761 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002762 if (attrs.type == TYPE_STATUS_BAR_PANEL
2763 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
2764 pf.left = df.left = cf.left = hasNavBar ? mDockLeft : mUnrestrictedScreenLeft;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002765 pf.top = df.top = cf.top = mUnrestrictedScreenTop;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002766 pf.right = df.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002767 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002768 : mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2769 pf.bottom = df.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002770 ? mRestrictedScreenTop+mRestrictedScreenHeight
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002771 : mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Daniel Sandler36412a72011-08-04 09:35:13 -04002772 if (DEBUG_LAYOUT) {
2773 Log.v(TAG, String.format(
2774 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
2775 pf.left, pf.top, pf.right, pf.bottom));
2776 }
Jim Millere898ac52012-04-06 17:10:57 -07002777 } else if (attrs.type == TYPE_NAVIGATION_BAR
2778 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002779 // The navigation bar has Real Ultimate Power.
2780 pf.left = df.left = mUnrestrictedScreenLeft;
2781 pf.top = df.top = mUnrestrictedScreenTop;
2782 pf.right = df.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2783 pf.bottom = df.bottom = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
2784 if (DEBUG_LAYOUT) {
2785 Log.v(TAG, String.format(
2786 "Laying out navigation bar window: (%d,%d - %d,%d)",
2787 pf.left, pf.top, pf.right, pf.bottom));
2788 }
Dianne Hackborn01011c32012-02-21 13:54:21 -08002789 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
2790 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002791 && ((fl & FLAG_FULLSCREEN) != 0)) {
2792 // Fullscreen secure system overlays get what they ask for.
2793 pf.left = df.left = mUnrestrictedScreenLeft;
2794 pf.top = df.top = mUnrestrictedScreenTop;
2795 pf.right = df.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2796 pf.bottom = df.bottom = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07002797 } else if (attrs.type == TYPE_BOOT_PROGRESS
2798 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08002799 // Boot progress screen always covers entire display.
2800 pf.left = df.left = cf.left = mUnrestrictedScreenLeft;
2801 pf.top = df.top = cf.top = mUnrestrictedScreenTop;
2802 pf.right = df.right = cf.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2803 pf.bottom = df.bottom = cf.bottom
2804 = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002805 } else if (mCanHideNavigationBar
2806 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002807 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
2808 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
2809 // Asking for layout as if the nav bar is hidden, lets the
2810 // application extend into the unrestricted screen area. We
2811 // only do this for application windows to ensure no window that
2812 // can be above the nav bar can do this.
2813 // XXX This assumes that an app asking for this will also
2814 // ask for layout in only content. We can't currently figure out
2815 // what the screen would be if only laying out to hide the nav bar.
2816 pf.left = df.left = cf.left = mUnrestrictedScreenLeft;
2817 pf.top = df.top = cf.top = mUnrestrictedScreenTop;
2818 pf.right = df.right = cf.right = mUnrestrictedScreenLeft+mUnrestrictedScreenWidth;
2819 pf.bottom = df.bottom = cf.bottom
2820 = mUnrestrictedScreenTop+mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08002821 } else {
2822 pf.left = df.left = cf.left = mRestrictedScreenLeft;
2823 pf.top = df.top = cf.top = mRestrictedScreenTop;
2824 pf.right = df.right = cf.right = mRestrictedScreenLeft+mRestrictedScreenWidth;
2825 pf.bottom = df.bottom = cf.bottom
2826 = mRestrictedScreenTop+mRestrictedScreenHeight;
2827 }
Craig Mautner69b08182012-09-05 13:07:13 -07002828
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002829 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07002830
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002831 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
2832 vf.left = mCurLeft;
2833 vf.top = mCurTop;
2834 vf.right = mCurRight;
2835 vf.bottom = mCurBottom;
2836 } else {
2837 vf.set(cf);
2838 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002839 } else if (attached != null) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002840 if (DEBUG_LAYOUT)
2841 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002842 // A child window should be placed inside of the same visible
2843 // frame that its parent had.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002844 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002845 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002846 if (DEBUG_LAYOUT)
2847 Log.v(TAG, "layoutWindowLw(" + attrs.getTitle() + "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002848 // Otherwise, a normal window must be placed inside the content
2849 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07002850 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
2851 // Status bar panels are the only windows who can go on top of
2852 // the status bar. They are protected by the STATUS_BAR_SERVICE
2853 // permission, so they have the same privileges as the status
2854 // bar itself.
Dianne Hackborn7d049322011-06-14 15:00:32 -07002855 pf.left = df.left = cf.left = mRestrictedScreenLeft;
2856 pf.top = df.top = cf.top = mRestrictedScreenTop;
2857 pf.right = df.right = cf.right = mRestrictedScreenLeft+mRestrictedScreenWidth;
2858 pf.bottom = df.bottom = cf.bottom
2859 = mRestrictedScreenTop+mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002860 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07002861 pf.left = mContentLeft;
2862 pf.top = mContentTop;
2863 pf.right = mContentRight;
2864 pf.bottom = mContentBottom;
2865 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
2866 df.left = cf.left = mDockLeft;
2867 df.top = cf.top = mDockTop;
2868 df.right = cf.right = mDockRight;
2869 df.bottom = cf.bottom = mDockBottom;
2870 } else {
2871 df.left = cf.left = mContentLeft;
2872 df.top = cf.top = mContentTop;
2873 df.right = cf.right = mContentRight;
2874 df.bottom = cf.bottom = mContentBottom;
2875 }
2876 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
2877 vf.left = mCurLeft;
2878 vf.top = mCurTop;
2879 vf.right = mCurRight;
2880 vf.bottom = mCurBottom;
2881 } else {
2882 vf.set(cf);
2883 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002884 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002885 }
2886 }
Craig Mautner69b08182012-09-05 13:07:13 -07002887
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002888 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0) {
2889 df.left = df.top = cf.left = cf.top = vf.left = vf.top = -10000;
2890 df.right = df.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
2891 }
2892
The Android Open Source Project11267662009-03-18 17:39:47 -07002893 if (DEBUG_LAYOUT) Log.v(TAG, "Compute frame " + attrs.getTitle()
2894 + ": sim=#" + Integer.toHexString(sim)
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002895 + " attach=" + attached + " type=" + attrs.type
2896 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07002897 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
2898 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07002899
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002900 win.computeFrameLw(pf, df, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002901
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002902 // Dock windows carve out the bottom of the screen, so normal windows
2903 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07002904 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
2905 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09002906 setLastInputMethodWindowLw(null, null);
2907 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002908 }
2909 }
2910
satok1bc0a492012-04-25 22:47:12 +09002911 private void offsetInputMethodWindowLw(WindowState win) {
2912 int top = win.getContentFrameLw().top;
2913 top += win.getGivenContentInsetsLw().top;
2914 if (mContentBottom > top) {
2915 mContentBottom = top;
2916 }
2917 top = win.getVisibleFrameLw().top;
2918 top += win.getGivenVisibleInsetsLw().top;
2919 if (mCurBottom > top) {
2920 mCurBottom = top;
2921 }
2922 if (DEBUG_LAYOUT) Log.v(TAG, "Input method: mDockBottom="
2923 + mDockBottom + " mContentBottom="
2924 + mContentBottom + " mCurBottom=" + mCurBottom);
2925 }
2926
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002927 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08002928 @Override
2929 public void finishLayoutLw() {
2930 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002931 }
2932
2933 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07002934 @Override
Craig Mautner39834192012-09-02 07:47:24 -07002935 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002936 mTopFullscreenOpaqueWindowState = null;
2937 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002938 mForceStatusBarFromKeyguard = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002939
2940 mHideLockScreen = false;
2941 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07002942 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002943 mShowingLockscreen = false;
2944 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002945 }
2946
2947 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07002948 @Override
Craig Mautner39834192012-09-02 07:47:24 -07002949 public void applyPostLayoutPolicyLw(WindowState win,
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002950 WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07002951 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
2952 + win.isVisibleOrBehindKeyguardLw());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002953 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08002954 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002955 if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002956 if (attrs.type == TYPE_KEYGUARD) {
2957 mForceStatusBarFromKeyguard = true;
2958 } else {
2959 mForceStatusBar = true;
2960 }
2961 }
2962 if (attrs.type == TYPE_KEYGUARD) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002963 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07002964 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002965 boolean applyWindow = attrs.type >= FIRST_APPLICATION_WINDOW
2966 && attrs.type <= LAST_APPLICATION_WINDOW;
2967 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07002968 // If the lockscreen was showing when the dream started then wait
2969 // for the dream to draw before hiding the lockscreen.
2970 if (!mDreamingLockscreen
2971 || (win.isVisibleLw() && win.hasDrawnLw())) {
2972 mShowingDream = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002973 applyWindow = true;
2974 }
2975 }
2976 if (applyWindow
Dianne Hackborn6493e642010-10-01 13:06:30 -07002977 && attrs.x == 0 && attrs.y == 0
2978 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
2979 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002980 if (DEBUG_LAYOUT) Log.v(TAG, "Fullscreen window: " + win);
2981 mTopFullscreenOpaqueWindowState = win;
2982 if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002983 if (DEBUG_LAYOUT) Log.v(TAG, "Setting mHideLockScreen to true by win " + win);
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002984 mHideLockScreen = true;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002985 mForceStatusBarFromKeyguard = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002986 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07002987 if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0
2988 && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002989 if (DEBUG_LAYOUT) Log.v(TAG, "Setting mDismissKeyguard to true by win " + win);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07002990 mDismissKeyguard = mWinDismissingKeyguard == win ?
2991 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
2992 mWinDismissingKeyguard = win;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002993 mForceStatusBarFromKeyguard = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08002994 }
2995 if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
2996 mAllowLockscreenWhenOn = true;
2997 }
2998 }
2999 }
3000 }
3001
3002 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003003 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003004 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003005 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003006 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003007
3008 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3009 ? mTopFullscreenOpaqueWindowState.getAttrs()
3010 : null;
3011
Jeff Brownc8018eb2012-10-29 21:33:27 -07003012 // If we are not currently showing a dream then remember the current
3013 // lockscreen state. We will use this to determine whether the dream
3014 // started while the lockscreen was showing and remember this state
3015 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003016 if (!mShowingDream) {
3017 mDreamingLockscreen = mShowingLockscreen;
3018 }
3019
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003020 if (mStatusBar != null) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003021 if (DEBUG_LAYOUT) Log.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003022 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003023 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003024 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003025 if (DEBUG_LAYOUT) Log.v(TAG, "Showing status bar: forced");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003026 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003027 } else if (mTopFullscreenOpaqueWindowState != null) {
Joe Onorato93056472010-09-10 10:30:46 -04003028 if (localLOGV) {
3029 Log.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
3030 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
3031 Log.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
3032 + " lp.flags=0x" + Integer.toHexString(lp.flags));
3033 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003034 topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
3035 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003036 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3037 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3038 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3039 // case though.
3040 if (topIsFullscreen) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003041 if (DEBUG_LAYOUT) Log.v(TAG, "** HIDING status bar");
3042 if (mStatusBar.hideLw(true)) {
3043 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Daniel Sandler9c00d5b2011-09-13 14:04:26 -04003044
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003045 mHandler.post(new Runnable() {
3046 @Override
3047 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07003048 try {
3049 IStatusBarService statusbar = getStatusBarService();
3050 if (statusbar != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -04003051 statusbar.collapsePanels();
Dianne Hackborn42e620c2012-06-24 13:20:51 -07003052 }
3053 } catch (RemoteException ex) {
3054 // re-acquire status bar service next time it is needed.
3055 mStatusBarService = null;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003056 }
3057 }});
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003058 } else if (DEBUG_LAYOUT) {
Daniel Sandler40427442010-07-16 11:44:52 -04003059 Log.v(TAG, "Preventing status bar from hiding by policy");
3060 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003061 } else {
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003062 if (DEBUG_LAYOUT) Log.v(TAG, "** SHOWING status bar: top is not fullscreen");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003063 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003064 }
3065 }
3066 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003067
Joe Onorato644f9c32011-01-25 12:06:23 -08003068 mTopIsFullscreen = topIsFullscreen;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003069
Craig Mautner39834192012-09-02 07:47:24 -07003070 // Hide the key guard if a visible window explicitly specifies that it wants to be
3071 // displayed when the screen is locked.
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003072 if (mKeyguard != null) {
Craig Mautner39834192012-09-02 07:47:24 -07003073 if (localLOGV) Log.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3074 + mHideLockScreen);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003075 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardMediator.isSecure()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003076 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003077 changes |= FINISH_LAYOUT_REDO_LAYOUT
3078 | FINISH_LAYOUT_REDO_CONFIG
3079 | FINISH_LAYOUT_REDO_WALLPAPER;
3080 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003081 if (mKeyguardMediator.isShowing()) {
Dianne Hackbornb446e972009-09-20 15:23:25 -07003082 mHandler.post(new Runnable() {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003083 @Override
Dianne Hackbornb446e972009-09-20 15:23:25 -07003084 public void run() {
Dianne Hackborn05726582009-09-22 17:28:24 -07003085 mKeyguardMediator.keyguardDone(false, false);
Dianne Hackbornb446e972009-09-20 15:23:25 -07003086 }
3087 });
3088 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003089 } else if (mHideLockScreen) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003090 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003091 changes |= FINISH_LAYOUT_REDO_LAYOUT
3092 | FINISH_LAYOUT_REDO_CONFIG
3093 | FINISH_LAYOUT_REDO_WALLPAPER;
3094 }
Mike Lockwoodf3bfed52010-01-21 16:38:44 -05003095 mKeyguardMediator.setHidden(true);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003096 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3097 // This is the case of keyguard isSecure() and not mHideLockScreen.
3098 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3099 // Only launch the next keyguard unlock window once per window.
3100 if (mKeyguard.showLw(true)) {
3101 changes |= FINISH_LAYOUT_REDO_LAYOUT
3102 | FINISH_LAYOUT_REDO_CONFIG
3103 | FINISH_LAYOUT_REDO_WALLPAPER;
3104 }
3105 mKeyguardMediator.setHidden(false);
3106 mHandler.post(new Runnable() {
3107 @Override
3108 public void run() {
3109 mKeyguardMediator.dismiss();
3110 }
3111 });
3112 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003113 } else {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003114 mWinDismissingKeyguard = null;
Dianne Hackborn08743722009-12-21 12:16:51 -08003115 if (mKeyguard.showLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003116 changes |= FINISH_LAYOUT_REDO_LAYOUT
3117 | FINISH_LAYOUT_REDO_CONFIG
3118 | FINISH_LAYOUT_REDO_WALLPAPER;
3119 }
Mike Lockwoodf3bfed52010-01-21 16:38:44 -05003120 mKeyguardMediator.setHidden(false);
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003121 }
3122 }
Joe Onorato664644d2011-01-23 17:53:23 -08003123
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003124 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003125 // If the navigation bar has been hidden or shown, we need to do another
3126 // layout pass to update that window.
3127 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3128 }
Joe Onorato664644d2011-01-23 17:53:23 -08003129
Mike Lockwood28569302010-01-28 11:54:40 -05003130 // update since mAllowLockscreenWhenOn might have changed
3131 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003132 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003133 }
3134
Dianne Hackborn08743722009-12-21 12:16:51 -08003135 public boolean allowAppAnimationsLw() {
Craig Mautnerf03e4c52012-06-14 14:11:27 -07003136 if (mKeyguard != null && mKeyguard.isVisibleLw() && !mKeyguard.isAnimatingLw()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003137 // If keyguard is currently visible, no reason to animate
3138 // behind it.
3139 return false;
3140 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003141 return true;
3142 }
3143
Dianne Hackborndf89e652011-10-06 22:35:11 -07003144 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003145 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003146 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003147 // If the navigation bar has been hidden or shown, we need to do another
3148 // layout pass to update that window.
3149 return FINISH_LAYOUT_REDO_LAYOUT;
3150 }
3151 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003152 }
3153
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003154 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07003155 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003156 // do nothing if headless
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003157 if (mHeadless) return;
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003158
Jeff Brown46b9ac02010-04-22 18:58:52 -07003159 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003160 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3161 if (newLidState == mLidState) {
3162 return;
3163 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003164
Jeff Brownc458ce92012-04-30 14:58:40 -07003165 mLidState = newLidState;
3166 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003167 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003168
3169 if (lidOpen) {
3170 if (keyguardIsShowingTq()) {
Jeff Brown1c2e4942012-11-06 16:32:01 -08003171 mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(KeyEvent.KEYCODE_POWER);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003172 } else {
Jeff Brown96307042012-07-27 15:51:34 -07003173 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brown46b9ac02010-04-22 18:58:52 -07003174 }
Jeff Brownc458ce92012-04-30 14:58:40 -07003175 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003176 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003177 }
3178 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003179
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003180 void setHdmiPlugged(boolean plugged) {
3181 if (mHdmiPlugged != plugged) {
3182 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003183 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003184 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003185 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003186 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003187 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003188 }
3189 }
3190
Joe Onoratoea495d42011-04-06 11:41:11 -07003191 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003192 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003193 // watch for HDMI plug messages if the hdmi switch exists
3194 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3195 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3196
Joe Onoratoea495d42011-04-06 11:41:11 -07003197 final String filename = "/sys/class/switch/hdmi/state";
3198 FileReader reader = null;
3199 try {
3200 reader = new FileReader(filename);
3201 char[] buf = new char[15];
3202 int n = reader.read(buf);
3203 if (n > 1) {
3204 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3205 }
3206 } catch (IOException ex) {
3207 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3208 } catch (NumberFormatException ex) {
3209 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3210 } finally {
3211 if (reader != null) {
3212 try {
3213 reader.close();
3214 } catch (IOException ex) {
3215 }
Joe Onoratodc100302011-01-11 17:07:41 -08003216 }
3217 }
3218 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07003219 // This dance forces the code in setHdmiPlugged to run.
3220 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
3221 mHdmiPlugged = !plugged;
3222 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08003223 }
3224
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003225 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003226 * @return Whether music is being played right now.
3227 */
3228 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07003229 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
3230 if (am == null) {
3231 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003232 return false;
3233 }
Eric Laurent413cb9d2009-07-17 11:52:43 -07003234 return am.isMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003235 }
3236
3237 /**
3238 * Tell the audio service to adjust the volume appropriate to the event.
3239 * @param keycode
3240 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04003241 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07003242 IAudioService audioService = getAudioService();
3243 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003244 return;
3245 }
3246 try {
3247 // since audio is playing, we shouldn't have to hold a wake lock
3248 // during the call, but we do it as a precaution for the rare possibility
3249 // that the music stops right before we call this
Jeff Brownb0418da2010-11-01 15:24:01 -07003250 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003251 mBroadcastWakeLock.acquire();
Jeff Brown4d396052010-10-29 21:50:21 -07003252 audioService.adjustStreamVolume(stream,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003253 keycode == KeyEvent.KEYCODE_VOLUME_UP
3254 ? AudioManager.ADJUST_RAISE
3255 : AudioManager.ADJUST_LOWER,
3256 0);
3257 } catch (RemoteException e) {
3258 Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e);
3259 } finally {
3260 mBroadcastWakeLock.release();
3261 }
3262 }
Jeff Brown4d396052010-10-29 21:50:21 -07003263
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07003264 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003265 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003266
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003267 final Runnable mScreenshotTimeout = new Runnable() {
3268 @Override public void run() {
3269 synchronized (mScreenshotLock) {
3270 if (mScreenshotConnection != null) {
3271 mContext.unbindService(mScreenshotConnection);
3272 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003273 }
Winson Chung9112ec32011-06-27 13:15:32 -07003274 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003275 }
3276 };
3277
3278 // Assume this is called from the Handler thread.
3279 private void takeScreenshot() {
3280 synchronized (mScreenshotLock) {
3281 if (mScreenshotConnection != null) {
3282 return;
3283 }
3284 ComponentName cn = new ComponentName("com.android.systemui",
3285 "com.android.systemui.screenshot.TakeScreenshotService");
3286 Intent intent = new Intent();
3287 intent.setComponent(cn);
3288 ServiceConnection conn = new ServiceConnection() {
3289 @Override
3290 public void onServiceConnected(ComponentName name, IBinder service) {
3291 synchronized (mScreenshotLock) {
3292 if (mScreenshotConnection != this) {
3293 return;
3294 }
3295 Messenger messenger = new Messenger(service);
3296 Message msg = Message.obtain(null, 1);
3297 final ServiceConnection myConn = this;
3298 Handler h = new Handler(mHandler.getLooper()) {
3299 @Override
3300 public void handleMessage(Message msg) {
3301 synchronized (mScreenshotLock) {
3302 if (mScreenshotConnection == myConn) {
3303 mContext.unbindService(mScreenshotConnection);
3304 mScreenshotConnection = null;
3305 mHandler.removeCallbacks(mScreenshotTimeout);
3306 }
3307 }
3308 }
3309 };
3310 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07003311 msg.arg1 = msg.arg2 = 0;
3312 if (mStatusBar != null && mStatusBar.isVisibleLw())
3313 msg.arg1 = 1;
3314 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
3315 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003316 try {
3317 messenger.send(msg);
3318 } catch (RemoteException e) {
3319 }
3320 }
3321 }
3322 @Override
3323 public void onServiceDisconnected(ComponentName name) {}
3324 };
Jeff Sharkey35744c12012-08-28 16:48:05 -07003325 if (mContext.bindService(
3326 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.USER_CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003327 mScreenshotConnection = conn;
3328 mHandler.postDelayed(mScreenshotTimeout, 10000);
3329 }
3330 }
Winson Chung9112ec32011-06-27 13:15:32 -07003331 }
3332
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003333 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003334 @Override
Jeff Brown1f245102010-11-18 20:53:46 -08003335 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
Jeff Brown96307042012-07-27 15:51:34 -07003336 if (!mSystemBooted) {
3337 // If we have not yet booted, don't let key events do anything.
3338 return 0;
3339 }
3340
Jeff Brown1f245102010-11-18 20:53:46 -08003341 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3342 final boolean canceled = event.isCanceled();
3343 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07003344
Jeff Brown3122e442010-10-11 23:32:49 -07003345 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07003346
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05003347 // If screen is off then we treat the case where the keyguard is open but hidden
3348 // the same as if it were open and in front.
3349 // This will prevent any keys other than the power button from waking the screen
3350 // when the keyguard is hidden by another activity.
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003351 final boolean keyguardActive = (mKeyguardMediator == null ? false :
3352 (isScreenOn ?
3353 mKeyguardMediator.isShowingAndNotHidden() :
3354 mKeyguardMediator.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003355
Jeff Brown96307042012-07-27 15:51:34 -07003356 if (keyCode == KeyEvent.KEYCODE_POWER) {
3357 policyFlags |= WindowManagerPolicy.FLAG_WAKE;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003358 }
Jeff Brown96307042012-07-27 15:51:34 -07003359 final boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE
3360 | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003361
Jeff Brown40013652012-05-16 21:22:36 -07003362 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003363 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown96307042012-07-27 15:51:34 -07003364 + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive
3365 + " policyFlags=" + Integer.toHexString(policyFlags)
3366 + " isWakeKey=" + isWakeKey);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003367 }
3368
Jeff Brown98392ef2011-09-12 18:24:59 -07003369 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
3370 && event.getRepeatCount() == 0) {
Jeff Brown4d396052010-10-29 21:50:21 -07003371 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
3372 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003373
Jeff Brown4d396052010-10-29 21:50:21 -07003374 // Basic policy based on screen state and keyguard.
3375 // FIXME: This policy isn't quite correct. We shouldn't care whether the screen
3376 // is on or off, really. We should care about whether the device is in an
3377 // interactive state or is in suspend pretending to be "off".
3378 // The primary screen might be turned off due to proximity sensor or
3379 // because we are presenting media on an auxiliary screen or remotely controlling
3380 // the device some other way (which is why we have an exemption here for injected
3381 // events).
3382 int result;
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003383 if ((isScreenOn && !mHeadless) || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003384 // When the screen is on or if the key is injected pass the key to the application.
3385 result = ACTION_PASS_TO_USER;
3386 } else {
3387 // When the screen is off and the key is not injected, determine whether
3388 // to wake the device but don't pass the key to the application.
3389 result = 0;
Jeff Brown1c2e4942012-11-06 16:32:01 -08003390 if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003391 if (keyguardActive) {
Jeff Brown1c2e4942012-11-06 16:32:01 -08003392 // If the keyguard is showing, let it wake the device when ready.
3393 mKeyguardMediator.onWakeKeyWhenKeyguardShowingTq(keyCode);
Jeff Brown4d396052010-10-29 21:50:21 -07003394 } else {
3395 // Otherwise, wake the device ourselves.
Jeff Brown96307042012-07-27 15:51:34 -07003396 result |= ACTION_WAKE_UP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003397 }
3398 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003399 }
3400
Jeff Brown4d396052010-10-29 21:50:21 -07003401 // Handle special keys.
3402 switch (keyCode) {
3403 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07003404 case KeyEvent.KEYCODE_VOLUME_UP:
3405 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003406 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
3407 if (down) {
3408 if (isScreenOn && !mVolumeDownKeyTriggered
3409 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3410 mVolumeDownKeyTriggered = true;
3411 mVolumeDownKeyTime = event.getDownTime();
3412 mVolumeDownKeyConsumedByScreenshotChord = false;
3413 cancelPendingPowerKeyAction();
3414 interceptScreenshotChord();
3415 }
3416 } else {
3417 mVolumeDownKeyTriggered = false;
3418 cancelPendingScreenshotChordAction();
3419 }
3420 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
3421 if (down) {
3422 if (isScreenOn && !mVolumeUpKeyTriggered
3423 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3424 mVolumeUpKeyTriggered = true;
3425 cancelPendingPowerKeyAction();
3426 cancelPendingScreenshotChordAction();
3427 }
3428 } else {
3429 mVolumeUpKeyTriggered = false;
3430 cancelPendingScreenshotChordAction();
3431 }
3432 }
Jeff Brown4d396052010-10-29 21:50:21 -07003433 if (down) {
3434 ITelephony telephonyService = getTelephonyService();
3435 if (telephonyService != null) {
3436 try {
3437 if (telephonyService.isRinging()) {
3438 // If an incoming call is ringing, either VOLUME key means
3439 // "silence ringer". We handle these keys here, rather than
3440 // in the InCallScreen, to make sure we'll respond to them
3441 // even if the InCallScreen hasn't come to the foreground yet.
3442 // Look for the DOWN event here, to agree with the "fallback"
3443 // behavior in the InCallScreen.
3444 Log.i(TAG, "interceptKeyBeforeQueueing:"
3445 + " VOLUME key-down while ringing: Silence ringer!");
3446
3447 // Silence the ringer. (It's safe to call this
3448 // even if the ringer has already been silenced.)
3449 telephonyService.silenceRinger();
3450
3451 // And *don't* pass this key thru to the current activity
3452 // (which is probably the InCallScreen.)
3453 result &= ~ACTION_PASS_TO_USER;
3454 break;
3455 }
3456 if (telephonyService.isOffhook()
3457 && (result & ACTION_PASS_TO_USER) == 0) {
3458 // If we are in call but we decided not to pass the key to
3459 // the application, handle the volume change here.
3460 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
3461 break;
3462 }
3463 } catch (RemoteException ex) {
3464 Log.w(TAG, "ITelephony threw RemoteException", ex);
3465 }
3466 }
3467
3468 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
3469 // If music is playing but we decided not to pass the key to the
3470 // application, handle the volume change here.
3471 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
3472 break;
3473 }
3474 }
3475 break;
3476 }
3477
3478 case KeyEvent.KEYCODE_ENDCALL: {
3479 result &= ~ACTION_PASS_TO_USER;
3480 if (down) {
3481 ITelephony telephonyService = getTelephonyService();
3482 boolean hungUp = false;
3483 if (telephonyService != null) {
3484 try {
3485 hungUp = telephonyService.endCall();
3486 } catch (RemoteException ex) {
3487 Log.w(TAG, "ITelephony threw RemoteException", ex);
3488 }
3489 }
3490 interceptPowerKeyDown(!isScreenOn || hungUp);
3491 } else {
3492 if (interceptPowerKeyUp(canceled)) {
3493 if ((mEndcallBehavior
3494 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
3495 if (goHome()) {
3496 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07003497 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003498 }
Jeff Brown4d396052010-10-29 21:50:21 -07003499 if ((mEndcallBehavior
3500 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown96307042012-07-27 15:51:34 -07003501 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
Jeff Brown4d396052010-10-29 21:50:21 -07003502 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003503 }
Jeff Brown4d396052010-10-29 21:50:21 -07003504 }
3505 break;
3506 }
3507
3508 case KeyEvent.KEYCODE_POWER: {
3509 result &= ~ACTION_PASS_TO_USER;
3510 if (down) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003511 if (isScreenOn && !mPowerKeyTriggered
3512 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3513 mPowerKeyTriggered = true;
3514 mPowerKeyTime = event.getDownTime();
3515 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07003516 }
Winson Chung9112ec32011-06-27 13:15:32 -07003517
Jeff Brown4d396052010-10-29 21:50:21 -07003518 ITelephony telephonyService = getTelephonyService();
3519 boolean hungUp = false;
3520 if (telephonyService != null) {
3521 try {
3522 if (telephonyService.isRinging()) {
3523 // Pressing Power while there's a ringing incoming
3524 // call should silence the ringer.
3525 telephonyService.silenceRinger();
3526 } else if ((mIncallPowerBehavior
3527 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
3528 && telephonyService.isOffhook()) {
3529 // Otherwise, if "Power button ends call" is enabled,
3530 // the Power button will hang up any current active call.
3531 hungUp = telephonyService.endCall();
3532 }
3533 } catch (RemoteException ex) {
3534 Log.w(TAG, "ITelephony threw RemoteException", ex);
3535 }
3536 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003537 interceptPowerKeyDown(!isScreenOn || hungUp
3538 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003539 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003540 mPowerKeyTriggered = false;
3541 cancelPendingScreenshotChordAction();
3542 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown96307042012-07-27 15:51:34 -07003543 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003544 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003545 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07003546 }
3547 break;
3548 }
3549
3550 case KeyEvent.KEYCODE_MEDIA_PLAY:
3551 case KeyEvent.KEYCODE_MEDIA_PAUSE:
3552 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3553 if (down) {
3554 ITelephony telephonyService = getTelephonyService();
3555 if (telephonyService != null) {
3556 try {
3557 if (!telephonyService.isIdle()) {
3558 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
3559 // to avoid music playback.
3560 break;
3561 }
3562 } catch (RemoteException ex) {
3563 Log.w(TAG, "ITelephony threw RemoteException", ex);
Jeff Brown3122e442010-10-11 23:32:49 -07003564 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003565 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003566 }
Jeff Brown4d396052010-10-29 21:50:21 -07003567 case KeyEvent.KEYCODE_HEADSETHOOK:
3568 case KeyEvent.KEYCODE_MUTE:
3569 case KeyEvent.KEYCODE_MEDIA_STOP:
3570 case KeyEvent.KEYCODE_MEDIA_NEXT:
3571 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
3572 case KeyEvent.KEYCODE_MEDIA_REWIND:
3573 case KeyEvent.KEYCODE_MEDIA_RECORD:
3574 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: {
3575 if ((result & ACTION_PASS_TO_USER) == 0) {
3576 // Only do this if we would otherwise not pass it to the user. In that
3577 // case, the PhoneWindow class will do the same thing, except it will
3578 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07003579 // Note that we need to make a copy of the key event here because the
3580 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07003581 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07003582 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
3583 new KeyEvent(event));
3584 msg.setAsynchronous(true);
3585 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07003586 }
3587 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003588 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003589
Jeff Brown4d396052010-10-29 21:50:21 -07003590 case KeyEvent.KEYCODE_CALL: {
3591 if (down) {
3592 ITelephony telephonyService = getTelephonyService();
3593 if (telephonyService != null) {
3594 try {
3595 if (telephonyService.isRinging()) {
3596 Log.i(TAG, "interceptKeyBeforeQueueing:"
3597 + " CALL key-down while ringing: Answer the call!");
3598 telephonyService.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003599
Jeff Brown4d396052010-10-29 21:50:21 -07003600 // And *don't* pass this key thru to the current activity
3601 // (which is presumably the InCallScreen.)
3602 result &= ~ACTION_PASS_TO_USER;
3603 }
3604 } catch (RemoteException ex) {
3605 Log.w(TAG, "ITelephony threw RemoteException", ex);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003606 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003607 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003608 }
Jeff Brown4d396052010-10-29 21:50:21 -07003609 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003610 }
3611 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003612 return result;
3613 }
3614
Jeff Brown1c2e4942012-11-06 16:32:01 -08003615 /**
3616 * When the screen is off we ignore some keys that might otherwise typically
3617 * be considered wake keys. We filter them out here.
3618 *
3619 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
3620 * is always considered a wake key.
3621 */
3622 private boolean isWakeKeyWhenScreenOff(int keyCode) {
3623 switch (keyCode) {
3624 // ignore volume keys unless docked
3625 case KeyEvent.KEYCODE_VOLUME_UP:
3626 case KeyEvent.KEYCODE_VOLUME_DOWN:
3627 case KeyEvent.KEYCODE_VOLUME_MUTE:
3628 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
3629
3630 // ignore media and camera keys
3631 case KeyEvent.KEYCODE_MUTE:
3632 case KeyEvent.KEYCODE_HEADSETHOOK:
3633 case KeyEvent.KEYCODE_MEDIA_PLAY:
3634 case KeyEvent.KEYCODE_MEDIA_PAUSE:
3635 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3636 case KeyEvent.KEYCODE_MEDIA_STOP:
3637 case KeyEvent.KEYCODE_MEDIA_NEXT:
3638 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
3639 case KeyEvent.KEYCODE_MEDIA_REWIND:
3640 case KeyEvent.KEYCODE_MEDIA_RECORD:
3641 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
3642 case KeyEvent.KEYCODE_CAMERA:
3643 return false;
3644 }
3645 return true;
3646 }
3647
3648
Jeff Brown56194eb2011-03-02 19:23:13 -08003649 /** {@inheritDoc} */
3650 @Override
3651 public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
3652 int result = 0;
3653
3654 final boolean isWakeMotion = (policyFlags
3655 & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
3656 if (isWakeMotion) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003657 if (mKeyguardMediator != null && mKeyguardMediator.isShowing()) {
Jeff Brown56194eb2011-03-02 19:23:13 -08003658 // If the keyguard is showing, let it decide what to do with the wake motion.
3659 mKeyguardMediator.onWakeMotionWhenKeyguardShowingTq();
3660 } else {
3661 // Otherwise, wake the device ourselves.
Jeff Brown96307042012-07-27 15:51:34 -07003662 result |= ACTION_WAKE_UP;
Jeff Brown56194eb2011-03-02 19:23:13 -08003663 }
3664 }
3665 return result;
3666 }
3667
Jeff Brown40013652012-05-16 21:22:36 -07003668 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
3669 if (DEBUG_INPUT) {
3670 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003671 }
3672
Jeff Brown40013652012-05-16 21:22:36 -07003673 if (mHavePendingMediaKeyRepeatWithWakeLock) {
3674 if (DEBUG_INPUT) {
3675 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
3676 }
3677
3678 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
3679 mHavePendingMediaKeyRepeatWithWakeLock = false;
3680 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
3681 }
3682
3683 dispatchMediaKeyWithWakeLockToAudioService(event);
3684
3685 if (event.getAction() == KeyEvent.ACTION_DOWN
3686 && event.getRepeatCount() == 0) {
3687 mHavePendingMediaKeyRepeatWithWakeLock = true;
3688
3689 Message msg = mHandler.obtainMessage(
3690 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
3691 msg.setAsynchronous(true);
3692 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
3693 } else {
3694 mBroadcastWakeLock.release();
3695 }
3696 }
3697
3698 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
3699 mHavePendingMediaKeyRepeatWithWakeLock = false;
3700
3701 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
3702 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
3703 if (DEBUG_INPUT) {
3704 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
3705 }
3706
3707 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
3708 mBroadcastWakeLock.release();
3709 }
3710
3711 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
3712 if (ActivityManagerNative.isSystemReady()) {
3713 IAudioService audioService = getAudioService();
3714 if (audioService != null) {
3715 try {
3716 audioService.dispatchMediaKeyEventUnderWakelock(event);
3717 } catch (RemoteException e) {
3718 Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
Jean-Michel Trivic6802222012-04-30 11:15:03 -07003719 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003720 }
3721 }
3722 }
3723
Mike Lockwood1753f7f2009-08-24 14:49:07 -07003724 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
3725 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07003726 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
3727 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
3728 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Dianne Hackborn80fa1662009-10-07 14:02:10 -07003729 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003730 updateRotation(true);
Mike Lockwoode9867d22009-09-20 01:59:02 -04003731 updateOrientationListenerLp();
Mike Lockwood1753f7f2009-08-24 14:49:07 -07003732 }
3733 };
3734
Jeff Brown6aaf2952012-10-05 16:01:08 -07003735 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
3736 @Override
3737 public void onReceive(Context context, Intent intent) {
3738 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
3739 if (mKeyguardMediator != null) {
3740 mKeyguardMediator.onDreamingStarted();
3741 }
3742 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
3743 if (mKeyguardMediator != null) {
3744 mKeyguardMediator.onDreamingStopped();
3745 }
3746 }
3747 }
3748 };
3749
Christopher Tate5e08af02012-09-21 17:17:22 -07003750 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
3751 @Override
3752 public void onReceive(Context context, Intent intent) {
3753 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
3754 // tickle the settings observer: this first ensures that we're
3755 // observing the relevant settings for the newly-active user,
3756 // and then updates our own bookkeeping based on the now-
3757 // current user.
3758 mSettingsObserver.onChange(false);
3759 }
3760 }
3761 };
3762
Jeff Brownc38c9be2012-10-04 13:16:19 -07003763 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003764 public void screenTurnedOff(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07003765 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07003766 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003767 mScreenOnEarly = false;
3768 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07003769 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003770 if (mKeyguardMediator != null) {
3771 mKeyguardMediator.onScreenTurnedOff(why);
3772 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07003773 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07003774 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05003775 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07003776 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003777 }
3778
Jeff Brownc38c9be2012-10-04 13:16:19 -07003779 @Override
Dianne Hackborn38e29a62011-09-18 14:43:08 -07003780 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07003781 EventLog.writeEvent(70000, 1);
Dianne Hackborn40011092011-09-22 13:37:48 -07003782 if (false) {
3783 RuntimeException here = new RuntimeException("here");
3784 here.fillInStackTrace();
3785 Slog.i(TAG, "Screen turning on...", here);
3786 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07003787
The Android Open Source Project0727d222009-03-11 12:11:58 -07003788 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003789 mScreenOnEarly = true;
The Android Open Source Project0727d222009-03-11 12:11:58 -07003790 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05003791 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07003792 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07003793
Jeff Brownc38c9be2012-10-04 13:16:19 -07003794 waitForKeyguard(screenOnListener);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003795 }
3796
Jeff Brownc38c9be2012-10-04 13:16:19 -07003797 private void waitForKeyguard(final ScreenOnListener screenOnListener) {
3798 if (mKeyguardMediator != null) {
3799 if (screenOnListener != null) {
3800 mKeyguardMediator.onScreenTurnedOn(new KeyguardViewManager.ShowListener() {
3801 @Override
3802 public void onShown(IBinder windowToken) {
3803 waitForKeyguardWindowDrawn(windowToken, screenOnListener);
3804 }
3805 });
3806 return;
3807 } else {
3808 mKeyguardMediator.onScreenTurnedOn(null);
3809 }
3810 } else {
3811 Slog.i(TAG, "No keyguard mediator!");
3812 }
3813 finishScreenTurningOn(screenOnListener);
3814 }
3815
3816 private void waitForKeyguardWindowDrawn(IBinder windowToken,
3817 final ScreenOnListener screenOnListener) {
3818 if (windowToken != null) {
3819 try {
3820 if (mWindowManager.waitForWindowDrawn(
3821 windowToken, new IRemoteCallback.Stub() {
3822 @Override
3823 public void sendResult(Bundle data) {
3824 Slog.i(TAG, "Lock screen displayed!");
3825 finishScreenTurningOn(screenOnListener);
3826 }
3827 })) {
3828 return;
3829 }
3830 } catch (RemoteException ex) {
3831 // Can't happen in system process.
3832 }
3833 }
3834
3835 Slog.i(TAG, "No lock screen!");
3836 finishScreenTurningOn(screenOnListener);
3837 }
3838
3839 private void finishScreenTurningOn(ScreenOnListener screenOnListener) {
3840 synchronized (mLock) {
3841 mScreenOnFully = true;
3842 }
3843
Jeff Brown4fc45272012-10-10 18:28:14 -07003844 try {
3845 mWindowManager.setEventDispatching(true);
3846 } catch (RemoteException unhandled) {
3847 }
3848
Jeff Brownc38c9be2012-10-04 13:16:19 -07003849 if (screenOnListener != null) {
3850 screenOnListener.onScreenOn();
3851 }
3852 }
3853
3854 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003855 public boolean isScreenOnEarly() {
3856 return mScreenOnEarly;
3857 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07003858
3859 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003860 public boolean isScreenOnFully() {
3861 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08003862 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07003863
Dianne Hackborn08743722009-12-21 12:16:51 -08003864 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003865 public void enableKeyguard(boolean enabled) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003866 if (mKeyguardMediator != null) {
3867 mKeyguardMediator.setKeyguardEnabled(enabled);
3868 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003869 }
3870
3871 /** {@inheritDoc} */
3872 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003873 if (mKeyguardMediator != null) {
3874 mKeyguardMediator.verifyUnlock(callback);
3875 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003876 }
3877
Mike Lockwoodf7913302009-11-28 22:27:10 -05003878 private boolean keyguardIsShowingTq() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003879 if (mKeyguardMediator == null) return false;
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -08003880 return mKeyguardMediator.isShowingAndNotHidden();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003881 }
3882
Mike Lockwood520d8bc2011-02-18 13:23:13 -05003883
3884 /** {@inheritDoc} */
3885 public boolean isKeyguardLocked() {
3886 return keyguardOn();
3887 }
3888
3889 /** {@inheritDoc} */
3890 public boolean isKeyguardSecure() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003891 if (mKeyguardMediator == null) return false;
Mike Lockwood520d8bc2011-02-18 13:23:13 -05003892 return mKeyguardMediator.isSecure();
3893 }
3894
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003895 /** {@inheritDoc} */
3896 public boolean inKeyguardRestrictedKeyInputMode() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003897 if (mKeyguardMediator == null) return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003898 return mKeyguardMediator.isInputRestricted();
3899 }
3900
Dianne Hackborn90c52de2011-09-23 12:57:44 -07003901 public void dismissKeyguardLw() {
Daniel Sandler1ce804392012-11-07 15:07:12 -05003902 if (mKeyguardMediator.isShowing()) {
3903 mHandler.post(new Runnable() {
3904 public void run() {
3905 if (mKeyguardMediator.isDismissable()) {
3906 // Can we just finish the keyguard straight away?
Dianne Hackborn90c52de2011-09-23 12:57:44 -07003907 mKeyguardMediator.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05003908 } else {
3909 // ask the keyguard to prompt the user to authenticate if necessary
3910 mKeyguardMediator.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07003911 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05003912 }
3913 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07003914 }
3915 }
3916
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003917 void sendCloseSystemWindows() {
3918 sendCloseSystemWindows(mContext, null);
3919 }
3920
3921 void sendCloseSystemWindows(String reason) {
3922 sendCloseSystemWindows(mContext, reason);
3923 }
3924
3925 static void sendCloseSystemWindows(Context context, String reason) {
3926 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07003927 try {
3928 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
3929 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003930 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003931 }
3932 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07003933
Jeff Brown01a98dd2011-09-20 15:08:29 -07003934 @Override
3935 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05003936 if (false) {
3937 Slog.v(TAG, "rotationForOrientationLw(orient="
3938 + orientation + ", last=" + lastRotation
3939 + "); user=" + mUserRotation + " "
3940 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
3941 ? "USER_ROTATION_LOCKED" : "")
3942 );
3943 }
3944
The Android Open Source Project0727d222009-03-11 12:11:58 -07003945 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07003946 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
3947 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07003948 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07003949 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003950
Jeff Browndec6cf42011-11-15 14:08:20 -08003951 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07003952 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07003953 // Ignore sensor when lid switch is open and rotation is forced.
3954 preferredRotation = mLidOpenRotation;
3955 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07003956 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07003957 // Ignore sensor when in car dock unless explicitly enabled.
3958 // This case can override the behavior of NOSENSOR, and can also
3959 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07003960 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07003961 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08003962 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
3963 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
3964 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07003965 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07003966 // Ignore sensor when in desk dock unless explicitly enabled.
3967 // This case can override the behavior of NOSENSOR, and can also
3968 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07003969 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07003970 ? sensorRotation : mDeskDockRotation;
Jeff Brown27f1d672012-10-17 18:32:34 -07003971 } else if (mHdmiPlugged && mHdmiRotationLock) {
Jeff Browneb3e4b92011-12-06 19:54:24 -08003972 // Ignore sensor when plugged into HDMI.
3973 // Note that the dock orientation overrides the HDMI orientation.
3974 preferredRotation = mHdmiRotation;
Jeff Brown207673cd2012-06-05 17:47:11 -07003975 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07003976 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
3977 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED))
3978 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
3979 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
3980 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
3981 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
3982 // Otherwise, use sensor only if requested by the application or enabled
3983 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07003984 if (mAllowAllRotations < 0) {
3985 // Can't read this during init() because the context doesn't
3986 // have display metrics at that time so we cannot determine
3987 // tablet vs. phone then.
3988 mAllowAllRotations = mContext.getResources().getBoolean(
3989 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
3990 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003991 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07003992 || mAllowAllRotations == 1
Jeff Brown01a98dd2011-09-20 15:08:29 -07003993 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR) {
3994 preferredRotation = sensorRotation;
3995 } else {
3996 preferredRotation = lastRotation;
3997 }
Jeff Brown207673cd2012-06-05 17:47:11 -07003998 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
3999 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4000 // Apply rotation lock. Does not apply to NOSENSOR.
4001 // The idea is that the user rotation expresses a weak preference for the direction
4002 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4003 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004004 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004005 } else {
4006 // No overriding preference.
4007 // We will do exactly what the application asked us to do.
4008 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004009 }
4010
Dianne Hackborne5439f22010-10-02 16:53:50 -07004011 switch (orientation) {
4012 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004013 // Return portrait unless overridden.
4014 if (isAnyPortrait(preferredRotation)) {
4015 return preferredRotation;
4016 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004017 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004018
Jeff Brown01a98dd2011-09-20 15:08:29 -07004019 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004020 // Return landscape unless overridden.
4021 if (isLandscapeOrSeascape(preferredRotation)) {
4022 return preferredRotation;
4023 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004024 return mLandscapeRotation;
4025
4026 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004027 // Return reverse portrait unless overridden.
4028 if (isAnyPortrait(preferredRotation)) {
4029 return preferredRotation;
4030 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004031 return mUpsideDownRotation;
4032
4033 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004034 // Return seascape unless overridden.
4035 if (isLandscapeOrSeascape(preferredRotation)) {
4036 return preferredRotation;
4037 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004038 return mSeascapeRotation;
4039
4040 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4041 // Return either landscape rotation.
4042 if (isLandscapeOrSeascape(preferredRotation)) {
4043 return preferredRotation;
4044 }
4045 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004046 return lastRotation;
4047 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004048 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004049
Jeff Brown01a98dd2011-09-20 15:08:29 -07004050 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4051 // Return either portrait rotation.
4052 if (isAnyPortrait(preferredRotation)) {
4053 return preferredRotation;
4054 }
4055 if (isAnyPortrait(lastRotation)) {
4056 return lastRotation;
4057 }
4058 return mPortraitRotation;
4059
4060 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004061 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4062 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004063 if (preferredRotation >= 0) {
4064 return preferredRotation;
4065 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004066 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004067 }
4068 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004069 }
4070
Jeff Brown01a98dd2011-09-20 15:08:29 -07004071 @Override
4072 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4073 switch (orientation) {
4074 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4075 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4076 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4077 return isAnyPortrait(rotation);
4078
4079 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4080 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4081 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4082 return isLandscapeOrSeascape(rotation);
4083
4084 default:
4085 return true;
4086 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004087 }
4088
Jeff Brownc0347aa2011-09-23 17:26:09 -07004089 @Override
4090 public void setRotationLw(int rotation) {
4091 mOrientationListener.setCurrentRotation(rotation);
4092 }
4093
Jeff Brown01a98dd2011-09-20 15:08:29 -07004094 private boolean isLandscapeOrSeascape(int rotation) {
4095 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004096 }
4097
Jeff Brown01a98dd2011-09-20 15:08:29 -07004098 private boolean isAnyPortrait(int rotation) {
4099 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004100 }
4101
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004102
4103 // User rotation: to be used when all else fails in assigning an orientation to the device
4104 public void setUserRotationMode(int mode, int rot) {
4105 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004106
4107 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004108 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004109 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004110 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004111 rot,
4112 UserHandle.USER_CURRENT);
4113 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004114 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004115 0,
4116 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004117 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004118 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004119 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004120 1,
4121 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004122 }
4123 }
4124
Jeff Brownac143512012-04-05 18:57:33 -07004125 public void setSafeMode(boolean safeMode) {
4126 mSafeMode = safeMode;
4127 performHapticFeedbackLw(null, safeMode
4128 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4129 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004130 }
4131
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004132 static long[] getLongIntArray(Resources r, int resid) {
4133 int[] ar = r.getIntArray(resid);
4134 if (ar == null) {
4135 return null;
4136 }
4137 long[] out = new long[ar.length];
4138 for (int i=0; i<ar.length; i++) {
4139 out[i] = ar[i];
4140 }
4141 return out;
4142 }
4143
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004144 /** {@inheritDoc} */
4145 public void systemReady() {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004146 if (mKeyguardMediator != null) {
4147 // tell the keyguard
4148 mKeyguardMediator.onSystemReady();
4149 }
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004150 synchronized (mLock) {
4151 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08004152 mSystemReady = true;
4153 mHandler.post(new Runnable() {
4154 public void run() {
4155 updateSettings();
4156 }
4157 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004158 }
4159 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07004160
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004161 /** {@inheritDoc} */
4162 public void systemBooted() {
4163 synchronized (mLock) {
4164 mSystemBooted = true;
4165 }
4166 }
4167
Dianne Hackborn661cd522011-08-22 00:26:20 -07004168 ProgressDialog mBootMsgDialog = null;
4169
4170 /** {@inheritDoc} */
4171 public void showBootMessage(final CharSequence msg, final boolean always) {
Mike Lockwoodaa5bf142011-09-21 13:03:40 -04004172 if (mHeadless) return;
Dianne Hackborn661cd522011-08-22 00:26:20 -07004173 mHandler.post(new Runnable() {
4174 @Override public void run() {
4175 if (mBootMsgDialog == null) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07004176 mBootMsgDialog = new ProgressDialog(mContext) {
4177 // This dialog will consume all events coming in to
4178 // it, to avoid it trying to do things too early in boot.
4179 @Override public boolean dispatchKeyEvent(KeyEvent event) {
4180 return true;
4181 }
4182 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
4183 return true;
4184 }
4185 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
4186 return true;
4187 }
4188 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
4189 return true;
4190 }
4191 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
4192 return true;
4193 }
4194 @Override public boolean dispatchPopulateAccessibilityEvent(
4195 AccessibilityEvent event) {
4196 return true;
4197 }
4198 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07004199 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
4200 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
4201 mBootMsgDialog.setIndeterminate(true);
4202 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004203 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004204 mBootMsgDialog.getWindow().addFlags(
4205 WindowManager.LayoutParams.FLAG_DIM_BEHIND
4206 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
4207 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08004208 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
4209 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
4210 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004211 mBootMsgDialog.setCancelable(false);
4212 mBootMsgDialog.show();
4213 }
4214 mBootMsgDialog.setMessage(msg);
4215 }
4216 });
4217 }
4218
4219 /** {@inheritDoc} */
4220 public void hideBootMessages() {
4221 mHandler.post(new Runnable() {
4222 @Override public void run() {
4223 if (mBootMsgDialog != null) {
4224 mBootMsgDialog.dismiss();
4225 mBootMsgDialog = null;
4226 }
4227 }
4228 });
4229 }
4230
Mike Lockwood28569302010-01-28 11:54:40 -05004231 /** {@inheritDoc} */
4232 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004233 // ***************************************
4234 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
4235 // ***************************************
4236 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
4237 // WITH ITS LOCKS HELD.
4238 //
4239 // This code must be VERY careful about the locks
4240 // it acquires.
4241 // In fact, the current code acquires way too many,
4242 // and probably has lurking deadlocks.
4243
Mike Lockwood28569302010-01-28 11:54:40 -05004244 synchronized (mScreenLockTimeout) {
4245 if (mLockScreenTimerActive) {
4246 // reset the timer
4247 mHandler.removeCallbacks(mScreenLockTimeout);
4248 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4249 }
4250 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04004251 }
4252
Adam Cohenf7522022012-10-03 20:03:18 -07004253 class ScreenLockTimeout implements Runnable {
4254 Bundle options;
4255
4256 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05004257 public void run() {
4258 synchronized (this) {
4259 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004260 if (mKeyguardMediator != null) {
Adam Cohenf7522022012-10-03 20:03:18 -07004261 mKeyguardMediator.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004262 }
Mike Lockwood28569302010-01-28 11:54:40 -05004263 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07004264 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05004265 }
4266 }
Mike Lockwood28569302010-01-28 11:54:40 -05004267
Adam Cohenf7522022012-10-03 20:03:18 -07004268 public void setLockOptions(Bundle options) {
4269 this.options = options;
4270 }
4271 }
4272
4273 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
4274
4275 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08004276 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
4277 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07004278 if (options != null) {
4279 // In case multiple calls are made to lockNow, we don't wipe out the options
4280 // until the runnable actually executes.
4281 mScreenLockTimeout.setLockOptions(options);
4282 }
Jim Miller93c518e2012-01-17 15:55:31 -08004283 mHandler.post(mScreenLockTimeout);
4284 }
4285
Mike Lockwood28569302010-01-28 11:54:40 -05004286 private void updateLockScreenTimeout() {
4287 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004288 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
4289 mKeyguardMediator != null && mKeyguardMediator.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05004290 if (mLockScreenTimerActive != enable) {
4291 if (enable) {
4292 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
4293 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4294 } else {
4295 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
4296 mHandler.removeCallbacks(mScreenLockTimeout);
4297 }
4298 mLockScreenTimerActive = enable;
4299 }
4300 }
4301 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004302
4303 /** {@inheritDoc} */
4304 public void enableScreenAfterBoot() {
4305 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07004306 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004307 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004308 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07004309
Jeff Brownc458ce92012-04-30 14:58:40 -07004310 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07004311 if (mLidState == LID_CLOSED && mLidControlsSleep) {
4312 mPowerManager.goToSleep(SystemClock.uptimeMillis());
4313 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004314 }
4315
4316 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004317 try {
4318 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004319 mWindowManager.updateRotation(alwaysSendConfiguration, false);
4320 } catch (RemoteException e) {
4321 // Ignore
4322 }
4323 }
4324
4325 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
4326 try {
4327 //set orientation on WindowManager
4328 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004329 } catch (RemoteException e) {
4330 // Ignore
4331 }
4332 }
4333
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004334 void startDockOrHome() {
Daniel Sandler7c135202012-09-28 14:04:59 -04004335 // 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 -07004336 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004337 }
4338
4339 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004340 * goes to the home screen
4341 * @return whether it did anything
4342 */
4343 boolean goHome() {
4344 if (false) {
4345 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07004346 try {
4347 ActivityManagerNative.getDefault().stopAppSwitches();
4348 } catch (RemoteException e) {
4349 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004350 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004351 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004352 } else {
4353 // This code brings home to the front or, if it is already
4354 // at the front, puts the device to sleep.
4355 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08004356 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
4357 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
4358 Log.d(TAG, "UTS-TEST-MODE");
4359 } else {
4360 ActivityManagerNative.getDefault().stopAppSwitches();
4361 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004362 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004363 int result = ActivityManagerNative.getDefault()
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004364 .startActivityAsUser(null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004365 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07004366 null, null, 0,
4367 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004368 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07004369 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004370 return false;
4371 }
4372 } catch (RemoteException ex) {
4373 // bummer, the activity manager, which is in this process, is dead
4374 }
4375 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004376 return true;
4377 }
4378
The Android Open Source Project0727d222009-03-11 12:11:58 -07004379 public void setCurrentOrientationLw(int newOrientation) {
4380 synchronized (mLock) {
4381 if (newOrientation != mCurrentAppOrientation) {
4382 mCurrentAppOrientation = newOrientation;
4383 updateOrientationListenerLp();
4384 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004385 }
4386 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004387
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07004388 private void performAuditoryFeedbackForAccessibilityIfNeed() {
4389 if (!isGlobalAccessibilityGestureEnabled()) {
4390 return;
4391 }
4392 AudioManager audioManager = (AudioManager) mContext.getSystemService(
4393 Context.AUDIO_SERVICE);
4394 if (audioManager.isSilentMode()) {
4395 return;
4396 }
4397 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
4398 Settings.System.DEFAULT_NOTIFICATION_URI);
4399 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
4400 ringTone.play();
4401 }
4402 private boolean isGlobalAccessibilityGestureEnabled() {
4403 return Settings.Global.getInt(mContext.getContentResolver(),
4404 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
4405 }
4406
The Android Open Source Project0727d222009-03-11 12:11:58 -07004407 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07004408 if (!mVibrator.hasVibrator()) {
4409 return false;
4410 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004411 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
4412 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Dianne Hackborn9dc06cc2009-11-17 18:19:23 -08004413 if (!always && (hapticsDisabled || mKeyguardMediator.isShowingAndNotHidden())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004414 return false;
4415 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004416 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004417 switch (effectId) {
4418 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004419 pattern = mLongPressVibePattern;
4420 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004421 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004422 pattern = mVirtualKeyVibePattern;
4423 break;
4424 case HapticFeedbackConstants.KEYBOARD_TAP:
4425 pattern = mKeyboardTapVibePattern;
4426 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004427 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004428 pattern = mSafeModeDisabledVibePattern;
4429 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004430 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004431 pattern = mSafeModeEnabledVibePattern;
4432 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08004433 default:
4434 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004435 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004436 if (pattern.length == 1) {
4437 // One-shot vibration
4438 mVibrator.vibrate(pattern[0]);
4439 } else {
4440 // Pattern vibration
4441 mVibrator.vibrate(pattern, -1);
4442 }
4443 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004444 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004445
4446 @Override
4447 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04004448 }
4449
Jeff Brownc38c9be2012-10-04 13:16:19 -07004450 @Override
4451 public void keepScreenOnStoppedLw() {
4452 if (mKeyguardMediator != null && !mKeyguardMediator.isShowingAndNotHidden()) {
4453 long curTime = SystemClock.uptimeMillis();
4454 mPowerManager.userActivity(curTime, false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004455 }
4456 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04004457
Dianne Hackborndf89e652011-10-06 22:35:11 -07004458 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08004459 // If there is no window focused, there will be nobody to handle the events
4460 // anyway, so just hang on in whatever state we're in until things settle down.
Dianne Hackborndf89e652011-10-06 22:35:11 -07004461 if (mFocusedWindow == null) {
4462 return 0;
4463 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004464 if (mFocusedWindow.getAttrs().type == TYPE_KEYGUARD && mHideLockScreen == true) {
4465 // We are updating at a point where the keyguard has gotten
4466 // focus, but we were last in a state where the top window is
4467 // hiding it. This is probably because the keyguard as been
4468 // shown while the top window was displayed, so we want to ignore
4469 // it here because this is just a very transient change and it
4470 // will quickly lose focus once it correctly gets hidden.
4471 return 0;
4472 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07004473 final int visibility = mFocusedWindow.getSystemUiVisibility()
Dianne Hackborne26ab702011-10-16 13:21:33 -07004474 & ~mResettingSystemUiFlags
4475 & ~mForceClearedSystemUiFlags;
4476 int diff = visibility ^ mLastSystemUiFlags;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08004477 final boolean needsMenu = mFocusedWindow.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08004478 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
4479 && mFocusedApp == mFocusedWindow.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004480 return 0;
4481 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07004482 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08004483 mLastFocusNeedsMenu = needsMenu;
Dianne Hackborne0f085d2011-11-30 18:41:15 -08004484 mFocusedApp = mFocusedWindow.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07004485 mHandler.post(new Runnable() {
4486 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07004487 try {
4488 IStatusBarService statusbar = getStatusBarService();
4489 if (statusbar != null) {
4490 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
4491 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08004492 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07004493 } catch (RemoteException e) {
4494 // re-acquire status bar service next time it is needed.
4495 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08004496 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07004497 }
4498 });
4499 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08004500 }
4501
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04004502 // Use this instead of checking config_showNavigationBar so that it can be consistently
4503 // overridden by qemu.hw.mainkeys in the emulator.
4504 public boolean hasNavigationBar() {
4505 return mHasNavigationBar;
4506 }
4507
satok1bc0a492012-04-25 22:47:12 +09004508 @Override
4509 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
4510 mLastInputMethodWindow = ime;
4511 mLastInputMethodTargetWindow = target;
4512 }
4513
Craig Mautnerf1b67412012-09-19 13:18:29 -07004514 @Override
4515 public boolean canMagnifyWindowLw(WindowManager.LayoutParams attrs) {
Svetoslav Ganov1cf70bb2012-08-06 10:53:34 -07004516 switch (attrs.type) {
4517 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
4518 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
4519 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
4520 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
4521 return false;
4522 }
4523 }
4524 return true;
4525 }
4526
Craig Mautnerf1b67412012-09-19 13:18:29 -07004527 @Override
4528 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
Jeff Brownd7a04de2012-06-17 14:17:52 -07004543 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004544 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004545 pw.print(" mSystemReady="); pw.print(mSystemReady);
4546 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07004547 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004548 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
4549 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07004550 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
4551 || mForceClearedSystemUiFlags != 0) {
4552 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
4553 pw.print(Integer.toHexString(mLastSystemUiFlags));
4554 pw.print(" mResettingSystemUiFlags=0x");
4555 pw.print(Integer.toHexString(mResettingSystemUiFlags));
4556 pw.print(" mForceClearedSystemUiFlags=0x");
4557 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07004558 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08004559 if (mLastFocusNeedsMenu) {
4560 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
4561 pw.println(mLastFocusNeedsMenu);
4562 }
Daniel Sandler7c135202012-09-28 14:04:59 -04004563 pw.print(prefix); pw.print("mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004564 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
4565 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
4566 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
4567 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004568 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07004569 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004570 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
4571 pw.print(mCarDockEnablesAccelerometer);
4572 pw.print(" mDeskDockEnablesAccelerometer=");
4573 pw.println(mDeskDockEnablesAccelerometer);
4574 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
4575 pw.print(mLidKeyboardAccessibility);
4576 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07004577 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
4578 pw.print(prefix); pw.print("mLongPressOnPowerBehavior=");
4579 pw.print(mLongPressOnPowerBehavior);
4580 pw.print(" mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004581 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
4582 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07004583 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004584 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
4585 pw.print(","); pw.print(mUnrestrictedScreenTop);
4586 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
4587 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
4588 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
4589 pw.print(","); pw.print(mRestrictedScreenTop);
4590 pw.print(") "); pw.print(mRestrictedScreenWidth);
4591 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004592 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
4593 pw.print(","); pw.print(mStableFullscreenTop);
4594 pw.print(")-("); pw.print(mStableFullscreenRight);
4595 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004596 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
4597 pw.print(","); pw.print(mStableTop);
4598 pw.print(")-("); pw.print(mStableRight);
4599 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07004600 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
4601 pw.print(","); pw.print(mSystemTop);
4602 pw.print(")-("); pw.print(mSystemRight);
4603 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004604 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
4605 pw.print(","); pw.print(mCurTop);
4606 pw.print(")-("); pw.print(mCurRight);
4607 pw.print(","); pw.print(mCurBottom); pw.println(")");
4608 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
4609 pw.print(","); pw.print(mContentTop);
4610 pw.print(")-("); pw.print(mContentRight);
4611 pw.print(","); pw.print(mContentBottom); pw.println(")");
4612 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
4613 pw.print(","); pw.print(mDockTop);
4614 pw.print(")-("); pw.print(mDockRight);
4615 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07004616 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
4617 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004618 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
4619 pw.print(" mShowingDream="); pw.print(mShowingDream);
4620 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07004621 if (mLastInputMethodWindow != null) {
4622 pw.print(prefix); pw.print("mLastInputMethodWindow=");
4623 pw.println(mLastInputMethodWindow);
4624 }
4625 if (mLastInputMethodTargetWindow != null) {
4626 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
4627 pw.println(mLastInputMethodTargetWindow);
4628 }
4629 if (mStatusBar != null) {
4630 pw.print(prefix); pw.print("mStatusBar=");
4631 pw.println(mStatusBar);
4632 }
4633 if (mNavigationBar != null) {
4634 pw.print(prefix); pw.print("mNavigationBar=");
4635 pw.println(mNavigationBar);
4636 }
4637 if (mKeyguard != null) {
4638 pw.print(prefix); pw.print("mKeyguard=");
4639 pw.println(mKeyguard);
4640 }
4641 if (mFocusedWindow != null) {
4642 pw.print(prefix); pw.print("mFocusedWindow=");
4643 pw.println(mFocusedWindow);
4644 }
4645 if (mFocusedApp != null) {
4646 pw.print(prefix); pw.print("mFocusedApp=");
4647 pw.println(mFocusedApp);
4648 }
4649 if (mWinDismissingKeyguard != null) {
4650 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
4651 pw.println(mWinDismissingKeyguard);
4652 }
4653 if (mTopFullscreenOpaqueWindowState != null) {
4654 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
4655 pw.println(mTopFullscreenOpaqueWindowState);
4656 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004657 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004658 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004659 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
4660 pw.print(" mForceStatusBarFromKeyguard=");
4661 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004662 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004663 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004664 pw.print(" mHomePressed="); pw.println(mHomePressed);
4665 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
4666 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
4667 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
4668 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
4669 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
4670 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
4671 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
4672 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
4673 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
4674 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brown27f1d672012-10-17 18:32:34 -07004675 pw.print(prefix); pw.print("mHdmiRotation="); pw.print(mHdmiRotation);
4676 pw.print(" mHdmiRotationLock="); pw.println(mHdmiRotationLock);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08004677 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004678}