blob: 56d0ec00cbeb7e9656b3b10cce6cc7747d387a8c [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 Hackbornc2293022013-02-06 23:14:49 -080020import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040021import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070022import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070023import android.app.SearchManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080024import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070025import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080026import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040027import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080028import android.content.ContentResolver;
29import android.content.Context;
30import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070031import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070032import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080033import android.content.pm.ActivityInfo;
34import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040035import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070036import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080037import android.content.res.Configuration;
38import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070039import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080040import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080041import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080042import android.graphics.Rect;
Michael Jurka7a348952012-02-27 13:07:58 -080043import android.media.AudioManager;
44import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070045import android.media.Ringtone;
46import android.media.RingtoneManager;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070047import android.os.Bundle;
Jeff Brown9a538ee2012-08-20 14:56:57 -070048import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080049import android.os.Handler;
50import android.os.IBinder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070051import android.os.IRemoteCallback;
Jeff Brown32cbc38552011-12-01 14:01:49 -080052import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070053import android.os.Message;
54import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080055import android.os.PowerManager;
56import android.os.RemoteException;
57import android.os.ServiceManager;
58import android.os.SystemClock;
59import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080060import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070061import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080062import android.os.Vibrator;
63import android.provider.Settings;
John Spurlockc8b46ca2013-04-08 12:59:26 -040064import android.service.dreams.DreamService;
65import android.service.dreams.IDreamManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070066import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080067import android.util.EventLog;
68import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070069import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080070import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070071import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080072import android.view.Gravity;
73import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080074import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080075import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070076import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070077import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080078import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080079import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080080import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080081import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080082import android.view.KeyEvent;
83import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.view.Surface;
85import android.view.View;
86import android.view.ViewConfiguration;
87import android.view.Window;
88import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080089import android.view.WindowManagerGlobal;
90import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -080091import android.view.accessibility.AccessibilityEvent;
92import android.view.animation.Animation;
93import android.view.animation.AnimationUtils;
94
95import com.android.internal.R;
96import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -080097import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautnerae446592012-12-06 19:05:05 -080098import com.android.internal.statusbar.IStatusBarService;
99import com.android.internal.telephony.ITelephony;
100import com.android.internal.widget.PointerLocationView;
101
102import java.io.File;
103import java.io.FileReader;
104import java.io.IOException;
105import java.io.PrintWriter;
John Spurlockad3e6cb2013-04-30 08:47:43 -0400106import java.util.HashSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800107
Dianne Hackbornc652de82013-02-15 16:32:56 -0800108import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700109import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
110import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
111import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800112
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800113/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700114 * WindowManagerPolicy implementation for the Android phone UI. This
115 * introduces a new method suffix, Lp, for an internal lock of the
116 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400117 * can be acquired with either the Lw and Li lock held, so has the restrictions
The Android Open Source Project0727d222009-03-11 12:11:58 -0700118 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800119 */
120public class PhoneWindowManager implements WindowManagerPolicy {
121 static final String TAG = "WindowManager";
122 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700123 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700124 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700125 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700126 static final boolean DEBUG_STARTING_WINDOW = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800127 static final boolean SHOW_STARTING_ANIMATIONS = true;
128 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400129
Daniel Sandler6396c722013-04-16 20:19:09 -0400130 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
131 // No longer recommended for desk docks; still useful in car docks.
132 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
133 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
134
Joe Onoratod208e702010-10-08 16:22:43 -0400135 static final int LONG_PRESS_POWER_NOTHING = 0;
136 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
137 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700138 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700139
140 // These need to match the documentation/constant in
141 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800142 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800143 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700144 static final int LONG_PRESS_HOME_ASSIST = 2;
145
146 static final int DOUBLE_TAP_HOME_NOTHING = 0;
147 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800148
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700149 static final int APPLICATION_MEDIA_SUBLAYER = -2;
150 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800151 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800152 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700153
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800154 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
155 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
156 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500157 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700158 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800159
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700160 /**
161 * These are the system UI flags that, when changing, can cause the layout
162 * of the screen to change.
163 */
164 static final int SYSTEM_UI_CHANGING_LAYOUT =
165 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;
166
Jim Miller5ecd8112013-01-09 18:50:26 -0800167 /**
168 * Keyguard stuff
169 */
170 private WindowState mKeyguardScrim;
171
Jeff Brown6651a632011-11-28 12:59:11 -0800172 /* Table of Application Launch keys. Maps from key codes to intent categories.
173 *
174 * These are special keys that are used to launch particular kinds of applications,
175 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
176 * usage page. We don't support quite that many yet...
177 */
178 static SparseArray<String> sApplicationLaunchKeyCategories;
179 static {
180 sApplicationLaunchKeyCategories = new SparseArray<String>();
181 sApplicationLaunchKeyCategories.append(
182 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
183 sApplicationLaunchKeyCategories.append(
184 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
185 sApplicationLaunchKeyCategories.append(
186 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
187 sApplicationLaunchKeyCategories.append(
188 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
189 sApplicationLaunchKeyCategories.append(
190 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
191 sApplicationLaunchKeyCategories.append(
192 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
193 }
194
Dianne Hackborndf89e652011-10-06 22:35:11 -0700195 /**
196 * Lock protecting internal state. Must not call out into window
197 * manager with lock held. (This lock will be acquired in places
198 * where the window manager is calling in with its own lock held.)
199 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800200 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700201
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800202 Context mContext;
203 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700204 WindowManagerFuncs mWindowManagerFuncs;
Jeff Brown96307042012-07-27 15:51:34 -0700205 PowerManager mPowerManager;
Joe Onorato93056472010-09-10 10:30:46 -0400206 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700207 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700208 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800209 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700210 SearchManager mSearchManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800211
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700212 // Vibrator pattern for haptic feedback of a long press.
213 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700214
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700215 // Vibrator pattern for haptic feedback of virtual key press.
216 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700217
Amith Yamasanic33cb712010-02-10 15:21:49 -0800218 // Vibrator pattern for a short vibration.
219 long[] mKeyboardTapVibePattern;
220
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700221 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
222 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700223
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700224 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
225 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700226
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800227 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
228 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400229
230 boolean mHeadless;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800231 boolean mSafeMode;
232 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700233 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400234 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400235 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700236 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400237 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
238 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
239 int[] mNavigationBarHeightForRotation = new int[4];
240 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400241
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800242 WindowState mKeyguard = null;
Jim Miller5ecd8112013-01-09 18:50:26 -0800243 KeyguardServiceDelegate mKeyguardDelegate;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800244 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700245 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
246 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800247 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900248 WindowState mLastInputMethodWindow = null;
249 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800250
Jeff Brown68b909d2011-12-07 16:36:01 -0800251 static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0;
252 static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1;
Jeff Brown602ab322012-05-16 13:33:47 -0700253 static final int RECENT_APPS_BEHAVIOR_DISMISS = 2;
254 static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 3;
Jeff Brown68b909d2011-12-07 16:36:01 -0800255
256 RecentApplicationsDialog mRecentAppsDialog;
257 int mRecentAppsDialogHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700258 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800259
Jeff Brown2e7760e2012-04-11 15:14:55 -0700260 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700261 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800262
Dianne Hackbornc777e072010-02-12 13:07:59 -0800263 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700264 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800265 boolean mHdmiPlugged;
Daniel Sandler6396c722013-04-16 20:19:09 -0400266 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700267 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700268 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400269 int mCarDockRotation;
270 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700271 int mUndockedHdmiRotation;
272 int mDemoHdmiRotation;
273 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400274
275 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
276 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700277 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400278
Jeff Brownd3187e32011-09-21 19:26:44 -0700279 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400280 boolean mCarDockEnablesAccelerometer;
281 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700282 int mLidKeyboardAccessibility;
283 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700284 boolean mLidControlsSleep;
Joe Onoratod208e702010-10-08 16:22:43 -0400285 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700286 boolean mScreenOnEarly = false;
287 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800288 boolean mOrientationSensorEnabled = false;
289 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800290 boolean mHasSoftInput = false;
Craig Mautner967212c2013-04-13 21:10:58 -0700291
Jeff Brown70825162012-03-28 17:27:48 -0700292 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800293
294 // The last window we were told about in focusChanged.
295 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800296 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800297
Craig Mautner037aa8d2013-06-07 10:35:44 -0700298 private final class PointerLocationPointerEventListener implements PointerEventListener {
Jeff Browna41ca772010-08-11 14:46:32 -0700299 @Override
Craig Mautner037aa8d2013-06-07 10:35:44 -0700300 public void onPointerEvent(MotionEvent motionEvent) {
301 if (mPointerLocationView != null) {
302 mPointerLocationView.addPointerEvent(motionEvent);
Jeff Browna41ca772010-08-11 14:46:32 -0700303 }
304 }
Jeff Brown32cbc38552011-12-01 14:01:49 -0800305 }
Jeff Brown70825162012-03-28 17:27:48 -0700306
307 // Pointer location view state, only modified on the mHandler Looper.
Craig Mautner037aa8d2013-06-07 10:35:44 -0700308 PointerLocationPointerEventListener mPointerLocationPointerEventListener;
Jeff Brown70825162012-03-28 17:27:48 -0700309 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800310
Dianne Hackbornc652de82013-02-15 16:32:56 -0800311 // The current size of the screen; really; extends into the overscan area of
312 // the screen and doesn't account for any system elements like the status bar.
313 int mOverscanScreenLeft, mOverscanScreenTop;
314 int mOverscanScreenWidth, mOverscanScreenHeight;
315 // The current visible size of the screen; really; (ir)regardless of whether the status
316 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800317 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
318 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800319 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
320 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
321 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700322 // The current size of the screen; these may be different than (0,0)-(dw,dh)
323 // if the status bar can't be hidden; in that case it effectively carves out
324 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800325 int mRestrictedScreenLeft, mRestrictedScreenTop;
326 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700327 // During layout, the current screen borders accounting for any currently
328 // visible system UI elements.
329 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700330 // For applications requesting stable content insets, these are them.
331 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700332 // For applications requesting stable content insets but have also set the
333 // fullscreen window flag, these are the stable dimensions without the status bar.
334 int mStableFullscreenLeft, mStableFullscreenTop;
335 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800336 // During layout, the current screen borders with all outer decoration
337 // (status bar, input method dock) accounted for.
338 int mCurLeft, mCurTop, mCurRight, mCurBottom;
339 // During layout, the frame in which content should be displayed
340 // to the user, accounting for all screen decoration except for any
341 // space they deem as available for other content. This is usually
342 // the same as mCur*, but may be larger if the screen decor has supplied
343 // content insets.
344 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800345 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800346 // windows are placed.
347 int mDockLeft, mDockTop, mDockRight, mDockBottom;
348 // During layout, the layer at which the doc window is placed.
349 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700350 // During layout, this is the layer of the status bar.
351 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700352 int mLastSystemUiFlags;
353 // Bits that we are in the process of clearing, so we want to prevent
354 // them from being set by applications until everything has been updated
355 // to have them clear.
356 int mResettingSystemUiFlags = 0;
357 // Bits that we are currently always keeping cleared.
358 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800359 // What we last reported to system UI about whether the compatibility
360 // menu needs to be displayed.
361 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700362
363 FakeWindow mHideNavFakeWindow = null;
364
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800365 static final Rect mTmpParentFrame = new Rect();
366 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800367 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800368 static final Rect mTmpContentFrame = new Rect();
369 static final Rect mTmpVisibleFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700370 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700371
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800372 WindowState mTopFullscreenOpaqueWindowState;
Joe Onorato93056472010-09-10 10:30:46 -0400373 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800374 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700375 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700376 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800377 boolean mForcingShowNavBar;
378 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700379
380 // States of keyguard dismiss.
381 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
382 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
383 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
384 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
385
386 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
387 * be done once per window. */
388 private WindowState mWinDismissingKeyguard;
389
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700390 boolean mShowingLockscreen;
391 boolean mShowingDream;
392 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800393 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700394 boolean mHomeConsumed;
395 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800396 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700397 Intent mCarDockIntent;
398 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700399 boolean mSearchKeyShortcutPending;
400 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700401 boolean mAssistKeyLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800402
Mike Lockwood28569302010-01-28 11:54:40 -0500403 // support for activating the lock screen while the screen is on
404 boolean mAllowLockscreenWhenOn;
405 int mLockScreenTimeout;
406 boolean mLockScreenTimerActive;
407
David Brownbaf8d092010-03-08 21:52:59 -0800408 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800409 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800410
411 // Behavior of POWER button while in-call and screen on.
412 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
413 int mIncallPowerBehavior;
414
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700415 Display mDisplay;
416
Dianne Hackborn9d132642011-04-21 17:26:39 -0700417 int mLandscapeRotation = 0; // default landscape rotation
418 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
419 int mPortraitRotation = 0; // default portrait rotation
420 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700421
Dianne Hackbornc652de82013-02-15 16:32:56 -0800422 int mOverscanLeft = 0;
423 int mOverscanTop = 0;
424 int mOverscanRight = 0;
425 int mOverscanBottom = 0;
426
Joe Onorato46b0d682010-11-22 17:37:27 -0800427 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700428 private int mLongPressOnHomeBehavior;
429
430 // What we do when the user double-taps on home
431 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800432
Winson Chung9112ec32011-06-27 13:15:32 -0700433 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700434 // Time to volume and power must be pressed within this interval of each other.
435 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700436 // Increase the chord delay when taking a screenshot from the keyguard
437 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800438 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700439 private boolean mVolumeDownKeyTriggered;
440 private long mVolumeDownKeyTime;
441 private boolean mVolumeDownKeyConsumedByScreenshotChord;
442 private boolean mVolumeUpKeyTriggered;
443 private boolean mPowerKeyTriggered;
444 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700445
Michael Wrightb854e242013-02-05 17:54:02 -0800446 /* The number of steps between min and max brightness */
447 private static final int BRIGHTNESS_STEPS = 10;
448
Christopher Tate5e08af02012-09-21 17:17:22 -0700449 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800450 ShortcutManager mShortcutManager;
451 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700452 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800453
Justin Kohd378ad72013-04-01 12:18:26 -0700454 // Maps global key codes to the components that will handle them.
455 private GlobalKeyManager mGlobalKeyManager;
456
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700457 // Fallback actions by key code.
458 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
459 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800460
Jeff Brown70825162012-03-28 17:27:48 -0700461 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
462 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700463 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
464 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Jeff Brown70825162012-03-28 17:27:48 -0700465
466 private class PolicyHandler extends Handler {
467 @Override
468 public void handleMessage(Message msg) {
469 switch (msg.what) {
470 case MSG_ENABLE_POINTER_LOCATION:
471 enablePointerLocation();
472 break;
473 case MSG_DISABLE_POINTER_LOCATION:
474 disablePointerLocation();
475 break;
Jeff Brown40013652012-05-16 21:22:36 -0700476 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
477 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
478 break;
479 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
480 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
481 break;
Jeff Brown70825162012-03-28 17:27:48 -0700482 }
483 }
484 }
485
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800486 private UEventObserver mHDMIObserver = new UEventObserver() {
487 @Override
488 public void onUEvent(UEventObserver.UEvent event) {
489 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
490 }
491 };
492
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800493 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800494 SettingsObserver(Handler handler) {
495 super(handler);
496 }
David Brownbaf8d092010-03-08 21:52:59 -0800497
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800498 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700499 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800500 ContentResolver resolver = mContext.getContentResolver();
501 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700502 Settings.System.END_BUTTON_BEHAVIOR), false, this,
503 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800504 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700505 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
506 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800507 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700508 Settings.System.ACCELEROMETER_ROTATION), false, this,
509 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500510 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700511 Settings.System.USER_ROTATION), false, this,
512 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400513 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700514 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
515 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800516 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700517 Settings.System.POINTER_LOCATION), false, this,
518 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800519 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700520 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
521 UserHandle.USER_ALL);
Dianne Hackborn03759ed2009-03-27 16:04:08 -0700522 resolver.registerContentObserver(Settings.System.getUriFor(
John Spurlock245fd012013-05-31 10:31:04 -0400523 OverlayTesting.ENABLED_SETTING), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700524 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800525 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800526 }
527
528 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800529 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700530 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800531 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800532 }
Craig Mautner967212c2013-04-13 21:10:58 -0700533
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800534 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800535 MyOrientationListener(Context context, Handler handler) {
536 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800537 }
Craig Mautner967212c2013-04-13 21:10:58 -0700538
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800539 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700540 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700541 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700542 updateRotation(false);
543 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800544 }
545 MyOrientationListener mOrientationListener;
546
John Spurlockad3e6cb2013-04-30 08:47:43 -0400547 private static final int HIDEYBAR_NONE = 0;
548 private static final int HIDEYBAR_SHOWING = 1;
549 private static final int HIDEYBAR_HIDING = 2;
550 private int mStatusHideybar;
551 private int mNavigationHideybar;
John Spurlock32beb2c2013-03-11 10:16:47 -0400552
Craig Mautner037aa8d2013-06-07 10:35:44 -0700553 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400554
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700555 IStatusBarService getStatusBarService() {
556 synchronized (mServiceAquireLock) {
557 if (mStatusBarService == null) {
558 mStatusBarService = IStatusBarService.Stub.asInterface(
559 ServiceManager.getService("statusbar"));
560 }
561 return mStatusBarService;
562 }
563 }
564
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700565 /*
566 * We always let the sensor be switched on by default except when
567 * the user has explicitly disabled sensor based rotation or when the
568 * screen is switched off.
569 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700570 boolean needSensorRunningLp() {
Dianne Hackborne5439f22010-10-02 16:53:50 -0700571 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
572 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
573 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
574 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800575 // If the application has explicitly requested to follow the
576 // orientation, then we need to turn the sensor or.
577 return true;
578 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700579 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800580 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
581 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
582 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400583 // enable accelerometer if we are docked in a dock that enables accelerometer
584 // orientation management,
585 return true;
586 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700587 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800588 // If the setting for using the sensor by default is enabled, then
589 // we will always leave it on. Note that the user could go to
590 // a window that forces an orientation that does not use the
591 // sensor and in theory we could turn it off... however, when next
592 // turning it on we won't have a good value for the current
593 // orientation for a little bit, which can cause orientation
594 // changes to lag, so we'd like to keep it always on. (It will
595 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700596 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800597 }
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700598 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800599 }
600
601 /*
602 * Various use cases for invoking this function
603 * screen turning off, should always disable listeners if already enabled
604 * screen turned on and current app has sensor based orientation, enable listeners
605 * if not already enabled
606 * screen turned on and current app does not have sensor orientation, disable listeners if
607 * already enabled
608 * screen turning on and current app has sensor based orientation, enable listeners if needed
609 * screen turning on and current app has nosensor based orientation, do nothing
610 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700611 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800612 if (!mOrientationListener.canDetectOrientation()) {
613 // If sensor is turned off or nonexistent for some reason
614 return;
615 }
616 //Could have been invoked due to screen turning on or off or
617 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700618 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800619 ", current orientation="+mCurrentAppOrientation+
620 ", SensorEnabled="+mOrientationSensorEnabled);
621 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700622 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700623 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800624 disable = false;
625 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700626 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800627 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700628 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800629 mOrientationSensorEnabled = true;
630 }
631 }
632 }
633 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700634 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800635 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700636 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800637 mOrientationSensorEnabled = false;
638 }
639 }
640
Jeff Brown4d396052010-10-29 21:50:21 -0700641 private void interceptPowerKeyDown(boolean handled) {
642 mPowerKeyHandled = handled;
643 if (!handled) {
644 mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
645 }
646 }
647
648 private boolean interceptPowerKeyUp(boolean canceled) {
649 if (!mPowerKeyHandled) {
650 mHandler.removeCallbacks(mPowerLongPress);
651 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700652 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700653 return false;
654 }
655
656 private void cancelPendingPowerKeyAction() {
657 if (!mPowerKeyHandled) {
658 mHandler.removeCallbacks(mPowerLongPress);
659 }
Jeff Brownff204712011-10-25 21:27:54 -0700660 if (mPowerKeyTriggered) {
661 mPendingPowerKeyUpCanceled = true;
662 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700663 }
664
665 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800666 if (mScreenshotChordEnabled
667 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700668 final long now = SystemClock.uptimeMillis();
669 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
670 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
671 mVolumeDownKeyConsumedByScreenshotChord = true;
672 cancelPendingPowerKeyAction();
673
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800674 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700675 }
676 }
677 }
678
Winson Chung1cea2f32012-10-08 20:42:01 -0700679 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800680 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700681 // Double the time it takes to take a screenshot from the keyguard
682 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
683 ViewConfiguration.getGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700684 }
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800685 return ViewConfiguration.getGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700686 }
687
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700688 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800689 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700690 }
691
692 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700693 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800694 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700695 // The context isn't read
696 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700697 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
698 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400699 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700700 int resolvedBehavior = mLongPressOnPowerBehavior;
701 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
702 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
703 }
704
705 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700706 case LONG_PRESS_POWER_NOTHING:
707 break;
708 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
709 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700710 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
711 performAuditoryFeedbackForAccessibilityIfNeed();
712 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700713 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
714 showGlobalActionsDialog();
715 break;
716 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700717 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700718 mPowerKeyHandled = true;
719 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
720 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700721 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700722 break;
723 }
724 }
725 };
726
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800727 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800728 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700729 public void run() {
730 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800731 }
732 };
733
734 void showGlobalActionsDialog() {
735 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700736 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800737 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700738 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800739 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
740 if (keyguardShowing) {
741 // since it took two seconds of long press to bring this up,
742 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800743 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800744 }
745 }
746
747 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700748 return Settings.Global.getInt(
749 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800750 }
751
Patrick Dubroyece94522011-02-23 18:35:01 -0800752 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800753 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700754 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800755 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800756
Jeff Browncaca8812013-05-09 13:34:33 -0700757 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
758 toggleRecentApps();
759 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
760 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700761 }
762 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800763 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800764
Jeff Browncaca8812013-05-09 13:34:33 -0700765 private void handleDoubleTapOnHome() {
766 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
767 mHomeConsumed = true;
768 toggleRecentApps();
769 }
770 }
771
772 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
773 @Override
774 public void run() {
775 if (mHomeDoubleTapPending) {
776 mHomeDoubleTapPending = false;
777 launchHomeFromHotKey();
778 }
779 }
780 };
781
Patrick Dubroyece94522011-02-23 18:35:01 -0800782 /**
Jeff Brown68b909d2011-12-07 16:36:01 -0800783 * Create (if necessary) and show or dismiss the recent apps dialog according
784 * according to the requested behavior.
Patrick Dubroyece94522011-02-23 18:35:01 -0800785 */
Jeff Brown68b909d2011-12-07 16:36:01 -0800786 void showOrHideRecentAppsDialog(final int behavior) {
Jeff Brownda3d5a92011-03-29 15:11:34 -0700787 mHandler.post(new Runnable() {
788 @Override
789 public void run() {
790 if (mRecentAppsDialog == null) {
Jeff Brown54875002011-04-06 15:33:01 -0700791 mRecentAppsDialog = new RecentApplicationsDialog(mContext);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700792 }
Jeff Brown54875002011-04-06 15:33:01 -0700793 if (mRecentAppsDialog.isShowing()) {
Jeff Brown68b909d2011-12-07 16:36:01 -0800794 switch (behavior) {
795 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
Jeff Brown602ab322012-05-16 13:33:47 -0700796 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800797 mRecentAppsDialog.dismiss();
798 break;
799 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
800 mRecentAppsDialog.dismissAndSwitch();
801 break;
802 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
803 default:
804 break;
Jeff Brown54875002011-04-06 15:33:01 -0700805 }
806 } else {
Jeff Brown68b909d2011-12-07 16:36:01 -0800807 switch (behavior) {
808 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
809 mRecentAppsDialog.show();
810 break;
811 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
812 try {
813 mWindowManager.setInTouchMode(false);
814 } catch (RemoteException e) {
815 }
816 mRecentAppsDialog.show();
817 break;
Jeff Brown602ab322012-05-16 13:33:47 -0700818 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800819 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
820 default:
821 break;
822 }
Jeff Brown54875002011-04-06 15:33:01 -0700823 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700824 }
825 });
Patrick Dubroyece94522011-02-23 18:35:01 -0800826 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700827
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800828 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800829 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800830 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700831 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800832 mContext = context;
833 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700834 mWindowManagerFuncs = windowManagerFuncs;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400835 mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
Jeff Brown70825162012-03-28 17:27:48 -0700836 mHandler = new PolicyHandler();
Craig Mautnereee29c42013-01-17 14:44:34 -0800837 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700838 try {
839 mOrientationListener.setCurrentRotation(windowManager.getRotation());
840 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700841 mSettingsObserver = new SettingsObserver(mHandler);
842 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800843 mShortcutManager = new ShortcutManager(context, mHandler);
844 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400845 mUiMode = context.getResources().getInteger(
846 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800847 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
848 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
849 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
850 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700851 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
852 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
853 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
854 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
855 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
856 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
857 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
858 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700859
Jeff Brown96307042012-07-27 15:51:34 -0700860 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
861 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800862 "PhoneWindowManager.mBroadcastWakeLock");
863 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700864 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400865 com.android.internal.R.integer.config_lidOpenRotation);
866 mCarDockRotation = readRotation(
867 com.android.internal.R.integer.config_carDockRotation);
868 mDeskDockRotation = readRotation(
869 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700870 mUndockedHdmiRotation = readRotation(
871 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400872 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
873 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
874 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
875 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700876 mLidKeyboardAccessibility = mContext.getResources().getInteger(
877 com.android.internal.R.integer.config_lidKeyboardAccessibility);
878 mLidNavigationAccessibility = mContext.getResources().getInteger(
879 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -0700880 mLidControlsSleep = mContext.getResources().getBoolean(
881 com.android.internal.R.bool.config_lidControlsSleep);
Jeff Brownf71343d2013-05-31 17:59:11 -0700882 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -0700883
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700884 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800885 IntentFilter filter = new IntentFilter();
886 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
887 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
888 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
889 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700890 filter.addAction(Intent.ACTION_DOCK_EVENT);
891 Intent intent = context.registerReceiver(mDockReceiver, filter);
892 if (intent != null) {
893 // Retrieve current sticky dock event broadcast.
894 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
895 Intent.EXTRA_DOCK_STATE_UNDOCKED);
896 }
Daniel Sandler7e37df52011-11-16 22:08:23 -0800897
Jeff Brown6aaf2952012-10-05 16:01:08 -0700898 // register for dream-related broadcasts
899 filter = new IntentFilter();
900 filter.addAction(Intent.ACTION_DREAMING_STARTED);
901 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
902 context.registerReceiver(mDreamReceiver, filter);
903
Christopher Tate5e08af02012-09-21 17:17:22 -0700904 // register for multiuser-relevant broadcasts
905 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
906 context.registerReceiver(mMultiuserReceiver, filter);
907
John Spurlock57306e62013-04-22 09:48:49 -0400908 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -0700909 mSystemGestures = new SystemGesturesPointerEventListener(context,
910 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -0400911 @Override
912 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -0400913 if (mStatusBar != null) {
914 requestHideybars(mStatusBar);
915 }
John Spurlockad3e6cb2013-04-30 08:47:43 -0400916 }
917 @Override
918 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -0400919 if (mNavigationBar != null && mNavigationBarOnBottom) {
920 requestHideybars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400921 }
922 }
923 @Override
924 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -0400925 if (mNavigationBar != null && !mNavigationBarOnBottom) {
926 requestHideybars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400927 }
928 }
929 @Override
930 public void onDebug() {
John Spurlock245fd012013-05-31 10:31:04 -0400931 if (OverlayTesting.enabled) {
John Spurlockad3e6cb2013-04-30 08:47:43 -0400932 OverlayTesting.toggleForceOverlay(mFocusedWindow, mContext);
933 }
934 }
935 });
Craig Mautner037aa8d2013-06-07 10:35:44 -0700936 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -0400937
Jeff Brownc2346132012-04-13 01:55:38 -0700938 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700939 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
940 com.android.internal.R.array.config_longPressVibePattern);
941 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
942 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -0800943 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
944 com.android.internal.R.array.config_keyboardTapVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700945 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
946 com.android.internal.R.array.config_safeModeDisabledVibePattern);
947 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
948 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -0400949
Christopher Tatee90585f2012-03-05 18:56:25 -0800950 mScreenshotChordEnabled = mContext.getResources().getBoolean(
951 com.android.internal.R.bool.config_enableScreenshotChord);
952
Justin Kohd378ad72013-04-01 12:18:26 -0700953 mGlobalKeyManager = new GlobalKeyManager(mContext);
954
Joe Onoratoea495d42011-04-06 11:41:11 -0700955 // Controls rotation and the like.
956 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -0700957
958 // Match current screen state.
959 if (mPowerManager.isScreenOn()) {
960 screenTurningOn(null);
961 } else {
962 screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
963 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700964 }
965
Jeff Brownf71343d2013-05-31 17:59:11 -0700966 /**
967 * Read values from config.xml that may be overridden depending on
968 * the configuration of the device.
969 * eg. Disable long press on home goes to recents on sw600dp.
970 */
971 private void readConfigurationDependentBehaviors() {
972 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
973 com.android.internal.R.integer.config_longPressOnHomeBehavior);
974 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
975 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
976 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
977 }
978
979 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
980 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
981 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
982 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
983 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
984 }
985 }
986
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800987 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -0700988 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Dianne Hackbornc652de82013-02-15 16:32:56 -0800989 if (display.getDisplayId() != Display.DEFAULT_DISPLAY) {
990 throw new IllegalArgumentException("Can only set the default display");
991 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700992 mDisplay = display;
993
994 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700995 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700996 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700997 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -0700998 mLandscapeRotation = Surface.ROTATION_0;
999 mSeascapeRotation = Surface.ROTATION_180;
1000 if (mContext.getResources().getBoolean(
1001 com.android.internal.R.bool.config_reverseDefaultRotation)) {
1002 mPortraitRotation = Surface.ROTATION_90;
1003 mUpsideDownRotation = Surface.ROTATION_270;
1004 } else {
1005 mPortraitRotation = Surface.ROTATION_270;
1006 mUpsideDownRotation = Surface.ROTATION_90;
1007 }
1008 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001009 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001010 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001011 mPortraitRotation = Surface.ROTATION_0;
1012 mUpsideDownRotation = Surface.ROTATION_180;
1013 if (mContext.getResources().getBoolean(
1014 com.android.internal.R.bool.config_reverseDefaultRotation)) {
1015 mLandscapeRotation = Surface.ROTATION_270;
1016 mSeascapeRotation = Surface.ROTATION_90;
1017 } else {
1018 mLandscapeRotation = Surface.ROTATION_90;
1019 mSeascapeRotation = Surface.ROTATION_270;
1020 }
1021 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001022
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001023 mStatusBarHeight = mContext.getResources().getDimensionPixelSize(
1024 com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001025
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001026 // Height of the navigation bar when presented horizontally at bottom
1027 mNavigationBarHeightForRotation[mPortraitRotation] =
1028 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Daniel Sandler4a066c52012-04-20 14:49:13 -04001029 mContext.getResources().getDimensionPixelSize(
1030 com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001031 mNavigationBarHeightForRotation[mLandscapeRotation] =
1032 mNavigationBarHeightForRotation[mSeascapeRotation] =
1033 mContext.getResources().getDimensionPixelSize(
1034 com.android.internal.R.dimen.navigation_bar_height_landscape);
1035
1036 // Width of the navigation bar when presented vertically along one side
1037 mNavigationBarWidthForRotation[mPortraitRotation] =
1038 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1039 mNavigationBarWidthForRotation[mLandscapeRotation] =
1040 mNavigationBarWidthForRotation[mSeascapeRotation] =
Daniel Sandler4a066c52012-04-20 14:49:13 -04001041 mContext.getResources().getDimensionPixelSize(
1042 com.android.internal.R.dimen.navigation_bar_width);
1043
1044 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001045 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001046
1047 if (shortSizeDp < 600) {
John Spurlock80f00c12013-06-13 11:10:51 -04001048 // Allow the navigation bar to move on small devices (phones).
Daniel Sandler4a066c52012-04-20 14:49:13 -04001049 mNavigationBarCanMove = true;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001050 }
Daniel Sandler36412a72011-08-04 09:35:13 -04001051
John Spurlock80f00c12013-06-13 11:10:51 -04001052 mHasNavigationBar = mContext.getResources().getBoolean(
1053 com.android.internal.R.bool.config_showNavigationBar);
1054 // Allow a system property to override this. Used by the emulator.
1055 // See also hasNavigationBar().
1056 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1057 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001058 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001059 } else if ("0".equals(navBarOverride)) {
1060 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001061 }
1062
John Spurlock80f00c12013-06-13 11:10:51 -04001063 if (mHasNavigationBar) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001064 // The navigation bar is at the right in landscape; it seems always
1065 // useful to hide it for showing a video.
1066 mCanHideNavigationBar = true;
1067 } else {
1068 mCanHideNavigationBar = false;
1069 }
Erik Gilling9a41ef82011-09-26 19:21:03 -07001070
Jeff Brown27f1d672012-10-17 18:32:34 -07001071 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1072 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001073 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001074 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001075 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001076 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001077 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001078 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Dianne Hackborn9d132642011-04-21 17:26:39 -07001079 }
1080
Dianne Hackbornc652de82013-02-15 16:32:56 -08001081 @Override
1082 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1083 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1084 mOverscanLeft = left;
1085 mOverscanTop = top;
1086 mOverscanRight = right;
1087 mOverscanBottom = bottom;
1088 }
1089 }
1090
Dianne Hackbornc777e072010-02-12 13:07:59 -08001091 public void updateSettings() {
1092 ContentResolver resolver = mContext.getContentResolver();
1093 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001094 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001095 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001096 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001097 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1098 UserHandle.USER_CURRENT);
1099 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001100 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001101 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1102 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001103
Jeff Brown207673cd2012-06-05 17:47:11 -07001104 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001105 int userRotation = Settings.System.getIntForUser(resolver,
1106 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1107 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001108 if (mUserRotation != userRotation) {
1109 mUserRotation = userRotation;
1110 updateRotation = true;
1111 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001112 int userRotationMode = Settings.System.getIntForUser(resolver,
1113 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001114 WindowManagerPolicy.USER_ROTATION_FREE :
1115 WindowManagerPolicy.USER_ROTATION_LOCKED;
1116 if (mUserRotationMode != userRotationMode) {
1117 mUserRotationMode = userRotationMode;
1118 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001119 updateOrientationListenerLp();
1120 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001121
Dianne Hackbornc777e072010-02-12 13:07:59 -08001122 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001123 int pointerLocation = Settings.System.getIntForUser(resolver,
1124 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001125 if (mPointerLocationMode != pointerLocation) {
1126 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001127 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1128 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001129 }
1130 }
1131 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001132 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1133 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1134 String imId = Settings.Secure.getStringForUser(resolver,
1135 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001136 boolean hasSoftInput = imId != null && imId.length() > 0;
1137 if (mHasSoftInput != hasSoftInput) {
1138 mHasSoftInput = hasSoftInput;
1139 updateRotation = true;
1140 }
John Spurlock245fd012013-05-31 10:31:04 -04001141 OverlayTesting.enabled = Settings.System.getIntForUser(resolver,
1142 OverlayTesting.ENABLED_SETTING, 0, UserHandle.USER_CURRENT) != 0;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001143 }
1144 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001145 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001146 }
Jeff Brown70825162012-03-28 17:27:48 -07001147 }
1148
1149 private void enablePointerLocation() {
1150 if (mPointerLocationView == null) {
1151 mPointerLocationView = new PointerLocationView(mContext);
1152 mPointerLocationView.setPrintCoords(false);
1153
Dianne Hackbornc777e072010-02-12 13:07:59 -08001154 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1155 WindowManager.LayoutParams.MATCH_PARENT,
1156 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001157 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001158 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1159 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1160 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1161 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001162 if (ActivityManager.isHighEndGfx()) {
1163 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1164 lp.privateFlags |=
1165 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1166 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001167 lp.format = PixelFormat.TRANSLUCENT;
1168 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001169 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001170 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001171 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001172 wm.addView(mPointerLocationView, lp);
1173
Craig Mautner037aa8d2013-06-07 10:35:44 -07001174 mPointerLocationPointerEventListener = new PointerLocationPointerEventListener();
1175 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationPointerEventListener);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001176 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001177 }
Jeff Brown70825162012-03-28 17:27:48 -07001178
1179 private void disablePointerLocation() {
Craig Mautner037aa8d2013-06-07 10:35:44 -07001180 if (mPointerLocationPointerEventListener != null) {
1181 mWindowManagerFuncs.unregisterPointerEventListener(
1182 mPointerLocationPointerEventListener);
1183 mPointerLocationPointerEventListener = null;
Jeff Brown70825162012-03-28 17:27:48 -07001184 }
1185
1186 if (mPointerLocationView != null) {
1187 WindowManager wm = (WindowManager)
1188 mContext.getSystemService(Context.WINDOW_SERVICE);
1189 wm.removeView(mPointerLocationView);
1190 mPointerLocationView = null;
1191 }
1192 }
1193
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001194 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001195 try {
1196 int rotation = mContext.getResources().getInteger(resID);
1197 switch (rotation) {
1198 case 0:
1199 return Surface.ROTATION_0;
1200 case 90:
1201 return Surface.ROTATION_90;
1202 case 180:
1203 return Surface.ROTATION_180;
1204 case 270:
1205 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001206 }
1207 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001208 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001209 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001210 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001211 }
1212
1213 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001214 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001215 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001216 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001217
1218 outAppOp[0] = AppOpsManager.OP_NONE;
1219
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001220 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1221 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001222 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001223 }
1224 String permission = null;
1225 switch (type) {
1226 case TYPE_TOAST:
1227 // XXX right now the app process has complete control over
1228 // this... should introduce a token to let the system
1229 // monitor/control what they are doing.
1230 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001231 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001232 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001233 case TYPE_WALLPAPER:
1234 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001235 break;
1236 case TYPE_PHONE:
1237 case TYPE_PRIORITY_PHONE:
1238 case TYPE_SYSTEM_ALERT:
1239 case TYPE_SYSTEM_ERROR:
1240 case TYPE_SYSTEM_OVERLAY:
1241 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001242 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001243 break;
1244 default:
1245 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1246 }
1247 if (permission != null) {
1248 if (mContext.checkCallingOrSelfPermission(permission)
1249 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001250 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001251 }
1252 }
Jeff Brown98365d72012-08-19 20:30:52 -07001253 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001254 }
Craig Mautner88400d32012-09-30 12:35:45 -07001255
1256 @Override
1257 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1258
1259 // If this switch statement is modified, modify the comment in the declarations of
1260 // the type in {@link WindowManager.LayoutParams} as well.
1261 switch (attrs.type) {
1262 default:
1263 // These are the windows that by default are shown only to the user that created
1264 // them. If this needs to be overridden, set
1265 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1266 // {@link WindowManager.LayoutParams}. Note that permission
1267 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1268 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1269 return true;
1270 }
1271 break;
1272
1273 // These are the windows that by default are shown to all users. However, to
1274 // protect against spoofing, check permissions below.
1275 case TYPE_APPLICATION_STARTING:
1276 case TYPE_BOOT_PROGRESS:
1277 case TYPE_DISPLAY_OVERLAY:
1278 case TYPE_HIDDEN_NAV_CONSUMER:
1279 case TYPE_KEYGUARD:
Jim Miller5ecd8112013-01-09 18:50:26 -08001280 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001281 case TYPE_KEYGUARD_DIALOG:
1282 case TYPE_MAGNIFICATION_OVERLAY:
1283 case TYPE_NAVIGATION_BAR:
1284 case TYPE_NAVIGATION_BAR_PANEL:
1285 case TYPE_PHONE:
1286 case TYPE_POINTER:
1287 case TYPE_PRIORITY_PHONE:
1288 case TYPE_RECENTS_OVERLAY:
1289 case TYPE_SEARCH_BAR:
1290 case TYPE_STATUS_BAR:
1291 case TYPE_STATUS_BAR_PANEL:
1292 case TYPE_STATUS_BAR_SUB_PANEL:
1293 case TYPE_SYSTEM_DIALOG:
1294 case TYPE_UNIVERSE_BACKGROUND:
1295 case TYPE_VOLUME_OVERLAY:
1296 break;
1297 }
1298
1299 // Check if third party app has set window to system window type.
1300 return mContext.checkCallingOrSelfPermission(
1301 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1302 != PackageManager.PERMISSION_GRANTED;
1303 }
1304
Craig Mautner967212c2013-04-13 21:10:58 -07001305 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001306 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1307 switch (attrs.type) {
1308 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001309 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001310 // These types of windows can't receive input events.
1311 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1312 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001313 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001314 break;
1315 }
1316 }
1317
1318 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001319 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001320 }
1321
Jeff Browndaa37532012-05-01 15:54:03 -07001322 private boolean isHidden(int accessibilityMode) {
1323 switch (accessibilityMode) {
1324 case 1:
1325 return mLidState == LID_CLOSED;
1326 case 2:
1327 return mLidState == LID_OPEN;
1328 default:
1329 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001330 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001331 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001332
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001333 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001334 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001335 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1336 int navigationPresence) {
1337 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1338
Jeff Brownf71343d2013-05-31 17:59:11 -07001339 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001340 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001341 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001342
Jeff Browndaa37532012-05-01 15:54:03 -07001343 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1344 || (keyboardPresence == PRESENCE_INTERNAL
1345 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001346 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001347 if (!mHasSoftInput) {
1348 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1349 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001350 }
1351
Jeff Browndaa37532012-05-01 15:54:03 -07001352 if (config.navigation == Configuration.NAVIGATION_NONAV
1353 || (navigationPresence == PRESENCE_INTERNAL
1354 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001355 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001356 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001357 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001358
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001359 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001360 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001361 public int windowTypeToLayerLw(int type) {
1362 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001363 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001364 }
1365 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001366 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001367 return 1;
1368 case TYPE_WALLPAPER:
1369 // wallpaper is at the bottom, though the window manager may move it.
1370 return 2;
1371 case TYPE_PHONE:
1372 return 3;
1373 case TYPE_SEARCH_BAR:
1374 return 4;
Craig Mautner88400d32012-09-30 12:35:45 -07001375 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001376 case TYPE_SYSTEM_DIALOG:
1377 return 5;
1378 case TYPE_TOAST:
1379 // toasts and the plugged-in battery thing
1380 return 6;
1381 case TYPE_PRIORITY_PHONE:
1382 // SIM errors and unlock. Not sure if this really should be in a high layer.
1383 return 7;
1384 case TYPE_DREAM:
1385 // used for Dreams (screensavers with TYPE_DREAM windows)
1386 return 8;
1387 case TYPE_SYSTEM_ALERT:
1388 // like the ANR / app crashed dialogs
1389 return 9;
1390 case TYPE_INPUT_METHOD:
1391 // on-screen keyboards and other such input method user interfaces go here.
1392 return 10;
1393 case TYPE_INPUT_METHOD_DIALOG:
1394 // on-screen keyboards and other such input method user interfaces go here.
1395 return 11;
Jim Miller5ecd8112013-01-09 18:50:26 -08001396 case TYPE_KEYGUARD_SCRIM:
1397 // the safety window that shows behind keyguard while keyguard is starting
1398 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001399 case TYPE_KEYGUARD:
1400 // the keyguard; nothing on top of these can take focus, since they are
1401 // responsible for power management when displayed.
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001402 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001403 case TYPE_KEYGUARD_DIALOG:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001404 return 14;
Jim Miller5ecd8112013-01-09 18:50:26 -08001405 case TYPE_STATUS_BAR_SUB_PANEL:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001406 return 15;
Jim Miller5ecd8112013-01-09 18:50:26 -08001407 case TYPE_STATUS_BAR:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001408 return 16;
Jim Miller5ecd8112013-01-09 18:50:26 -08001409 case TYPE_STATUS_BAR_PANEL:
1410 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001411 case TYPE_VOLUME_OVERLAY:
1412 // the on-screen volume indicator and controller shown when the user
1413 // changes the device volume
Jim Miller5ecd8112013-01-09 18:50:26 -08001414 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001415 case TYPE_SYSTEM_OVERLAY:
1416 // the on-screen volume indicator and controller shown when the user
1417 // changes the device volume
Jim Miller5ecd8112013-01-09 18:50:26 -08001418 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001419 case TYPE_NAVIGATION_BAR:
1420 // the navigation bar, if available, shows atop most things
Jim Miller5ecd8112013-01-09 18:50:26 -08001421 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001422 case TYPE_NAVIGATION_BAR_PANEL:
1423 // some panels (e.g. search) need to show on top of the navigation bar
Jim Miller5ecd8112013-01-09 18:50:26 -08001424 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001425 case TYPE_SYSTEM_ERROR:
1426 // system-level error dialogs
Jim Miller5ecd8112013-01-09 18:50:26 -08001427 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001428 case TYPE_MAGNIFICATION_OVERLAY:
1429 // used to highlight the magnified portion of a display
Jim Miller5ecd8112013-01-09 18:50:26 -08001430 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001431 case TYPE_DISPLAY_OVERLAY:
1432 // used to simulate secondary display devices
Jim Miller5ecd8112013-01-09 18:50:26 -08001433 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001434 case TYPE_DRAG:
1435 // the drag layer: input for drag-and-drop is associated with this window,
1436 // which sits above all other focusable windows
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001437 return 25;
Jim Miller5ecd8112013-01-09 18:50:26 -08001438 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001439 return 26;
Jim Miller5ecd8112013-01-09 18:50:26 -08001440 case TYPE_BOOT_PROGRESS:
1441 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001442 case TYPE_POINTER:
1443 // the (mouse) pointer layer
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001444 return 28;
Jim Miller5ecd8112013-01-09 18:50:26 -08001445 case TYPE_HIDDEN_NAV_CONSUMER:
1446 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001447 }
1448 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001449 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001450 }
1451
1452 /** {@inheritDoc} */
1453 public int subWindowTypeToLayerLw(int type) {
1454 switch (type) {
1455 case TYPE_APPLICATION_PANEL:
1456 case TYPE_APPLICATION_ATTACHED_DIALOG:
1457 return APPLICATION_PANEL_SUBLAYER;
1458 case TYPE_APPLICATION_MEDIA:
1459 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001460 case TYPE_APPLICATION_MEDIA_OVERLAY:
1461 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001462 case TYPE_APPLICATION_SUB_PANEL:
1463 return APPLICATION_SUB_PANEL_SUBLAYER;
1464 }
1465 Log.e(TAG, "Unknown sub-window type: " + type);
1466 return 0;
1467 }
1468
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001469 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001470 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001471 }
1472
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001473 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001474 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001475 }
1476
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001477 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001478 if (mHasNavigationBar) {
1479 // For a basic navigation bar, when we are in landscape mode we place
1480 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001481 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1482 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001483 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001484 }
1485 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001486 }
1487
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001488 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001489 if (mHasNavigationBar) {
1490 // For a basic navigation bar, when we are in portrait mode we place
1491 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001492 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1493 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001494 }
1495 }
1496 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001497 }
1498
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001499 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1500 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001501 }
1502
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001503 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001504 // There is a separate status bar at the top of the display. We don't count that as part
1505 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001506 // we do want to exclude it since applications can't generally use that part
1507 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001508 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001509 }
1510
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001511 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001512 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) {
1513 return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD;
1514 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001515
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001516 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001517 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001518 switch (attrs.type) {
1519 case TYPE_STATUS_BAR:
1520 case TYPE_NAVIGATION_BAR:
1521 case TYPE_WALLPAPER:
1522 case TYPE_DREAM:
1523 case TYPE_UNIVERSE_BACKGROUND:
1524 case TYPE_KEYGUARD:
Jim Miller5ecd8112013-01-09 18:50:26 -08001525 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001526 return false;
1527 default:
1528 return true;
1529 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001530 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001531
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001532 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001533 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001534 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1535 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001536 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001537 if (!SHOW_STARTING_ANIMATIONS) {
1538 return null;
1539 }
1540 if (packageName == null) {
1541 return null;
1542 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001543
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001544 WindowManager wm = null;
1545 View view = null;
1546
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001547 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001548 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001549 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1550 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1551 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001552 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001553 try {
1554 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001555 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001556 } catch (PackageManager.NameNotFoundException e) {
1557 // Ignore
1558 }
1559 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001560
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001561 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001562 final TypedArray ta = win.getWindowStyle();
1563 if (ta.getBoolean(
1564 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1565 || ta.getBoolean(
1566 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001567 return null;
1568 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001569
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001570 Resources r = context.getResources();
1571 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001572
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001573 win.setType(
1574 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1575 // Force the window flags: this is a fake window, so it is not really
1576 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1577 // flag because we do know that the next window will take input
1578 // focus, so we want to get the IME window up on top of us right away.
1579 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001580 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001581 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1582 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1583 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001584 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001585 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1586 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1587 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001588
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001589 if (!compatInfo.supportsScreen()) {
1590 win.addFlags(WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW);
1591 }
1592
Adam Powell04fe6eb2013-05-31 14:39:48 -07001593 win.setDefaultIcon(icon);
1594 win.setDefaultLogo(logo);
1595
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001596 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001597 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001598
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001599 final WindowManager.LayoutParams params = win.getAttributes();
1600 params.token = appToken;
1601 params.packageName = packageName;
1602 params.windowAnimations = win.getWindowStyle().getResourceId(
1603 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001604 params.privateFlags |=
1605 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001606 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001607 params.setTitle("Starting " + packageName);
1608
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001609 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1610 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001611
1612 if (win.isFloating()) {
1613 // Whoops, there is no way to display an animation/preview
1614 // of such a thing! After all that work... let's skip it.
1615 // (Note that we must do this here because it is in
1616 // getDecorView() where the theme is evaluated... maybe
1617 // we should peek the floating attribute from the theme
1618 // earlier.)
1619 return null;
1620 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001621
Craig Mautner6fbda632012-07-03 09:26:39 -07001622 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001623 TAG, "Adding starting window for " + packageName
1624 + " / " + appToken + ": "
1625 + (view.getParent() != null ? view : null));
1626
1627 wm.addView(view, params);
1628
1629 // Only return the view if it was successfully added to the
1630 // window manager... which we can tell by it having a parent.
1631 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001632 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001633 // ignore
1634 Log.w(TAG, appToken + " already running, starting window not displayed");
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001635 } catch (RuntimeException e) {
1636 // don't crash if something else bad happens, for example a
1637 // failure loading resources because we are loading from an app
1638 // on external storage that has been unmounted.
1639 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001640 } finally {
1641 if (view != null && view.getParent() == null) {
1642 Log.w(TAG, "view not successfully added to wm, removing view");
1643 wm.removeViewImmediate(view);
1644 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001645 }
1646
1647 return null;
1648 }
1649
1650 /** {@inheritDoc} */
1651 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001652 if (DEBUG_STARTING_WINDOW) {
1653 RuntimeException e = new RuntimeException("here");
1654 e.fillInStackTrace();
1655 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1656 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001657
1658 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001659 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001660 wm.removeView(window);
1661 }
1662 }
1663
1664 /**
1665 * Preflight adding a window to the system.
1666 *
1667 * Currently enforces that three window types are singletons:
1668 * <ul>
1669 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001670 * <li>KEYGUARD_TYPE</li>
1671 * </ul>
1672 *
1673 * @param win The window to be added
1674 * @param attrs Information about the window to be added
1675 *
Jeff Brown98365d72012-08-19 20:30:52 -07001676 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1677 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001678 */
1679 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1680 switch (attrs.type) {
1681 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001682 mContext.enforceCallingOrSelfPermission(
1683 android.Manifest.permission.STATUS_BAR_SERVICE,
1684 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001685 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001686 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001687 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001688 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001689 }
1690 mStatusBar = win;
1691 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001692 case TYPE_NAVIGATION_BAR:
1693 mContext.enforceCallingOrSelfPermission(
1694 android.Manifest.permission.STATUS_BAR_SERVICE,
1695 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001696 if (mNavigationBar != null) {
1697 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001698 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001699 }
1700 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001701 mNavigationBar = win;
Craig Mautnereda67292013-04-28 13:50:14 -07001702 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001703 break;
Jim Millere898ac52012-04-06 17:10:57 -07001704 case TYPE_NAVIGATION_BAR_PANEL:
1705 mContext.enforceCallingOrSelfPermission(
1706 android.Manifest.permission.STATUS_BAR_SERVICE,
1707 "PhoneWindowManager");
1708 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001709 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001710 mContext.enforceCallingOrSelfPermission(
1711 android.Manifest.permission.STATUS_BAR_SERVICE,
1712 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001713 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001714 case TYPE_STATUS_BAR_SUB_PANEL:
1715 mContext.enforceCallingOrSelfPermission(
1716 android.Manifest.permission.STATUS_BAR_SERVICE,
1717 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001718 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001719 case TYPE_KEYGUARD:
1720 if (mKeyguard != null) {
Jeff Brown98365d72012-08-19 20:30:52 -07001721 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001722 }
1723 mKeyguard = win;
1724 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001725 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001726 if (mKeyguardScrim != null) {
1727 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1728 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001729 mKeyguardScrim = win;
1730 break;
1731
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001732 }
Jeff Brown98365d72012-08-19 20:30:52 -07001733 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001734 }
1735
1736 /** {@inheritDoc} */
1737 public void removeWindowLw(WindowState win) {
1738 if (mStatusBar == win) {
1739 mStatusBar = null;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001740 } else if (mKeyguard == win) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001741 Log.v(TAG, "Removing keyguard window (Did it crash?)");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001742 mKeyguard = null;
Jim Millerc0b676d2013-03-22 16:11:08 -07001743 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001744 } else if (mKeyguardScrim == win) {
1745 Log.v(TAG, "Removing keyguard scrim");
1746 mKeyguardScrim = null;
1747 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001748 mNavigationBar = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001749 }
1750 }
1751
1752 static final boolean PRINT_ANIM = false;
1753
1754 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001755 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001756 public int selectAnimationLw(WindowState win, int transit) {
1757 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1758 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001759 if (win == mStatusBar) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001760 if (transit == TRANSIT_EXIT
1761 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001762 return R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001763 } else if (transit == TRANSIT_ENTER
1764 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001765 return R.anim.dock_top_enter;
1766 }
1767 } else if (win == mNavigationBar) {
1768 // This can be on either the bottom or the right.
1769 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001770 if (transit == TRANSIT_EXIT
1771 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001772 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001773 } else if (transit == TRANSIT_ENTER
1774 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001775 return R.anim.dock_bottom_enter;
1776 }
1777 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001778 if (transit == TRANSIT_EXIT
1779 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001780 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001781 } else if (transit == TRANSIT_ENTER
1782 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001783 return R.anim.dock_right_enter;
1784 }
1785 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001786 }
1787
1788 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001789 if (win.hasAppShownWindows()) {
1790 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1791 return com.android.internal.R.anim.app_starting_exit;
1792 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001793 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001794 && transit == TRANSIT_ENTER) {
1795 // Special case: we are animating in a dream, while the keyguard
1796 // is shown. We don't want an animation on the dream, because
1797 // we need it shown immediately with the keyguard animating away
1798 // to reveal it.
1799 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001800 }
1801
1802 return 0;
1803 }
1804
Craig Mautner3c174372013-02-21 17:54:37 -08001805 @Override
1806 public void selectRotationAnimationLw(int anim[]) {
1807 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
1808 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
1809 + (mTopFullscreenOpaqueWindowState == null ?
1810 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
1811 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
1812 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
1813 case ROTATION_ANIMATION_CROSSFADE:
1814 anim[0] = R.anim.rotation_animation_xfade_exit;
1815 anim[1] = R.anim.rotation_animation_enter;
1816 break;
1817 case ROTATION_ANIMATION_JUMPCUT:
1818 anim[0] = R.anim.rotation_animation_jump_exit;
1819 anim[1] = R.anim.rotation_animation_enter;
1820 break;
1821 case ROTATION_ANIMATION_ROTATE:
1822 default:
1823 anim[0] = anim[1] = 0;
1824 break;
1825 }
1826 } else {
1827 anim[0] = anim[1] = 0;
1828 }
1829 }
1830
1831 @Override
1832 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
1833 boolean forceDefault) {
1834 switch (exitAnimId) {
1835 case R.anim.rotation_animation_xfade_exit:
1836 case R.anim.rotation_animation_jump_exit:
1837 // These are the only cases that matter.
1838 if (forceDefault) {
1839 return false;
1840 }
1841 int anim[] = new int[2];
1842 selectRotationAnimationLw(anim);
1843 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
1844 default:
1845 return true;
1846 }
1847 }
1848
1849 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07001850 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
1851 return AnimationUtils.loadAnimation(mContext, onWallpaper
1852 ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter
1853 : com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001854 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04001855
1856 private static void awakenDreams() {
1857 IDreamManager dreamManager = getDreamManager();
1858 if (dreamManager != null) {
1859 try {
1860 dreamManager.awaken();
1861 } catch (RemoteException e) {
1862 // fine, stay asleep then
1863 }
1864 }
1865 }
1866
1867 static IDreamManager getDreamManager() {
1868 return IDreamManager.Stub.asInterface(
1869 ServiceManager.checkService(DreamService.DREAM_SERVICE));
1870 }
1871
Jeff Brown4d396052010-10-29 21:50:21 -07001872 static ITelephony getTelephonyService() {
Mike Lockwoodf5f4ec92011-11-08 14:05:31 -08001873 return ITelephony.Stub.asInterface(
Jeff Brown4d396052010-10-29 21:50:21 -07001874 ServiceManager.checkService(Context.TELEPHONY_SERVICE));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001875 }
1876
Jeff Brown4d396052010-10-29 21:50:21 -07001877 static IAudioService getAudioService() {
1878 IAudioService audioService = IAudioService.Stub.asInterface(
1879 ServiceManager.checkService(Context.AUDIO_SERVICE));
1880 if (audioService == null) {
1881 Log.w(TAG, "Unable to find IAudioService interface.");
1882 }
1883 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001884 }
1885
1886 boolean keyguardOn() {
1887 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
1888 }
1889
1890 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
1891 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
1892 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
1893 };
1894
1895 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001896 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001897 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001898 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08001899 final int keyCode = event.getKeyCode();
1900 final int repeatCount = event.getRepeatCount();
1901 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001902 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08001903 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
1904 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001905
Jeff Brown40013652012-05-16 21:22:36 -07001906 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001907 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001908 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
1909 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001910 }
1911
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001912 // If we think we might have a volume down & power key chord on the way
1913 // but we're not sure, then tell the dispatcher to wait a little while and
1914 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08001915 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001916 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
1917 final long now = SystemClock.uptimeMillis();
1918 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
1919 if (now < timeoutTime) {
1920 return timeoutTime - now;
1921 }
1922 }
1923 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
1924 && mVolumeDownKeyConsumedByScreenshotChord) {
1925 if (!down) {
1926 mVolumeDownKeyConsumedByScreenshotChord = false;
1927 }
1928 return -1;
1929 }
1930 }
1931
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001932 // First we always handle the home key here, so applications
1933 // can never break it, although if keyguard is on, we do let
1934 // it handle it, because that gives us the correct 5 second
1935 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001936 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001937
Jeff Brown49ed71d2010-12-06 17:13:33 -08001938 // If we have released the home key, and didn't do anything else
1939 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07001940 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07001941 cancelPreloadRecentApps();
1942
Jeff Brown49ed71d2010-12-06 17:13:33 -08001943 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07001944 if (mHomeConsumed) {
1945 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07001946 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001947 }
Jeff Browncaca8812013-05-09 13:34:33 -07001948
1949 if (canceled) {
1950 Log.i(TAG, "Ignoring HOME; event canceled.");
1951 return -1;
1952 }
1953
1954 // If an incoming call is ringing, HOME is totally disabled.
1955 // (The user is already on the InCallScreen at this point,
1956 // and his ONLY options are to answer or reject the call.)
1957 try {
1958 ITelephony telephonyService = getTelephonyService();
1959 if (telephonyService != null && telephonyService.isRinging()) {
1960 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
1961 return -1;
1962 }
1963 } catch (RemoteException ex) {
1964 Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
1965 }
1966
1967 // Delay handling home if a double-tap is possible.
1968 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
1969 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
1970 mHomeDoubleTapPending = true;
1971 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
1972 ViewConfiguration.getDoubleTapTimeout());
1973 return -1;
1974 }
1975
1976 // Go home!
1977 launchHomeFromHotKey();
1978 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001979 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001980
1981 // If a system window has focus, then it doesn't make sense
1982 // right now to interact with applications.
1983 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
1984 if (attrs != null) {
1985 final int type = attrs.type;
1986 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
Jim Miller5ecd8112013-01-09 18:50:26 -08001987 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001988 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
1989 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001990 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001991 }
1992 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
1993 for (int i=0; i<typeCount; i++) {
1994 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
1995 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001996 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001997 }
1998 }
1999 }
Jeff Browncaca8812013-05-09 13:34:33 -07002000
2001 // Remember that home is pressed and handle special actions.
2002 if (repeatCount == 0) {
2003 mHomePressed = true;
2004 if (mHomeDoubleTapPending) {
2005 mHomeDoubleTapPending = false;
2006 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2007 handleDoubleTapOnHome();
2008 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2009 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2010 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002011 }
Jeff Browncaca8812013-05-09 13:34:33 -07002012 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2013 if (!keyguardOn) {
2014 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002015 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002016 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002017 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002018 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002019 // Hijack modified menu keys for debugging features
2020 final int chordBug = KeyEvent.META_SHIFT_ON;
2021
2022 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002023 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002024 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002025 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2026 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002027 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002028 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002029 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002030 Intent service = new Intent();
2031 service.setClassName(mContext, "com.android.server.LoadAverageService");
2032 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002033 boolean shown = Settings.Global.getInt(
2034 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002035 if (!shown) {
2036 mContext.startService(service);
2037 } else {
2038 mContext.stopService(service);
2039 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002040 Settings.Global.putInt(
2041 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002042 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002043 }
2044 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002045 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002046 if (down) {
2047 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002048 mSearchKeyShortcutPending = true;
2049 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002050 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002051 } else {
2052 mSearchKeyShortcutPending = false;
2053 if (mConsumeSearchKeyUp) {
2054 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002055 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002056 }
2057 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002058 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002059 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002060 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002061 if (down && repeatCount == 0) {
2062 preloadRecentApps();
2063 } else if (!down) {
2064 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002065 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002066 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002067 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002068 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2069 if (down) {
2070 if (repeatCount == 0) {
2071 mAssistKeyLongPressed = false;
2072 } else if (repeatCount == 1) {
2073 mAssistKeyLongPressed = true;
2074 if (!keyguardOn) {
2075 launchAssistLongPressAction();
2076 }
2077 }
2078 } else {
2079 if (mAssistKeyLongPressed) {
2080 mAssistKeyLongPressed = false;
2081 } else {
2082 if (!keyguardOn) {
2083 launchAssistAction();
2084 }
2085 }
2086 }
2087 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002088 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2089 if (down && repeatCount == 0) {
2090 mHandler.post(mScreenshotRunnable);
2091 }
2092 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002093 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2094 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2095 if (down) {
2096 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2097
2098 // Disable autobrightness if it's on
2099 int auto = Settings.System.getIntForUser(
2100 mContext.getContentResolver(),
2101 Settings.System.SCREEN_BRIGHTNESS_MODE,
2102 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2103 UserHandle.USER_CURRENT_OR_SELF);
2104 if (auto != 0) {
2105 Settings.System.putIntForUser(mContext.getContentResolver(),
2106 Settings.System.SCREEN_BRIGHTNESS_MODE,
2107 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2108 UserHandle.USER_CURRENT_OR_SELF);
2109 }
2110
2111 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2112 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2113 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2114 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2115 Settings.System.SCREEN_BRIGHTNESS,
2116 mPowerManager.getDefaultScreenBrightnessSetting(),
2117 UserHandle.USER_CURRENT_OR_SELF);
2118 brightness += step;
2119 // Make sure we don't go beyond the limits.
2120 brightness = Math.min(max, brightness);
2121 brightness = Math.max(min, brightness);
2122
2123 Settings.System.putIntForUser(mContext.getContentResolver(),
2124 Settings.System.SCREEN_BRIGHTNESS, brightness,
2125 UserHandle.USER_CURRENT_OR_SELF);
2126 Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG);
2127 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF);
2128 }
2129 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002130 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002131
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002132 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002133 // Any printing key that is chorded with Search should be consumed
2134 // even if no shortcut was invoked. This prevents text from being
2135 // inadvertently inserted when using a keyboard that has built-in macro
2136 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002137 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002138 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2139 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002140 mConsumeSearchKeyUp = true;
2141 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002142 if (down && repeatCount == 0 && !keyguardOn) {
2143 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2144 if (shortcutIntent != null) {
2145 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002146 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002147 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002148 } catch (ActivityNotFoundException ex) {
2149 Slog.w(TAG, "Dropping shortcut key combination because "
2150 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002151 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002152 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002153 } else {
2154 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002155 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002156 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002157 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002158 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002159 }
2160 }
2161
Jeff Brown68b909d2011-12-07 16:36:01 -08002162 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002163 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002164 && (metaState & KeyEvent.META_META_ON) != 0) {
2165 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002166 if (kcm.isPrintingKey(keyCode)) {
2167 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2168 metaState & ~(KeyEvent.META_META_ON
2169 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2170 if (shortcutIntent != null) {
2171 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2172 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002173 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002174 } catch (ActivityNotFoundException ex) {
2175 Slog.w(TAG, "Dropping shortcut key combination because "
2176 + "the activity to which it is registered was not found: "
2177 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2178 }
2179 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002180 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002181 }
2182 }
2183
Jeff Brown6651a632011-11-28 12:59:11 -08002184 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002185 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002186 String category = sApplicationLaunchKeyCategories.get(keyCode);
2187 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002188 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002189 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2190 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002191 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002192 } catch (ActivityNotFoundException ex) {
2193 Slog.w(TAG, "Dropping application launch key because "
2194 + "the activity to which it is registered was not found: "
2195 + "keyCode=" + keyCode + ", category=" + category, ex);
2196 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002197 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002198 }
2199 }
2200
Jeff Brown68b909d2011-12-07 16:36:01 -08002201 // Display task switcher for ALT-TAB or Meta-TAB.
2202 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Jeff Brown602ab322012-05-16 13:33:47 -07002203 if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002204 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
2205 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2206 || KeyEvent.metaStateHasModifiers(
2207 shiftlessModifiers, KeyEvent.META_META_ON)) {
2208 mRecentAppsDialogHeldModifiers = shiftlessModifiers;
2209 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW);
2210 return -1;
2211 }
2212 }
2213 } else if (!down && mRecentAppsDialogHeldModifiers != 0
2214 && (metaState & mRecentAppsDialogHeldModifiers) == 0) {
2215 mRecentAppsDialogHeldModifiers = 0;
Jeff Brown602ab322012-05-16 13:33:47 -07002216 showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS :
2217 RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH);
Jeff Brown68b909d2011-12-07 16:36:01 -08002218 }
2219
Jeff Browncf39bdf2012-05-18 14:41:19 -07002220 // Handle keyboard language switching.
2221 if (down && repeatCount == 0
2222 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2223 || (keyCode == KeyEvent.KEYCODE_SPACE
2224 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2225 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2226 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2227 return -1;
2228 }
2229 if (mLanguageSwitchKeyPressed && !down
2230 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2231 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2232 mLanguageSwitchKeyPressed = false;
2233 return -1;
2234 }
2235
Justin Kohd378ad72013-04-01 12:18:26 -07002236 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2237 return -1;
2238 }
2239
Jeff Brown68b909d2011-12-07 16:36:01 -08002240 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002241 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002242 }
2243
Jeff Brown3915bb82010-11-05 15:02:16 -07002244 /** {@inheritDoc} */
2245 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002246 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002247 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002248 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002249 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2250 + ", flags=" + event.getFlags()
2251 + ", keyCode=" + event.getKeyCode()
2252 + ", scanCode=" + event.getScanCode()
2253 + ", metaState=" + event.getMetaState()
2254 + ", repeatCount=" + event.getRepeatCount()
2255 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002256 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002257
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002258 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002259 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2260 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002261 final int keyCode = event.getKeyCode();
2262 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002263 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2264 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002265
Jeff Brown54875002011-04-06 15:33:01 -07002266 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002267 final FallbackAction fallbackAction;
2268 if (initialDown) {
2269 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2270 } else {
2271 fallbackAction = mFallbackActions.get(keyCode);
2272 }
2273
2274 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002275 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002276 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2277 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002278 }
2279
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002280 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2281 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002282 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002283 event.getAction(), fallbackAction.keyCode,
2284 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002285 event.getDeviceId(), event.getScanCode(),
2286 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002287
2288 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2289 fallbackEvent.recycle();
2290 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002291 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002292
2293 if (initialDown) {
2294 mFallbackActions.put(keyCode, fallbackAction);
2295 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2296 mFallbackActions.remove(keyCode);
2297 fallbackAction.recycle();
2298 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002299 }
2300 }
2301
Jeff Brown40013652012-05-16 21:22:36 -07002302 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002303 if (fallbackEvent == null) {
2304 Slog.d(TAG, "No fallback.");
2305 } else {
2306 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2307 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002308 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002309 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002310 }
2311
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002312 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
2313 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true);
2314 if ((actions & ACTION_PASS_TO_USER) != 0) {
2315 long delayMillis = interceptKeyBeforeDispatching(
2316 win, fallbackEvent, policyFlags);
2317 if (delayMillis == 0) {
2318 return true;
2319 }
2320 }
2321 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002322 }
2323
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002324 private void launchAssistLongPressAction() {
2325 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2326 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2327
2328 // launch the search activity
2329 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2330 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2331 try {
Jim Miller45308b12012-06-18 19:23:39 -07002332 // TODO: This only stops the factory-installed search manager.
2333 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002334 SearchManager searchManager = getSearchManager();
2335 if (searchManager != null) {
2336 searchManager.stopSearch();
2337 }
Michael Wright43e27f72013-04-10 14:06:48 -07002338 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002339 } catch (ActivityNotFoundException e) {
2340 Slog.w(TAG, "No activity to handle assist long press action.", e);
2341 }
2342 }
2343
2344 private void launchAssistAction() {
2345 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002346 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002347 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002348 if (intent != null) {
2349 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2350 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2351 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2352 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002353 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002354 } catch (ActivityNotFoundException e) {
2355 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002356 }
2357 }
2358 }
2359
2360 private SearchManager getSearchManager() {
2361 if (mSearchManager == null) {
2362 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2363 }
2364 return mSearchManager;
2365 }
2366
Jeff Browncaca8812013-05-09 13:34:33 -07002367 private void preloadRecentApps() {
2368 mPreloadedRecentApps = true;
2369 try {
2370 IStatusBarService statusbar = getStatusBarService();
2371 if (statusbar != null) {
2372 statusbar.preloadRecentApps();
2373 }
2374 } catch (RemoteException e) {
2375 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2376 // re-acquire status bar service next time it is needed.
2377 mStatusBarService = null;
2378 }
2379 }
2380
2381 private void cancelPreloadRecentApps() {
2382 if (mPreloadedRecentApps) {
2383 mPreloadedRecentApps = false;
2384 try {
2385 IStatusBarService statusbar = getStatusBarService();
2386 if (statusbar != null) {
2387 statusbar.cancelPreloadRecentApps();
2388 }
2389 } catch (RemoteException e) {
2390 Slog.e(TAG, "RemoteException when showing recent apps", e);
2391 // re-acquire status bar service next time it is needed.
2392 mStatusBarService = null;
2393 }
2394 }
2395 }
2396
2397 private void toggleRecentApps() {
2398 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2399 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
2400 try {
2401 IStatusBarService statusbar = getStatusBarService();
2402 if (statusbar != null) {
2403 statusbar.toggleRecentApps();
2404 }
2405 } catch (RemoteException e) {
2406 Slog.e(TAG, "RemoteException when showing recent apps", e);
2407 // re-acquire status bar service next time it is needed.
2408 mStatusBarService = null;
2409 }
2410 }
2411
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002412 /**
2413 * A home key -> launch home action was detected. Take the appropriate action
2414 * given the situation with the keyguard.
2415 */
2416 void launchHomeFromHotKey() {
Jim Miller5ecd8112013-01-09 18:50:26 -08002417 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotHidden()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002418 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002419 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002420 // when in keyguard restricted mode, must first verify unlock
2421 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002422 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002423 public void onKeyguardExitResult(boolean success) {
2424 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002425 try {
2426 ActivityManagerNative.getDefault().stopAppSwitches();
2427 } catch (RemoteException e) {
2428 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002429 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002430 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002431 }
2432 }
2433 });
2434 } else {
2435 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002436 try {
2437 ActivityManagerNative.getDefault().stopAppSwitches();
2438 } catch (RemoteException e) {
2439 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002440 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002441 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002442 }
2443 }
2444
John Spurlock04db1762013-05-13 12:46:41 -04002445 private final Runnable mClearHideNavigationFlag = new Runnable() {
2446 @Override
2447 public void run() {
2448 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2449 // Clear flags.
2450 mForceClearedSystemUiFlags &=
2451 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2452 }
2453 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002454 }
2455 };
2456
2457 /**
2458 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2459 * to determine when the nav bar should be shown and prevent applications from
2460 * receiving those touches.
2461 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002462 final class HideNavInputEventReceiver extends InputEventReceiver {
2463 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2464 super(inputChannel, looper);
2465 }
2466
Dianne Hackborndf89e652011-10-06 22:35:11 -07002467 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002468 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002469 boolean handled = false;
2470 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002471 if (event instanceof MotionEvent
2472 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2473 final MotionEvent motionEvent = (MotionEvent)event;
2474 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002475 // When the user taps down, we re-show the nav bar.
2476 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002477 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002478 // Any user activity always causes us to show the
2479 // navigation controls, if they had been hidden.
2480 // We also clear the low profile and only content
2481 // flags so that tapping on the screen will atomically
2482 // restore all currently hidden screen decorations.
2483 int newVal = mResettingSystemUiFlags |
2484 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2485 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2486 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002487 if (mResettingSystemUiFlags != newVal) {
2488 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002489 changed = true;
2490 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002491 // We don't allow the system's nav bar to be hidden
2492 // again for 1 second, to prevent applications from
2493 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002494 newVal = mForceClearedSystemUiFlags |
2495 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002496 if (mForceClearedSystemUiFlags != newVal) {
2497 mForceClearedSystemUiFlags = newVal;
2498 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002499 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002500 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002501 }
2502 if (changed) {
2503 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2504 }
2505 }
2506 }
2507 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002508 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002509 }
2510 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002511 }
2512 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2513 new InputEventReceiver.Factory() {
2514 @Override
2515 public InputEventReceiver createInputEventReceiver(
2516 InputChannel inputChannel, Looper looper) {
2517 return new HideNavInputEventReceiver(inputChannel, looper);
2518 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002519 };
2520
2521 @Override
2522 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock04db1762013-05-13 12:46:41 -04002523 if (mStatusBar != null && mStatusHideybar == HIDEYBAR_SHOWING &&
John Spurlockad3e6cb2013-04-30 08:47:43 -04002524 0 == (visibility & View.STATUS_BAR_OVERLAY)) {
2525 mStatusHideybar = HIDEYBAR_HIDING;
John Spurlock32beb2c2013-03-11 10:16:47 -04002526 mStatusBar.hideLw(true);
2527 }
John Spurlocke3b642e2013-05-09 15:51:32 -04002528 if (mNavigationBar != null && mNavigationHideybar == HIDEYBAR_SHOWING &&
John Spurlockad3e6cb2013-04-30 08:47:43 -04002529 0 == (visibility & View.NAVIGATION_BAR_OVERLAY)) {
2530 mNavigationHideybar = HIDEYBAR_HIDING;
2531 mNavigationBar.hideLw(true);
2532 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002533 // Reset any bits in mForceClearingStatusBarVisibility that
2534 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002535 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002536 // Clear any bits in the new visibility that are currently being
2537 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002538 return visibility & ~mResettingSystemUiFlags
2539 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002540 }
2541
Craig Mautner69b08182012-09-05 13:07:13 -07002542 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002543 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
2544 final int fl = attrs.flags;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002545 final int systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002546
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002547 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002548 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002549 int availRight, availBottom;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002550 if (mCanHideNavigationBar &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002551 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002552 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2553 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2554 } else {
2555 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2556 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2557 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002558 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2559 if ((fl & FLAG_FULLSCREEN) != 0) {
2560 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2561 availRight - mStableFullscreenRight,
2562 availBottom - mStableFullscreenBottom);
2563 } else {
2564 contentInset.set(mStableLeft, mStableTop,
2565 availRight - mStableRight, availBottom - mStableBottom);
2566 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002567 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002568 contentInset.setEmpty();
2569 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002570 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2571 contentInset.set(mCurLeft, mCurTop,
2572 availRight - mCurRight, availBottom - mCurBottom);
2573 } else {
2574 contentInset.set(mCurLeft, mCurTop,
2575 availRight - mCurRight, availBottom - mCurBottom);
2576 }
2577 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002578 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002579 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002580 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002581
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002582 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002583 @Override
2584 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2585 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002586 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2587 if (isDefaultDisplay) {
2588 switch (displayRotation) {
2589 case Surface.ROTATION_90:
2590 overscanLeft = mOverscanTop;
2591 overscanTop = mOverscanRight;
2592 overscanRight = mOverscanBottom;
2593 overscanBottom = mOverscanLeft;
2594 break;
2595 case Surface.ROTATION_180:
2596 overscanLeft = mOverscanRight;
2597 overscanTop = mOverscanBottom;
2598 overscanRight = mOverscanLeft;
2599 overscanBottom = mOverscanTop;
2600 break;
2601 case Surface.ROTATION_270:
2602 overscanLeft = mOverscanBottom;
2603 overscanTop = mOverscanLeft;
2604 overscanRight = mOverscanTop;
2605 overscanBottom = mOverscanRight;
2606 break;
2607 default:
2608 overscanLeft = mOverscanLeft;
2609 overscanTop = mOverscanTop;
2610 overscanRight = mOverscanRight;
2611 overscanBottom = mOverscanBottom;
2612 break;
2613 }
2614 } else {
2615 overscanLeft = 0;
2616 overscanTop = 0;
2617 overscanRight = 0;
2618 overscanBottom = 0;
2619 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002620 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2621 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2622 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2623 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002624 mSystemLeft = 0;
2625 mSystemTop = 0;
2626 mSystemRight = displayWidth;
2627 mSystemBottom = displayHeight;
2628 mUnrestrictedScreenLeft = overscanLeft;
2629 mUnrestrictedScreenTop = overscanTop;
2630 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2631 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2632 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2633 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002634 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2635 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002636 mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002637 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002638 mDockTop = mContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002639 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002640 mDockRight = mContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002641 = mCurRight = displayWidth - overscanRight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002642 mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002643 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002644 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002645 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002646
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002647 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2648 final Rect pf = mTmpParentFrame;
2649 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002650 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002651 final Rect vf = mTmpVisibleFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002652 pf.left = df.left = of.left = vf.left = mDockLeft;
2653 pf.top = df.top = of.top = vf.top = mDockTop;
2654 pf.right = df.right = of.right = vf.right = mDockRight;
2655 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002656
Craig Mautner69b08182012-09-05 13:07:13 -07002657 if (isDefaultDisplay) {
2658 // For purposes of putting out fake window up to steal focus, we will
2659 // drive nav being hidden only by whether it is requested.
2660 boolean navVisible = (mLastSystemUiFlags&View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002661 boolean overlayAllowed = (mLastSystemUiFlags&View.SYSTEM_UI_FLAG_ALLOW_OVERLAY) != 0;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002662
Craig Mautner69b08182012-09-05 13:07:13 -07002663 // When the navigation bar isn't visible, we put up a fake
2664 // input window to catch all touch events. This way we can
2665 // detect when the user presses anywhere to bring back the nav
2666 // bar and ensure the application doesn't see the event.
John Spurlockad3e6cb2013-04-30 08:47:43 -04002667 if (navVisible || overlayAllowed) {
Craig Mautner69b08182012-09-05 13:07:13 -07002668 if (mHideNavFakeWindow != null) {
2669 mHideNavFakeWindow.dismiss();
2670 mHideNavFakeWindow = null;
2671 }
2672 } else if (mHideNavFakeWindow == null) {
2673 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2674 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
2675 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER,
2676 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002677 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002678
Craig Mautner69b08182012-09-05 13:07:13 -07002679 // For purposes of positioning and showing the nav bar, if we have
2680 // decided that it can't be hidden (because of the screen aspect ratio),
2681 // then take that into account.
2682 navVisible |= !mCanHideNavigationBar;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002683
John Spurlockad3e6cb2013-04-30 08:47:43 -04002684 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07002685 if (mNavigationBar != null) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002686 boolean navBarHideyShowing = mNavigationHideybar == HIDEYBAR_SHOWING;
Craig Mautner69b08182012-09-05 13:07:13 -07002687 // Force the navigation bar to its appropriate place and
2688 // size. We need to do this directly, instead of relying on
2689 // it to bubble up from the nav bar, because this needs to
2690 // change atomically with screen rotations.
2691 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2692 if (mNavigationBarOnBottom) {
2693 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002694 int top = displayHeight - overscanBottom
2695 - mNavigationBarHeightForRotation[displayRotation];
2696 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07002697 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002698 if (navBarHideyShowing) {
2699 mNavigationBar.showLw(true);
2700 } else if (navVisible) {
Craig Mautner69b08182012-09-05 13:07:13 -07002701 mNavigationBar.showLw(true);
2702 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08002703 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
2704 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002705 } else {
2706 // We currently want to hide the navigation UI.
2707 mNavigationBar.hideLw(true);
2708 }
2709 if (navVisible && !mNavigationBar.isAnimatingLw()) {
2710 // If the nav bar is currently requested to be visible,
2711 // and not in the process of animating on or off, then
2712 // we can tell the app that it is covered by it.
2713 mSystemBottom = mTmpNavigationFrame.top;
2714 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002715 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002716 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002717 int left = displayWidth - overscanRight
2718 - mNavigationBarWidthForRotation[displayRotation];
2719 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07002720 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002721 if (navBarHideyShowing) {
2722 mNavigationBar.showLw(true);
2723 } else if (navVisible) {
Craig Mautner69b08182012-09-05 13:07:13 -07002724 mNavigationBar.showLw(true);
2725 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08002726 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
2727 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07002728 } else {
2729 // We currently want to hide the navigation UI.
2730 mNavigationBar.hideLw(true);
2731 }
2732 if (navVisible && !mNavigationBar.isAnimatingLw()) {
2733 // If the nav bar is currently requested to be visible,
2734 // and not in the process of animating on or off, then
2735 // we can tell the app that it is covered by it.
2736 mSystemRight = mTmpNavigationFrame.left;
2737 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002738 }
Craig Mautner69b08182012-09-05 13:07:13 -07002739 // Make sure the content and current rectangles are updated to
2740 // account for the restrictions from the navigation bar.
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002741 mContentTop = mCurTop = mDockTop;
2742 mContentBottom = mCurBottom = mDockBottom;
2743 mContentLeft = mCurLeft = mDockLeft;
2744 mContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002745 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2746 // And compute the final frame.
2747 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002748 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07002749 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002750 if (mNavigationHideybar == HIDEYBAR_HIDING && !mNavigationBar.isVisibleLw()) {
2751 // Finished animating out, clean up and reset alpha
2752 mNavigationHideybar = HIDEYBAR_NONE;
2753 updateSysUiVisibility = true;
2754 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002755 }
Craig Mautnereda67292013-04-28 13:50:14 -07002756 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07002757 mDockLeft, mDockTop, mDockRight, mDockBottom));
2758
2759 // decide where the status bar goes ahead of time
2760 if (mStatusBar != null) {
2761 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002762 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
2763 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2764 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
2765 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
2766 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002767 vf.left = mStableLeft;
2768 vf.top = mStableTop;
2769 vf.right = mStableRight;
2770 vf.bottom = mStableBottom;
2771
2772 mStatusBarLayer = mStatusBar.getSurfaceLayer();
2773
2774 // Let the status bar determine its size.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002775 mStatusBar.computeFrameLw(pf, df, vf, vf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002776
2777 // For layout, the status bar is always at the top with our fixed height.
2778 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
2779
John Spurlock32beb2c2013-03-11 10:16:47 -04002780 boolean statusBarOverlay = (mLastSystemUiFlags & View.STATUS_BAR_OVERLAY) != 0;
2781
Craig Mautner69b08182012-09-05 13:07:13 -07002782 // If the status bar is hidden, we don't want to cause
2783 // windows behind it to scroll.
John Spurlock32beb2c2013-03-11 10:16:47 -04002784 if (mStatusBar.isVisibleLw() && !statusBarOverlay) {
Craig Mautner69b08182012-09-05 13:07:13 -07002785 // Status bar may go away, so the screen area it occupies
2786 // is available to apps but just covering them when the
2787 // status bar is visible.
2788 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
2789
2790 mContentTop = mCurTop = mDockTop;
2791 mContentBottom = mCurBottom = mDockBottom;
2792 mContentLeft = mCurLeft = mDockLeft;
2793 mContentRight = mCurRight = mDockRight;
2794
Craig Mautnereda67292013-04-28 13:50:14 -07002795 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07002796 String.format(
2797 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
2798 mDockLeft, mDockTop, mDockRight, mDockBottom,
2799 mContentLeft, mContentTop, mContentRight, mContentBottom,
2800 mCurLeft, mCurTop, mCurRight, mCurBottom));
2801 }
John Spurlock32beb2c2013-03-11 10:16:47 -04002802 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw() && !statusBarOverlay) {
Craig Mautner69b08182012-09-05 13:07:13 -07002803 // If the status bar is currently requested to be visible,
2804 // and not in the process of animating on or off, then
2805 // we can tell the app that it is covered by it.
2806 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
2807 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04002808
2809 if (mStatusHideybar == HIDEYBAR_HIDING && !mStatusBar.isVisibleLw()) {
2810 // Finished animating out, clean up and reset alpha
2811 mStatusHideybar = HIDEYBAR_NONE;
2812 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04002813 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002814 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04002815 if (updateSysUiVisibility) {
2816 updateSystemUiVisibilityLw();
2817 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002818 }
2819 }
2820
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002821 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002822 @Override
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002823 public int getSystemDecorRectLw(Rect systemRect) {
2824 systemRect.left = mSystemLeft;
2825 systemRect.top = mSystemTop;
2826 systemRect.right = mSystemRight;
2827 systemRect.bottom = mSystemBottom;
2828 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
2829 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
2830 return 0;
2831 }
2832
Craig Mautner967212c2013-04-13 21:10:58 -07002833 @Override
2834 public void getContentRectLw(Rect r) {
2835 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
2836 }
2837
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002838 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
2839 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002840 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
2841 // Here's a special case: if this attached window is a panel that is
2842 // above the dock window, and the window it is attached to is below
2843 // the dock window, then the frames we computed for the window it is
2844 // attached to can not be used because the dock is effectively part
2845 // of the underlying window and the attached window is floating on top
2846 // of the whole thing. So, we ignore the attached window and explicitly
2847 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002848 df.left = of.left = cf.left = vf.left = mDockLeft;
2849 df.top = of.top = cf.top = vf.top = mDockTop;
2850 df.right = of.right = cf.right = vf.right = mDockRight;
2851 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002852 } else {
2853 // The effective display frame of the attached window depends on
2854 // whether it is taking care of insetting its content. If not,
2855 // we need to use the parent's content frame so that the entire
2856 // window is positioned within that content. Otherwise we can use
2857 // the display frame and let the attached window take care of
2858 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002859 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002860 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002861 } else {
2862 // If the window is resizing, then we want to base the content
2863 // frame on our attached content frame to resize... however,
2864 // things can be tricky if the attached window is NOT in resize
2865 // mode, in which case its content frame will be larger.
2866 // Ungh. So to deal with that, make sure the content frame
2867 // we end up using is not covering the IM dock.
2868 cf.set(attached.getContentFrameLw());
2869 if (attached.getSurfaceLayer() < mDockLayer) {
2870 if (cf.left < mContentLeft) cf.left = mContentLeft;
2871 if (cf.top < mContentTop) cf.top = mContentTop;
2872 if (cf.right > mContentRight) cf.right = mContentRight;
2873 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
2874 }
2875 }
2876 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002877 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002878 vf.set(attached.getVisibleFrameLw());
2879 }
2880 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
2881 // window should be positioned relative to its parent or the entire
2882 // screen.
2883 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
2884 ? attached.getFrameLw() : df);
2885 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002886
2887 private void applyStableConstraints(int sysui, int fl, Rect r) {
2888 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2889 // If app is requesting a stable layout, don't let the
2890 // content insets go below the stable values.
2891 if ((fl & FLAG_FULLSCREEN) != 0) {
2892 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
2893 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
2894 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
2895 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
2896 } else {
2897 if (r.left < mStableLeft) r.left = mStableLeft;
2898 if (r.top < mStableTop) r.top = mStableTop;
2899 if (r.right > mStableRight) r.right = mStableRight;
2900 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
2901 }
2902 }
2903 }
2904
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002905 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002906 @Override
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07002907 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
2908 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002909 // we've already done the status bar
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002910 if (win == mStatusBar || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002911 return;
2912 }
Craig Mautner69b08182012-09-05 13:07:13 -07002913 final boolean isDefaultDisplay = win.isDefaultDisplay();
2914 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09002915 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
2916 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07002917 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09002918 offsetInputMethodWindowLw(mLastInputMethodWindow);
2919 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002920
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002921 final int fl = attrs.flags;
2922 final int sim = attrs.softInputMode;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002923 final int sysUiFl = win.getSystemUiVisibility();
2924
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002925 final Rect pf = mTmpParentFrame;
2926 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002927 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002928 final Rect cf = mTmpContentFrame;
2929 final Rect vf = mTmpVisibleFrame;
Craig Mautner69b08182012-09-05 13:07:13 -07002930
2931 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04002932 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002933
Craig Mautnerf683b562012-10-02 11:10:57 -07002934 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
2935
Craig Mautner69b08182012-09-05 13:07:13 -07002936 if (!isDefaultDisplay) {
2937 if (attached != null) {
2938 // If this window is attached to another, our display
2939 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002940 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002941 } else {
2942 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002943 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
2944 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
2945 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08002946 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002947 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002948 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07002949 }
2950 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002951 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
2952 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
2953 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
2954 pf.bottom = df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002955 // IM dock windows always go to the bottom of the screen.
2956 attrs.gravity = Gravity.BOTTOM;
2957 mDockLayer = win.getSurfaceLayer();
2958 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002959 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
2960 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Craig Mautnereda67292013-04-28 13:50:14 -07002961 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002962 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002963 // This is the case for a normal activity window: we want it
2964 // to cover all of the screen space, and it can take care of
2965 // moving its contents to account for screen decorations that
2966 // intrude into that space.
2967 if (attached != null) {
2968 // If this window is attached to another, our display
2969 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002970 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002971 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002972 if (attrs.type == TYPE_STATUS_BAR_PANEL
2973 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08002974 // Status bar panels are the only windows who can go on top of
2975 // the status bar. They are protected by the STATUS_BAR_SERVICE
2976 // permission, so they have the same privileges as the status
2977 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002978 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002979 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002980
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002981 pf.left = df.left = of.left = hasNavBar
2982 ? mDockLeft : mUnrestrictedScreenLeft;
2983 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2984 pf.right = df.right = of.right = hasNavBar
2985 ? mRestrictedScreenLeft+mRestrictedScreenWidth
2986 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2987 pf.bottom = df.bottom = of.bottom = hasNavBar
2988 ? mRestrictedScreenTop+mRestrictedScreenHeight
2989 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002990
Craig Mautnereda67292013-04-28 13:50:14 -07002991 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04002992 "Laying out status bar window: (%d,%d - %d,%d)",
2993 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackbornc652de82013-02-15 16:32:56 -08002994 } else if ((attrs.flags&FLAG_LAYOUT_IN_OVERSCAN) != 0
2995 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
2996 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
2997 // Asking to layout into the overscan region, so give it that pure
2998 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002999 pf.left = df.left = of.left = mOverscanScreenLeft;
3000 pf.top = df.top = of.top = mOverscanScreenTop;
3001 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3002 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3003 + mOverscanScreenHeight;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003004 } else if (mCanHideNavigationBar
3005 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003006 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3007 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3008 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003009 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003010 // only do this for application windows to ensure no window that
3011 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003012 pf.left = df.left = mOverscanScreenLeft;
3013 pf.top = df.top = mOverscanScreenTop;
3014 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3015 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003016 // We need to tell the app about where the frame inside the overscan
3017 // is, so it can inset its content by that amount -- it didn't ask
3018 // to actually extend itself into the overscan region.
3019 of.left = mUnrestrictedScreenLeft;
3020 of.top = mUnrestrictedScreenTop;
3021 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3022 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003023 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003024 pf.left = df.left = mRestrictedOverscanScreenLeft;
3025 pf.top = df.top = mRestrictedOverscanScreenTop;
3026 pf.right = df.right = mRestrictedOverscanScreenLeft
3027 + mRestrictedOverscanScreenWidth;
3028 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3029 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003030 // We need to tell the app about where the frame inside the overscan
3031 // is, so it can inset its content by that amount -- it didn't ask
3032 // to actually extend itself into the overscan region.
3033 of.left = mUnrestrictedScreenLeft;
3034 of.top = mUnrestrictedScreenTop;
3035 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3036 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003037 }
Craig Mautner69b08182012-09-05 13:07:13 -07003038
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003039 if ((attrs.flags&FLAG_FULLSCREEN) == 0) {
3040 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3041 cf.left = mDockLeft;
3042 cf.top = mDockTop;
3043 cf.right = mDockRight;
3044 cf.bottom = mDockBottom;
3045 } else {
3046 cf.left = mContentLeft;
3047 cf.top = mContentTop;
3048 cf.right = mContentRight;
3049 cf.bottom = mContentBottom;
3050 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003051 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003052 // Full screen windows are always given a layout that is as if the
3053 // status bar and other transient decors are gone. This is to avoid
3054 // bad states when moving from a window that is not hding the
3055 // status bar to one that is.
3056 cf.left = mRestrictedScreenLeft;
3057 cf.top = mRestrictedScreenTop;
3058 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3059 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003060 }
Craig Mautner69b08182012-09-05 13:07:13 -07003061
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003062 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003063 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3064 vf.left = mCurLeft;
3065 vf.top = mCurTop;
3066 vf.right = mCurRight;
3067 vf.bottom = mCurBottom;
3068 } else {
3069 vf.set(cf);
3070 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003071 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003072 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3073 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3074 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003075 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3076 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003077 // A window that has requested to fill the entire screen just
3078 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003079 if (attrs.type == TYPE_STATUS_BAR_PANEL
3080 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003081 pf.left = df.left = of.left = cf.left = hasNavBar
3082 ? mDockLeft : mUnrestrictedScreenLeft;
3083 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3084 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003085 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003086 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003087 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003088 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003089 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003090 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003091 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3092 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003093 } else if (attrs.type == TYPE_NAVIGATION_BAR
3094 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003095 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003096 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3097 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3098 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3099 + mUnrestrictedScreenWidth;
3100 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3101 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003102 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003103 "Laying out navigation bar window: (%d,%d - %d,%d)",
3104 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003105 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3106 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003107 && ((fl & FLAG_FULLSCREEN) != 0)) {
3108 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003109 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3110 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3111 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3112 + mOverscanScreenWidth;
3113 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3114 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003115 } else if (attrs.type == TYPE_BOOT_PROGRESS
3116 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003117 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003118 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3119 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3120 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3121 + mOverscanScreenWidth;
3122 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3123 + mOverscanScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -08003124 } else if (attrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER) {
3125 // The wallpaper mostly goes into the overscan region.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003126 pf.left = df.left = of.left = cf.left = mRestrictedOverscanScreenLeft;
3127 pf.top = df.top = of.top = cf.top = mRestrictedOverscanScreenTop;
3128 pf.right = df.right = of.right = cf.right
Dianne Hackborn313440842013-02-19 19:22:59 -08003129 = mRestrictedOverscanScreenLeft + mRestrictedOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003130 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackborn313440842013-02-19 19:22:59 -08003131 = mRestrictedOverscanScreenTop + mRestrictedOverscanScreenHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003132 } else if ((attrs.flags & FLAG_LAYOUT_IN_OVERSCAN) != 0
3133 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3134 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3135 // Asking to layout into the overscan region, so give it that pure
3136 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003137 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3138 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3139 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003140 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003141 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003142 = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003143 } else if (mCanHideNavigationBar
3144 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003145 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3146 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3147 // Asking for layout as if the nav bar is hidden, lets the
3148 // application extend into the unrestricted screen area. We
3149 // only do this for application windows to ensure no window that
3150 // can be above the nav bar can do this.
3151 // XXX This assumes that an app asking for this will also
3152 // ask for layout in only content. We can't currently figure out
3153 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003154 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3155 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3156 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3157 + mUnrestrictedScreenWidth;
3158 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3159 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003160 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003161 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3162 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3163 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3164 + mRestrictedScreenWidth;
3165 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3166 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003167 }
Craig Mautner69b08182012-09-05 13:07:13 -07003168
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003169 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003170
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003171 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3172 vf.left = mCurLeft;
3173 vf.top = mCurTop;
3174 vf.right = mCurRight;
3175 vf.bottom = mCurBottom;
3176 } else {
3177 vf.set(cf);
3178 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003179 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003180 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3181 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003182 // A child window should be placed inside of the same visible
3183 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003184 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003185 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003186 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3187 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003188 // Otherwise, a normal window must be placed inside the content
3189 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003190 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3191 // Status bar panels are the only windows who can go on top of
3192 // the status bar. They are protected by the STATUS_BAR_SERVICE
3193 // permission, so they have the same privileges as the status
3194 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003195 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3196 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3197 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3198 + mRestrictedScreenWidth;
3199 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3200 + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003201 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003202 pf.left = mContentLeft;
3203 pf.top = mContentTop;
3204 pf.right = mContentRight;
3205 pf.bottom = mContentBottom;
3206 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003207 df.left = of.left = cf.left = mDockLeft;
3208 df.top = of.top = cf.top = mDockTop;
3209 df.right = of.right = cf.right = mDockRight;
3210 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003211 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003212 df.left = of.left = cf.left = mContentLeft;
3213 df.top = of.top = cf.top = mContentTop;
3214 df.right = of.right = cf.right = mContentRight;
3215 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003216 }
3217 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3218 vf.left = mCurLeft;
3219 vf.top = mCurTop;
3220 vf.right = mCurRight;
3221 vf.bottom = mCurBottom;
3222 } else {
3223 vf.set(cf);
3224 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003225 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003226 }
3227 }
Craig Mautner69b08182012-09-05 13:07:13 -07003228
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003229 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003230 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3231 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3232 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003233 }
3234
Craig Mautnereda67292013-04-28 13:50:14 -07003235 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003236 + ": sim=#" + Integer.toHexString(sim)
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003237 + " attach=" + attached + " type=" + attrs.type
3238 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003239 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003240 + " of=" + of.toShortString()
The Android Open Source Project11267662009-03-18 17:39:47 -07003241 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003242
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003243 win.computeFrameLw(pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003244
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003245 // Dock windows carve out the bottom of the screen, so normal windows
3246 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003247 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3248 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003249 setLastInputMethodWindowLw(null, null);
3250 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003251 }
3252 }
3253
satok1bc0a492012-04-25 22:47:12 +09003254 private void offsetInputMethodWindowLw(WindowState win) {
3255 int top = win.getContentFrameLw().top;
3256 top += win.getGivenContentInsetsLw().top;
3257 if (mContentBottom > top) {
3258 mContentBottom = top;
3259 }
3260 top = win.getVisibleFrameLw().top;
3261 top += win.getGivenVisibleInsetsLw().top;
3262 if (mCurBottom > top) {
3263 mCurBottom = top;
3264 }
Craig Mautnereda67292013-04-28 13:50:14 -07003265 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003266 + mDockBottom + " mContentBottom="
3267 + mContentBottom + " mCurBottom=" + mCurBottom);
3268 }
3269
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003270 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003271 @Override
3272 public void finishLayoutLw() {
3273 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003274 }
3275
3276 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003277 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003278 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003279 mTopFullscreenOpaqueWindowState = null;
3280 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003281 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003282 mForcingShowNavBar = false;
3283 mForcingShowNavBarLayer = -1;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003284
3285 mHideLockScreen = false;
3286 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003287 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003288 mShowingLockscreen = false;
3289 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003290 }
3291
3292 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003293 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003294 public void applyPostLayoutPolicyLw(WindowState win,
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003295 WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003296 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3297 + win.isVisibleOrBehindKeyguardLw());
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003298 if (mTopFullscreenOpaqueWindowState == null && (win.getAttrs().privateFlags
3299 &WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_SHOW_NAV_BAR) != 0) {
3300 if (mForcingShowNavBarLayer < 0) {
3301 mForcingShowNavBar = true;
3302 mForcingShowNavBarLayer = win.getSurfaceLayer();
3303 }
3304 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003305 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003306 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003307 if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003308 if (attrs.type == TYPE_KEYGUARD) {
3309 mForceStatusBarFromKeyguard = true;
3310 } else {
3311 mForceStatusBar = true;
3312 }
3313 }
3314 if (attrs.type == TYPE_KEYGUARD) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003315 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003316 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003317 boolean applyWindow = attrs.type >= FIRST_APPLICATION_WINDOW
3318 && attrs.type <= LAST_APPLICATION_WINDOW;
3319 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003320 // If the lockscreen was showing when the dream started then wait
3321 // for the dream to draw before hiding the lockscreen.
3322 if (!mDreamingLockscreen
3323 || (win.isVisibleLw() && win.hasDrawnLw())) {
3324 mShowingDream = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003325 applyWindow = true;
3326 }
3327 }
3328 if (applyWindow
Dianne Hackborn6493e642010-10-01 13:06:30 -07003329 && attrs.x == 0 && attrs.y == 0
3330 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3331 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
Craig Mautnereda67292013-04-28 13:50:14 -07003332 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003333 mTopFullscreenOpaqueWindowState = win;
3334 if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003335 if (DEBUG_LAYOUT) Slog.v(TAG, "Setting mHideLockScreen to true by win " + win);
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003336 mHideLockScreen = true;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003337 mForceStatusBarFromKeyguard = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003338 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003339 if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0
3340 && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautnereda67292013-04-28 13:50:14 -07003341 if (DEBUG_LAYOUT) Slog.v(TAG, "Setting mDismissKeyguard true by win " + win);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003342 mDismissKeyguard = mWinDismissingKeyguard == win ?
3343 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3344 mWinDismissingKeyguard = win;
Craig Mautnereda67292013-04-28 13:50:14 -07003345 mForceStatusBarFromKeyguard = mShowingLockscreen && isKeyguardSecure();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003346 }
3347 if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
3348 mAllowLockscreenWhenOn = true;
3349 }
3350 }
3351 }
3352 }
3353
3354 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003355 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003356 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003357 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003358 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003359
3360 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3361 ? mTopFullscreenOpaqueWindowState.getAttrs()
3362 : null;
3363
Jeff Brownc8018eb2012-10-29 21:33:27 -07003364 // If we are not currently showing a dream then remember the current
3365 // lockscreen state. We will use this to determine whether the dream
3366 // started while the lockscreen was showing and remember this state
3367 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003368 if (!mShowingDream) {
3369 mDreamingLockscreen = mShowingLockscreen;
3370 }
3371
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003372 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003373 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003374 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003375 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003376 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003377 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003378 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003379 } else if (mTopFullscreenOpaqueWindowState != null) {
Joe Onorato93056472010-09-10 10:30:46 -04003380 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003381 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003382 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003383 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
Joe Onorato93056472010-09-10 10:30:46 -04003384 + " lp.flags=0x" + Integer.toHexString(lp.flags));
3385 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003386 topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
3387 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003388 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3389 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3390 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3391 // case though.
John Spurlockad3e6cb2013-04-30 08:47:43 -04003392 if (mStatusHideybar == HIDEYBAR_SHOWING) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003393 if (mStatusBar.showLw(true)) {
3394 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3395 }
3396 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003397 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003398 if (mStatusBar.hideLw(true)) {
3399 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Daniel Sandler9c00d5b2011-09-13 14:04:26 -04003400
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003401 mHandler.post(new Runnable() {
3402 @Override
3403 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07003404 try {
3405 IStatusBarService statusbar = getStatusBarService();
3406 if (statusbar != null) {
Daniel Sandler11cf1782012-09-27 14:03:08 -04003407 statusbar.collapsePanels();
Dianne Hackborn42e620c2012-06-24 13:20:51 -07003408 }
3409 } catch (RemoteException ex) {
3410 // re-acquire status bar service next time it is needed.
3411 mStatusBarService = null;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003412 }
3413 }});
Craig Mautnereda67292013-04-28 13:50:14 -07003414 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003415 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003416 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003417 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003418 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003419 if (mStatusBar.showLw(true)) changes |= FINISH_LAYOUT_REDO_LAYOUT;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003420 }
3421 }
3422 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003423
Joe Onorato644f9c32011-01-25 12:06:23 -08003424 mTopIsFullscreen = topIsFullscreen;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003425
Craig Mautner39834192012-09-02 07:47:24 -07003426 // Hide the key guard if a visible window explicitly specifies that it wants to be
3427 // displayed when the screen is locked.
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003428 if (mKeyguard != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003429 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
Craig Mautner39834192012-09-02 07:47:24 -07003430 + mHideLockScreen);
Jim Miller5ecd8112013-01-09 18:50:26 -08003431 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardDelegate.isSecure()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003432 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003433 changes |= FINISH_LAYOUT_REDO_LAYOUT
3434 | FINISH_LAYOUT_REDO_CONFIG
3435 | FINISH_LAYOUT_REDO_WALLPAPER;
3436 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003437 if (mKeyguardDelegate.isShowing()) {
Dianne Hackbornb446e972009-09-20 15:23:25 -07003438 mHandler.post(new Runnable() {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003439 @Override
Dianne Hackbornb446e972009-09-20 15:23:25 -07003440 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08003441 mKeyguardDelegate.keyguardDone(false, false);
Dianne Hackbornb446e972009-09-20 15:23:25 -07003442 }
3443 });
3444 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003445 } else if (mHideLockScreen) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003446 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003447 changes |= FINISH_LAYOUT_REDO_LAYOUT
3448 | FINISH_LAYOUT_REDO_CONFIG
3449 | FINISH_LAYOUT_REDO_WALLPAPER;
3450 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003451 mKeyguardDelegate.setHidden(true);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003452 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3453 // This is the case of keyguard isSecure() and not mHideLockScreen.
3454 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3455 // Only launch the next keyguard unlock window once per window.
3456 if (mKeyguard.showLw(true)) {
3457 changes |= FINISH_LAYOUT_REDO_LAYOUT
3458 | FINISH_LAYOUT_REDO_CONFIG
3459 | FINISH_LAYOUT_REDO_WALLPAPER;
3460 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003461 mKeyguardDelegate.setHidden(false);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003462 mHandler.post(new Runnable() {
3463 @Override
3464 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08003465 mKeyguardDelegate.dismiss();
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003466 }
3467 });
3468 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003469 } else {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003470 mWinDismissingKeyguard = null;
Dianne Hackborn08743722009-12-21 12:16:51 -08003471 if (mKeyguard.showLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003472 changes |= FINISH_LAYOUT_REDO_LAYOUT
3473 | FINISH_LAYOUT_REDO_CONFIG
3474 | FINISH_LAYOUT_REDO_WALLPAPER;
3475 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003476 mKeyguardDelegate.setHidden(false);
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003477 }
3478 }
Joe Onorato664644d2011-01-23 17:53:23 -08003479
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003480 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003481 // If the navigation bar has been hidden or shown, we need to do another
3482 // layout pass to update that window.
3483 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3484 }
Joe Onorato664644d2011-01-23 17:53:23 -08003485
Mike Lockwood28569302010-01-28 11:54:40 -05003486 // update since mAllowLockscreenWhenOn might have changed
3487 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003488 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003489 }
3490
Dianne Hackborn08743722009-12-21 12:16:51 -08003491 public boolean allowAppAnimationsLw() {
Craig Mautnerf03e4c52012-06-14 14:11:27 -07003492 if (mKeyguard != null && mKeyguard.isVisibleLw() && !mKeyguard.isAnimatingLw()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003493 // If keyguard is currently visible, no reason to animate
3494 // behind it.
3495 return false;
3496 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003497 return true;
3498 }
3499
Dianne Hackborndf89e652011-10-06 22:35:11 -07003500 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003501 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003502 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003503 // If the navigation bar has been hidden or shown, we need to do another
3504 // layout pass to update that window.
3505 return FINISH_LAYOUT_REDO_LAYOUT;
3506 }
3507 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003508 }
3509
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003510 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07003511 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003512 // do nothing if headless
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003513 if (mHeadless) return;
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003514
Jeff Brown46b9ac02010-04-22 18:58:52 -07003515 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003516 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3517 if (newLidState == mLidState) {
3518 return;
3519 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003520
Jeff Brownc458ce92012-04-30 14:58:40 -07003521 mLidState = newLidState;
3522 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003523 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003524
3525 if (lidOpen) {
3526 if (keyguardIsShowingTq()) {
Jim Miller5ecd8112013-01-09 18:50:26 -08003527 mKeyguardDelegate.onWakeKeyWhenKeyguardShowingTq(KeyEvent.KEYCODE_POWER);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003528 } else {
Jeff Brown96307042012-07-27 15:51:34 -07003529 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brown46b9ac02010-04-22 18:58:52 -07003530 }
Jeff Brownc458ce92012-04-30 14:58:40 -07003531 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003532 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003533 }
3534 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003535
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003536 void setHdmiPlugged(boolean plugged) {
3537 if (mHdmiPlugged != plugged) {
3538 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003539 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003540 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003541 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003542 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003543 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003544 }
3545 }
3546
Joe Onoratoea495d42011-04-06 11:41:11 -07003547 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003548 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003549 // watch for HDMI plug messages if the hdmi switch exists
3550 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3551 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3552
Joe Onoratoea495d42011-04-06 11:41:11 -07003553 final String filename = "/sys/class/switch/hdmi/state";
3554 FileReader reader = null;
3555 try {
3556 reader = new FileReader(filename);
3557 char[] buf = new char[15];
3558 int n = reader.read(buf);
3559 if (n > 1) {
3560 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3561 }
3562 } catch (IOException ex) {
3563 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3564 } catch (NumberFormatException ex) {
3565 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3566 } finally {
3567 if (reader != null) {
3568 try {
3569 reader.close();
3570 } catch (IOException ex) {
3571 }
Joe Onoratodc100302011-01-11 17:07:41 -08003572 }
3573 }
3574 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07003575 // This dance forces the code in setHdmiPlugged to run.
3576 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
3577 mHdmiPlugged = !plugged;
3578 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08003579 }
3580
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003581 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003582 * @return Whether music is being played right now.
3583 */
3584 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07003585 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
3586 if (am == null) {
3587 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003588 return false;
3589 }
Eric Laurent413cb9d2009-07-17 11:52:43 -07003590 return am.isMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003591 }
3592
3593 /**
3594 * Tell the audio service to adjust the volume appropriate to the event.
3595 * @param keycode
3596 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04003597 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07003598 IAudioService audioService = getAudioService();
3599 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003600 return;
3601 }
3602 try {
3603 // since audio is playing, we shouldn't have to hold a wake lock
3604 // during the call, but we do it as a precaution for the rare possibility
3605 // that the music stops right before we call this
Jeff Brownb0418da2010-11-01 15:24:01 -07003606 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003607 mBroadcastWakeLock.acquire();
Jeff Brown4d396052010-10-29 21:50:21 -07003608 audioService.adjustStreamVolume(stream,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003609 keycode == KeyEvent.KEYCODE_VOLUME_UP
3610 ? AudioManager.ADJUST_RAISE
3611 : AudioManager.ADJUST_LOWER,
Dianne Hackbornba50b97c2013-04-30 15:04:46 -07003612 0,
3613 mContext.getBasePackageName());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003614 } catch (RemoteException e) {
3615 Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e);
3616 } finally {
3617 mBroadcastWakeLock.release();
3618 }
3619 }
Jeff Brown4d396052010-10-29 21:50:21 -07003620
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07003621 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003622 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003623
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003624 final Runnable mScreenshotTimeout = new Runnable() {
3625 @Override public void run() {
3626 synchronized (mScreenshotLock) {
3627 if (mScreenshotConnection != null) {
3628 mContext.unbindService(mScreenshotConnection);
3629 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003630 }
Winson Chung9112ec32011-06-27 13:15:32 -07003631 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003632 }
3633 };
3634
3635 // Assume this is called from the Handler thread.
3636 private void takeScreenshot() {
3637 synchronized (mScreenshotLock) {
3638 if (mScreenshotConnection != null) {
3639 return;
3640 }
3641 ComponentName cn = new ComponentName("com.android.systemui",
3642 "com.android.systemui.screenshot.TakeScreenshotService");
3643 Intent intent = new Intent();
3644 intent.setComponent(cn);
3645 ServiceConnection conn = new ServiceConnection() {
3646 @Override
3647 public void onServiceConnected(ComponentName name, IBinder service) {
3648 synchronized (mScreenshotLock) {
3649 if (mScreenshotConnection != this) {
3650 return;
3651 }
3652 Messenger messenger = new Messenger(service);
3653 Message msg = Message.obtain(null, 1);
3654 final ServiceConnection myConn = this;
3655 Handler h = new Handler(mHandler.getLooper()) {
3656 @Override
3657 public void handleMessage(Message msg) {
3658 synchronized (mScreenshotLock) {
3659 if (mScreenshotConnection == myConn) {
3660 mContext.unbindService(mScreenshotConnection);
3661 mScreenshotConnection = null;
3662 mHandler.removeCallbacks(mScreenshotTimeout);
3663 }
3664 }
3665 }
3666 };
3667 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07003668 msg.arg1 = msg.arg2 = 0;
3669 if (mStatusBar != null && mStatusBar.isVisibleLw())
3670 msg.arg1 = 1;
3671 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
3672 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003673 try {
3674 messenger.send(msg);
3675 } catch (RemoteException e) {
3676 }
3677 }
3678 }
3679 @Override
3680 public void onServiceDisconnected(ComponentName name) {}
3681 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08003682 if (mContext.bindServiceAsUser(
3683 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003684 mScreenshotConnection = conn;
3685 mHandler.postDelayed(mScreenshotTimeout, 10000);
3686 }
3687 }
Winson Chung9112ec32011-06-27 13:15:32 -07003688 }
3689
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003690 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003691 @Override
Jeff Brown1f245102010-11-18 20:53:46 -08003692 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
Jeff Brown96307042012-07-27 15:51:34 -07003693 if (!mSystemBooted) {
3694 // If we have not yet booted, don't let key events do anything.
3695 return 0;
3696 }
3697
Jeff Brown1f245102010-11-18 20:53:46 -08003698 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3699 final boolean canceled = event.isCanceled();
3700 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07003701
Jeff Brown3122e442010-10-11 23:32:49 -07003702 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07003703
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05003704 // If screen is off then we treat the case where the keyguard is open but hidden
3705 // the same as if it were open and in front.
3706 // This will prevent any keys other than the power button from waking the screen
3707 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08003708 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003709 (isScreenOn ?
Jim Miller5ecd8112013-01-09 18:50:26 -08003710 mKeyguardDelegate.isShowingAndNotHidden() :
3711 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003712
Jeff Brown96307042012-07-27 15:51:34 -07003713 if (keyCode == KeyEvent.KEYCODE_POWER) {
3714 policyFlags |= WindowManagerPolicy.FLAG_WAKE;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003715 }
Jeff Brown96307042012-07-27 15:51:34 -07003716 final boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE
3717 | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003718
Jeff Brown40013652012-05-16 21:22:36 -07003719 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003720 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown96307042012-07-27 15:51:34 -07003721 + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive
3722 + " policyFlags=" + Integer.toHexString(policyFlags)
3723 + " isWakeKey=" + isWakeKey);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003724 }
3725
Jeff Brown98392ef2011-09-12 18:24:59 -07003726 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
3727 && event.getRepeatCount() == 0) {
Jeff Brown4d396052010-10-29 21:50:21 -07003728 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
3729 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003730
Jeff Brown4d396052010-10-29 21:50:21 -07003731 // Basic policy based on screen state and keyguard.
3732 // FIXME: This policy isn't quite correct. We shouldn't care whether the screen
3733 // is on or off, really. We should care about whether the device is in an
3734 // interactive state or is in suspend pretending to be "off".
3735 // The primary screen might be turned off due to proximity sensor or
3736 // because we are presenting media on an auxiliary screen or remotely controlling
3737 // the device some other way (which is why we have an exemption here for injected
3738 // events).
3739 int result;
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003740 if ((isScreenOn && !mHeadless) || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003741 // When the screen is on or if the key is injected pass the key to the application.
3742 result = ACTION_PASS_TO_USER;
3743 } else {
3744 // When the screen is off and the key is not injected, determine whether
3745 // to wake the device but don't pass the key to the application.
3746 result = 0;
Jeff Brown1c2e4942012-11-06 16:32:01 -08003747 if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003748 if (keyguardActive) {
Jeff Brown1c2e4942012-11-06 16:32:01 -08003749 // If the keyguard is showing, let it wake the device when ready.
Jim Miller5ecd8112013-01-09 18:50:26 -08003750 mKeyguardDelegate.onWakeKeyWhenKeyguardShowingTq(keyCode);
Jeff Brown4d396052010-10-29 21:50:21 -07003751 } else {
3752 // Otherwise, wake the device ourselves.
Jeff Brown96307042012-07-27 15:51:34 -07003753 result |= ACTION_WAKE_UP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003754 }
3755 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003756 }
3757
Justin Kohd378ad72013-04-01 12:18:26 -07003758 // If the key would be handled globally, just return the result, don't worry about special
3759 // key processing.
3760 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
3761 return result;
3762 }
3763
Jeff Brown4d396052010-10-29 21:50:21 -07003764 // Handle special keys.
3765 switch (keyCode) {
3766 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07003767 case KeyEvent.KEYCODE_VOLUME_UP:
3768 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003769 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
3770 if (down) {
3771 if (isScreenOn && !mVolumeDownKeyTriggered
3772 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3773 mVolumeDownKeyTriggered = true;
3774 mVolumeDownKeyTime = event.getDownTime();
3775 mVolumeDownKeyConsumedByScreenshotChord = false;
3776 cancelPendingPowerKeyAction();
3777 interceptScreenshotChord();
3778 }
3779 } else {
3780 mVolumeDownKeyTriggered = false;
3781 cancelPendingScreenshotChordAction();
3782 }
3783 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
3784 if (down) {
3785 if (isScreenOn && !mVolumeUpKeyTriggered
3786 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3787 mVolumeUpKeyTriggered = true;
3788 cancelPendingPowerKeyAction();
3789 cancelPendingScreenshotChordAction();
3790 }
3791 } else {
3792 mVolumeUpKeyTriggered = false;
3793 cancelPendingScreenshotChordAction();
3794 }
3795 }
Jeff Brown4d396052010-10-29 21:50:21 -07003796 if (down) {
3797 ITelephony telephonyService = getTelephonyService();
3798 if (telephonyService != null) {
3799 try {
3800 if (telephonyService.isRinging()) {
3801 // If an incoming call is ringing, either VOLUME key means
3802 // "silence ringer". We handle these keys here, rather than
3803 // in the InCallScreen, to make sure we'll respond to them
3804 // even if the InCallScreen hasn't come to the foreground yet.
3805 // Look for the DOWN event here, to agree with the "fallback"
3806 // behavior in the InCallScreen.
3807 Log.i(TAG, "interceptKeyBeforeQueueing:"
3808 + " VOLUME key-down while ringing: Silence ringer!");
3809
3810 // Silence the ringer. (It's safe to call this
3811 // even if the ringer has already been silenced.)
3812 telephonyService.silenceRinger();
3813
3814 // And *don't* pass this key thru to the current activity
3815 // (which is probably the InCallScreen.)
3816 result &= ~ACTION_PASS_TO_USER;
3817 break;
3818 }
3819 if (telephonyService.isOffhook()
3820 && (result & ACTION_PASS_TO_USER) == 0) {
3821 // If we are in call but we decided not to pass the key to
3822 // the application, handle the volume change here.
3823 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
3824 break;
3825 }
3826 } catch (RemoteException ex) {
3827 Log.w(TAG, "ITelephony threw RemoteException", ex);
3828 }
3829 }
3830
3831 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
3832 // If music is playing but we decided not to pass the key to the
3833 // application, handle the volume change here.
3834 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
3835 break;
3836 }
3837 }
3838 break;
3839 }
3840
3841 case KeyEvent.KEYCODE_ENDCALL: {
3842 result &= ~ACTION_PASS_TO_USER;
3843 if (down) {
3844 ITelephony telephonyService = getTelephonyService();
3845 boolean hungUp = false;
3846 if (telephonyService != null) {
3847 try {
3848 hungUp = telephonyService.endCall();
3849 } catch (RemoteException ex) {
3850 Log.w(TAG, "ITelephony threw RemoteException", ex);
3851 }
3852 }
3853 interceptPowerKeyDown(!isScreenOn || hungUp);
3854 } else {
3855 if (interceptPowerKeyUp(canceled)) {
3856 if ((mEndcallBehavior
3857 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
3858 if (goHome()) {
3859 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07003860 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003861 }
Jeff Brown4d396052010-10-29 21:50:21 -07003862 if ((mEndcallBehavior
3863 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown96307042012-07-27 15:51:34 -07003864 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
Jeff Brown4d396052010-10-29 21:50:21 -07003865 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003866 }
Jeff Brown4d396052010-10-29 21:50:21 -07003867 }
3868 break;
3869 }
3870
3871 case KeyEvent.KEYCODE_POWER: {
3872 result &= ~ACTION_PASS_TO_USER;
3873 if (down) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003874 if (isScreenOn && !mPowerKeyTriggered
3875 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3876 mPowerKeyTriggered = true;
3877 mPowerKeyTime = event.getDownTime();
3878 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07003879 }
Winson Chung9112ec32011-06-27 13:15:32 -07003880
Jeff Brown4d396052010-10-29 21:50:21 -07003881 ITelephony telephonyService = getTelephonyService();
3882 boolean hungUp = false;
3883 if (telephonyService != null) {
3884 try {
3885 if (telephonyService.isRinging()) {
3886 // Pressing Power while there's a ringing incoming
3887 // call should silence the ringer.
3888 telephonyService.silenceRinger();
3889 } else if ((mIncallPowerBehavior
3890 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
3891 && telephonyService.isOffhook()) {
3892 // Otherwise, if "Power button ends call" is enabled,
3893 // the Power button will hang up any current active call.
3894 hungUp = telephonyService.endCall();
3895 }
3896 } catch (RemoteException ex) {
3897 Log.w(TAG, "ITelephony threw RemoteException", ex);
3898 }
3899 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003900 interceptPowerKeyDown(!isScreenOn || hungUp
3901 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003902 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003903 mPowerKeyTriggered = false;
3904 cancelPendingScreenshotChordAction();
3905 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown96307042012-07-27 15:51:34 -07003906 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003907 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003908 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07003909 }
3910 break;
3911 }
3912
3913 case KeyEvent.KEYCODE_MEDIA_PLAY:
3914 case KeyEvent.KEYCODE_MEDIA_PAUSE:
3915 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3916 if (down) {
3917 ITelephony telephonyService = getTelephonyService();
3918 if (telephonyService != null) {
3919 try {
3920 if (!telephonyService.isIdle()) {
3921 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
3922 // to avoid music playback.
3923 break;
3924 }
3925 } catch (RemoteException ex) {
3926 Log.w(TAG, "ITelephony threw RemoteException", ex);
Jeff Brown3122e442010-10-11 23:32:49 -07003927 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003928 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003929 }
Jeff Brown4d396052010-10-29 21:50:21 -07003930 case KeyEvent.KEYCODE_HEADSETHOOK:
3931 case KeyEvent.KEYCODE_MUTE:
3932 case KeyEvent.KEYCODE_MEDIA_STOP:
3933 case KeyEvent.KEYCODE_MEDIA_NEXT:
3934 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
3935 case KeyEvent.KEYCODE_MEDIA_REWIND:
3936 case KeyEvent.KEYCODE_MEDIA_RECORD:
3937 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD: {
3938 if ((result & ACTION_PASS_TO_USER) == 0) {
3939 // Only do this if we would otherwise not pass it to the user. In that
3940 // case, the PhoneWindow class will do the same thing, except it will
3941 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07003942 // Note that we need to make a copy of the key event here because the
3943 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07003944 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07003945 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
3946 new KeyEvent(event));
3947 msg.setAsynchronous(true);
3948 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07003949 }
3950 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003951 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003952
Jeff Brown4d396052010-10-29 21:50:21 -07003953 case KeyEvent.KEYCODE_CALL: {
3954 if (down) {
3955 ITelephony telephonyService = getTelephonyService();
3956 if (telephonyService != null) {
3957 try {
3958 if (telephonyService.isRinging()) {
3959 Log.i(TAG, "interceptKeyBeforeQueueing:"
3960 + " CALL key-down while ringing: Answer the call!");
3961 telephonyService.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003962
Jeff Brown4d396052010-10-29 21:50:21 -07003963 // And *don't* pass this key thru to the current activity
3964 // (which is presumably the InCallScreen.)
3965 result &= ~ACTION_PASS_TO_USER;
3966 }
3967 } catch (RemoteException ex) {
3968 Log.w(TAG, "ITelephony threw RemoteException", ex);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003969 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003970 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003971 }
Jeff Brown4d396052010-10-29 21:50:21 -07003972 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003973 }
3974 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003975 return result;
3976 }
3977
Jeff Brown1c2e4942012-11-06 16:32:01 -08003978 /**
3979 * When the screen is off we ignore some keys that might otherwise typically
3980 * be considered wake keys. We filter them out here.
3981 *
3982 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
3983 * is always considered a wake key.
3984 */
3985 private boolean isWakeKeyWhenScreenOff(int keyCode) {
3986 switch (keyCode) {
3987 // ignore volume keys unless docked
3988 case KeyEvent.KEYCODE_VOLUME_UP:
3989 case KeyEvent.KEYCODE_VOLUME_DOWN:
3990 case KeyEvent.KEYCODE_VOLUME_MUTE:
3991 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
3992
3993 // ignore media and camera keys
3994 case KeyEvent.KEYCODE_MUTE:
3995 case KeyEvent.KEYCODE_HEADSETHOOK:
3996 case KeyEvent.KEYCODE_MEDIA_PLAY:
3997 case KeyEvent.KEYCODE_MEDIA_PAUSE:
3998 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3999 case KeyEvent.KEYCODE_MEDIA_STOP:
4000 case KeyEvent.KEYCODE_MEDIA_NEXT:
4001 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4002 case KeyEvent.KEYCODE_MEDIA_REWIND:
4003 case KeyEvent.KEYCODE_MEDIA_RECORD:
4004 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4005 case KeyEvent.KEYCODE_CAMERA:
4006 return false;
4007 }
4008 return true;
4009 }
4010
4011
Jeff Brown56194eb2011-03-02 19:23:13 -08004012 /** {@inheritDoc} */
4013 @Override
4014 public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
4015 int result = 0;
4016
4017 final boolean isWakeMotion = (policyFlags
4018 & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
4019 if (isWakeMotion) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004020 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Jeff Brown56194eb2011-03-02 19:23:13 -08004021 // If the keyguard is showing, let it decide what to do with the wake motion.
Jim Miller25190572013-02-28 17:36:24 -08004022 mKeyguardDelegate.onWakeMotionWhenKeyguardShowing();
Jeff Brown56194eb2011-03-02 19:23:13 -08004023 } else {
4024 // Otherwise, wake the device ourselves.
Jeff Brown96307042012-07-27 15:51:34 -07004025 result |= ACTION_WAKE_UP;
Jeff Brown56194eb2011-03-02 19:23:13 -08004026 }
4027 }
4028 return result;
4029 }
4030
Jeff Brown40013652012-05-16 21:22:36 -07004031 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4032 if (DEBUG_INPUT) {
4033 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004034 }
4035
Jeff Brown40013652012-05-16 21:22:36 -07004036 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4037 if (DEBUG_INPUT) {
4038 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4039 }
4040
4041 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4042 mHavePendingMediaKeyRepeatWithWakeLock = false;
4043 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4044 }
4045
4046 dispatchMediaKeyWithWakeLockToAudioService(event);
4047
4048 if (event.getAction() == KeyEvent.ACTION_DOWN
4049 && event.getRepeatCount() == 0) {
4050 mHavePendingMediaKeyRepeatWithWakeLock = true;
4051
4052 Message msg = mHandler.obtainMessage(
4053 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4054 msg.setAsynchronous(true);
4055 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4056 } else {
4057 mBroadcastWakeLock.release();
4058 }
4059 }
4060
4061 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4062 mHavePendingMediaKeyRepeatWithWakeLock = false;
4063
4064 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4065 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4066 if (DEBUG_INPUT) {
4067 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4068 }
4069
4070 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4071 mBroadcastWakeLock.release();
4072 }
4073
4074 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4075 if (ActivityManagerNative.isSystemReady()) {
4076 IAudioService audioService = getAudioService();
4077 if (audioService != null) {
4078 try {
4079 audioService.dispatchMediaKeyEventUnderWakelock(event);
4080 } catch (RemoteException e) {
4081 Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
Jean-Michel Trivic6802222012-04-30 11:15:03 -07004082 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004083 }
4084 }
4085 }
4086
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004087 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004088 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004089 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004090 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4091 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4092 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004093 } else {
4094 try {
4095 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4096 ServiceManager.getService(Context.UI_MODE_SERVICE));
4097 mUiMode = uiModeService.getCurrentModeType();
4098 } catch (RemoteException e) {
4099 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004100 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004101 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004102 synchronized (mLock) {
4103 updateOrientationListenerLp();
4104 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004105 }
4106 };
4107
Jeff Brown6aaf2952012-10-05 16:01:08 -07004108 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4109 @Override
4110 public void onReceive(Context context, Intent intent) {
4111 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004112 if (mKeyguardDelegate != null) {
4113 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004114 }
4115 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004116 if (mKeyguardDelegate != null) {
4117 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004118 }
4119 }
4120 }
4121 };
4122
Christopher Tate5e08af02012-09-21 17:17:22 -07004123 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4124 @Override
4125 public void onReceive(Context context, Intent intent) {
4126 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4127 // tickle the settings observer: this first ensures that we're
4128 // observing the relevant settings for the newly-active user,
4129 // and then updates our own bookkeeping based on the now-
4130 // current user.
4131 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004132
4133 // force a re-application of focused window sysui visibility.
4134 // the window may never have been shown for this user
4135 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004136 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004137 mLastSystemUiFlags = 0;
4138 updateSystemUiVisibilityLw();
4139 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004140 }
4141 }
4142 };
4143
John Spurlock04db1762013-05-13 12:46:41 -04004144 private void requestHideybars(WindowState swipeTarget) {
4145 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04004146 boolean sb = checkShowHideybar("status", mStatusHideybar, mStatusBar);
4147 boolean nb = checkShowHideybar("navigation", mNavigationHideybar, mNavigationBar);
4148 if (sb || nb) {
4149 WindowState hideyTarget = sb ? mStatusBar : mNavigationBar;
4150 if (sb ^ nb && hideyTarget != swipeTarget) {
4151 if (DEBUG) Slog.d(TAG, "Not showing hideybar, wrong swipe target");
4152 return;
4153 }
4154 mStatusHideybar = sb ? HIDEYBAR_SHOWING : mStatusHideybar;
4155 mNavigationHideybar = nb ? HIDEYBAR_SHOWING : mNavigationHideybar;
4156 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004157 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004158 }
4159 }
4160
4161 private boolean checkShowHideybar(String tag, int hideybar, WindowState win) {
4162 if (hideybar == HIDEYBAR_SHOWING) {
4163 if (DEBUG) Slog.d(TAG, "Not showing " + tag + " hideybar, already shown");
4164 return false;
John Spurlocke3b642e2013-05-09 15:51:32 -04004165 } else if (win == null) {
4166 if (DEBUG) Slog.d(TAG, "Not showing " + tag + " hideybar, bar doesn't exist");
4167 return false;
John Spurlockad3e6cb2013-04-30 08:47:43 -04004168 } else if (win.isDisplayedLw()) {
4169 if (DEBUG) Slog.d(TAG, "Not showing " + tag + " hideybar, bar already visible");
4170 return false;
4171 } else {
4172 return true;
John Spurlock32beb2c2013-03-11 10:16:47 -04004173 }
4174 }
4175
Jeff Brownc38c9be2012-10-04 13:16:19 -07004176 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004177 public void screenTurnedOff(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004178 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004179 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004180 mScreenOnEarly = false;
4181 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004182 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004183 if (mKeyguardDelegate != null) {
4184 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004185 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004186 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07004187 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004188 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004189 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004190 }
4191
Jeff Brownc38c9be2012-10-04 13:16:19 -07004192 @Override
Dianne Hackborn38e29a62011-09-18 14:43:08 -07004193 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004194 EventLog.writeEvent(70000, 1);
Dianne Hackborn40011092011-09-22 13:37:48 -07004195 if (false) {
4196 RuntimeException here = new RuntimeException("here");
4197 here.fillInStackTrace();
4198 Slog.i(TAG, "Screen turning on...", here);
4199 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004200
The Android Open Source Project0727d222009-03-11 12:11:58 -07004201 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004202 mScreenOnEarly = true;
The Android Open Source Project0727d222009-03-11 12:11:58 -07004203 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004204 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004205 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004206
Jeff Brownc38c9be2012-10-04 13:16:19 -07004207 waitForKeyguard(screenOnListener);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004208 }
4209
Jeff Brownc38c9be2012-10-04 13:16:19 -07004210 private void waitForKeyguard(final ScreenOnListener screenOnListener) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004211 if (mKeyguardDelegate != null) {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004212 if (screenOnListener != null) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004213 mKeyguardDelegate.onScreenTurnedOn(new KeyguardServiceDelegate.ShowListener() {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004214 @Override
4215 public void onShown(IBinder windowToken) {
4216 waitForKeyguardWindowDrawn(windowToken, screenOnListener);
4217 }
4218 });
4219 return;
4220 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -08004221 mKeyguardDelegate.onScreenTurnedOn(null);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004222 }
4223 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -08004224 Slog.i(TAG, "No keyguard interface!");
Jeff Brownc38c9be2012-10-04 13:16:19 -07004225 }
4226 finishScreenTurningOn(screenOnListener);
4227 }
4228
4229 private void waitForKeyguardWindowDrawn(IBinder windowToken,
4230 final ScreenOnListener screenOnListener) {
4231 if (windowToken != null) {
4232 try {
4233 if (mWindowManager.waitForWindowDrawn(
4234 windowToken, new IRemoteCallback.Stub() {
4235 @Override
4236 public void sendResult(Bundle data) {
4237 Slog.i(TAG, "Lock screen displayed!");
4238 finishScreenTurningOn(screenOnListener);
4239 }
4240 })) {
4241 return;
4242 }
4243 } catch (RemoteException ex) {
4244 // Can't happen in system process.
4245 }
4246 }
4247
4248 Slog.i(TAG, "No lock screen!");
4249 finishScreenTurningOn(screenOnListener);
4250 }
4251
4252 private void finishScreenTurningOn(ScreenOnListener screenOnListener) {
4253 synchronized (mLock) {
4254 mScreenOnFully = true;
4255 }
4256
Jeff Brown4fc45272012-10-10 18:28:14 -07004257 try {
4258 mWindowManager.setEventDispatching(true);
4259 } catch (RemoteException unhandled) {
4260 }
4261
Jeff Brownc38c9be2012-10-04 13:16:19 -07004262 if (screenOnListener != null) {
4263 screenOnListener.onScreenOn();
4264 }
4265 }
4266
4267 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004268 public boolean isScreenOnEarly() {
4269 return mScreenOnEarly;
4270 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004271
4272 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004273 public boolean isScreenOnFully() {
4274 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004275 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004276
Dianne Hackborn08743722009-12-21 12:16:51 -08004277 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004278 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004279 if (mKeyguardDelegate != null) {
4280 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004281 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004282 }
4283
4284 /** {@inheritDoc} */
4285 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004286 if (mKeyguardDelegate != null) {
4287 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004288 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004289 }
4290
Mike Lockwoodf7913302009-11-28 22:27:10 -05004291 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004292 if (mKeyguardDelegate == null) return false;
4293 return mKeyguardDelegate.isShowingAndNotHidden();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004294 }
4295
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004296
4297 /** {@inheritDoc} */
4298 public boolean isKeyguardLocked() {
4299 return keyguardOn();
4300 }
4301
4302 /** {@inheritDoc} */
4303 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004304 if (mKeyguardDelegate == null) return false;
4305 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004306 }
4307
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004308 /** {@inheritDoc} */
4309 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004310 if (mKeyguardDelegate == null) return false;
4311 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004312 }
4313
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004314 public void dismissKeyguardLw() {
Jim Miller195b5512013-02-28 03:35:57 -08004315 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004316 mHandler.post(new Runnable() {
4317 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004318 if (mKeyguardDelegate.isDismissable()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004319 // Can we just finish the keyguard straight away?
Jim Miller5ecd8112013-01-09 18:50:26 -08004320 mKeyguardDelegate.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004321 } else {
4322 // ask the keyguard to prompt the user to authenticate if necessary
Jim Miller5ecd8112013-01-09 18:50:26 -08004323 mKeyguardDelegate.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004324 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004325 }
4326 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004327 }
4328 }
4329
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004330 void sendCloseSystemWindows() {
4331 sendCloseSystemWindows(mContext, null);
4332 }
4333
4334 void sendCloseSystemWindows(String reason) {
4335 sendCloseSystemWindows(mContext, reason);
4336 }
4337
4338 static void sendCloseSystemWindows(Context context, String reason) {
4339 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004340 try {
4341 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4342 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004343 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004344 }
4345 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004346
Jeff Brown01a98dd2011-09-20 15:08:29 -07004347 @Override
4348 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004349 if (false) {
4350 Slog.v(TAG, "rotationForOrientationLw(orient="
4351 + orientation + ", last=" + lastRotation
4352 + "); user=" + mUserRotation + " "
4353 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4354 ? "USER_ROTATION_LOCKED" : "")
4355 );
4356 }
4357
The Android Open Source Project0727d222009-03-11 12:11:58 -07004358 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004359 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4360 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004361 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004362 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004363
Jeff Browndec6cf42011-11-15 14:08:20 -08004364 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004365 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004366 // Ignore sensor when lid switch is open and rotation is forced.
4367 preferredRotation = mLidOpenRotation;
4368 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004369 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004370 // Ignore sensor when in car dock unless explicitly enabled.
4371 // This case can override the behavior of NOSENSOR, and can also
4372 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004373 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004374 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004375 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4376 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4377 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004378 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004379 // Ignore sensor when in desk dock unless explicitly enabled.
4380 // This case can override the behavior of NOSENSOR, and can also
4381 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004382 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004383 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004384 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4385 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004386 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004387 preferredRotation = mDemoHdmiRotation;
4388 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4389 && mUndockedHdmiRotation >= 0) {
4390 // Ignore sensor when plugged into HDMI and an undocked orientation has
4391 // been specified in the configuration (only for legacy devices without
4392 // full multi-display support).
4393 // Note that the dock orientation overrides the HDMI orientation.
4394 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004395 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4396 // Application just wants to remain locked in the last rotation.
4397 preferredRotation = lastRotation;
Jeff Brown207673cd2012-06-05 17:47:11 -07004398 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004399 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004400 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4401 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4402 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4403 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004404 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4405 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4406 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4407 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4408 // Otherwise, use sensor only if requested by the application or enabled
4409 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004410 if (mAllowAllRotations < 0) {
4411 // Can't read this during init() because the context doesn't
4412 // have display metrics at that time so we cannot determine
4413 // tablet vs. phone then.
4414 mAllowAllRotations = mContext.getResources().getBoolean(
4415 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4416 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004417 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004418 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004419 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4420 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004421 preferredRotation = sensorRotation;
4422 } else {
4423 preferredRotation = lastRotation;
4424 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004425 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4426 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4427 // Apply rotation lock. Does not apply to NOSENSOR.
4428 // The idea is that the user rotation expresses a weak preference for the direction
4429 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4430 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004431 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004432 } else {
4433 // No overriding preference.
4434 // We will do exactly what the application asked us to do.
4435 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004436 }
4437
Dianne Hackborne5439f22010-10-02 16:53:50 -07004438 switch (orientation) {
4439 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004440 // Return portrait unless overridden.
4441 if (isAnyPortrait(preferredRotation)) {
4442 return preferredRotation;
4443 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004444 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004445
Jeff Brown01a98dd2011-09-20 15:08:29 -07004446 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004447 // Return landscape unless overridden.
4448 if (isLandscapeOrSeascape(preferredRotation)) {
4449 return preferredRotation;
4450 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004451 return mLandscapeRotation;
4452
4453 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004454 // Return reverse portrait unless overridden.
4455 if (isAnyPortrait(preferredRotation)) {
4456 return preferredRotation;
4457 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004458 return mUpsideDownRotation;
4459
4460 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004461 // Return seascape unless overridden.
4462 if (isLandscapeOrSeascape(preferredRotation)) {
4463 return preferredRotation;
4464 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004465 return mSeascapeRotation;
4466
4467 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004468 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004469 // Return either landscape rotation.
4470 if (isLandscapeOrSeascape(preferredRotation)) {
4471 return preferredRotation;
4472 }
4473 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004474 return lastRotation;
4475 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004476 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004477
Jeff Brown01a98dd2011-09-20 15:08:29 -07004478 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004479 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004480 // Return either portrait rotation.
4481 if (isAnyPortrait(preferredRotation)) {
4482 return preferredRotation;
4483 }
4484 if (isAnyPortrait(lastRotation)) {
4485 return lastRotation;
4486 }
4487 return mPortraitRotation;
4488
4489 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004490 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4491 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004492 if (preferredRotation >= 0) {
4493 return preferredRotation;
4494 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004495 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004496 }
4497 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004498 }
4499
Jeff Brown01a98dd2011-09-20 15:08:29 -07004500 @Override
4501 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4502 switch (orientation) {
4503 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4504 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4505 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4506 return isAnyPortrait(rotation);
4507
4508 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4509 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4510 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4511 return isLandscapeOrSeascape(rotation);
4512
4513 default:
4514 return true;
4515 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004516 }
4517
Jeff Brownc0347aa2011-09-23 17:26:09 -07004518 @Override
4519 public void setRotationLw(int rotation) {
4520 mOrientationListener.setCurrentRotation(rotation);
4521 }
4522
Jeff Brown01a98dd2011-09-20 15:08:29 -07004523 private boolean isLandscapeOrSeascape(int rotation) {
4524 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004525 }
4526
Jeff Brown01a98dd2011-09-20 15:08:29 -07004527 private boolean isAnyPortrait(int rotation) {
4528 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004529 }
4530
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004531 public int getUserRotationMode() {
4532 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07004533 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
4534 WindowManagerPolicy.USER_ROTATION_FREE :
4535 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004536 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004537
4538 // User rotation: to be used when all else fails in assigning an orientation to the device
4539 public void setUserRotationMode(int mode, int rot) {
4540 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004541
4542 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004543 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004544 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004545 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004546 rot,
4547 UserHandle.USER_CURRENT);
4548 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004549 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004550 0,
4551 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004552 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004553 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004554 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004555 1,
4556 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004557 }
4558 }
4559
Jeff Brownac143512012-04-05 18:57:33 -07004560 public void setSafeMode(boolean safeMode) {
4561 mSafeMode = safeMode;
4562 performHapticFeedbackLw(null, safeMode
4563 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4564 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004565 }
Craig Mautnereda67292013-04-28 13:50:14 -07004566
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004567 static long[] getLongIntArray(Resources r, int resid) {
4568 int[] ar = r.getIntArray(resid);
4569 if (ar == null) {
4570 return null;
4571 }
4572 long[] out = new long[ar.length];
4573 for (int i=0; i<ar.length; i++) {
4574 out[i] = ar[i];
4575 }
4576 return out;
4577 }
Craig Mautnereda67292013-04-28 13:50:14 -07004578
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004579 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004580 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004581 public void systemReady() {
Jim Miller195b5512013-02-28 03:35:57 -08004582 if (!mHeadless) {
4583 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
Jim Miller5ecd8112013-01-09 18:50:26 -08004584 mKeyguardDelegate.onSystemReady();
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004585 }
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004586 synchronized (mLock) {
4587 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08004588 mSystemReady = true;
4589 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07004590 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08004591 public void run() {
4592 updateSettings();
4593 }
4594 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004595 }
4596 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07004597
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004598 /** {@inheritDoc} */
4599 public void systemBooted() {
4600 synchronized (mLock) {
4601 mSystemBooted = true;
4602 }
4603 }
4604
Dianne Hackborn661cd522011-08-22 00:26:20 -07004605 ProgressDialog mBootMsgDialog = null;
4606
4607 /** {@inheritDoc} */
4608 public void showBootMessage(final CharSequence msg, final boolean always) {
Mike Lockwoodaa5bf142011-09-21 13:03:40 -04004609 if (mHeadless) return;
Dianne Hackborn661cd522011-08-22 00:26:20 -07004610 mHandler.post(new Runnable() {
4611 @Override public void run() {
4612 if (mBootMsgDialog == null) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07004613 mBootMsgDialog = new ProgressDialog(mContext) {
4614 // This dialog will consume all events coming in to
4615 // it, to avoid it trying to do things too early in boot.
4616 @Override public boolean dispatchKeyEvent(KeyEvent event) {
4617 return true;
4618 }
4619 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
4620 return true;
4621 }
4622 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
4623 return true;
4624 }
4625 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
4626 return true;
4627 }
4628 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
4629 return true;
4630 }
4631 @Override public boolean dispatchPopulateAccessibilityEvent(
4632 AccessibilityEvent event) {
4633 return true;
4634 }
4635 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07004636 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
4637 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
4638 mBootMsgDialog.setIndeterminate(true);
4639 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004640 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004641 mBootMsgDialog.getWindow().addFlags(
4642 WindowManager.LayoutParams.FLAG_DIM_BEHIND
4643 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
4644 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08004645 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
4646 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
4647 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004648 mBootMsgDialog.setCancelable(false);
4649 mBootMsgDialog.show();
4650 }
4651 mBootMsgDialog.setMessage(msg);
4652 }
4653 });
4654 }
4655
4656 /** {@inheritDoc} */
4657 public void hideBootMessages() {
4658 mHandler.post(new Runnable() {
4659 @Override public void run() {
4660 if (mBootMsgDialog != null) {
4661 mBootMsgDialog.dismiss();
4662 mBootMsgDialog = null;
4663 }
4664 }
4665 });
4666 }
4667
Mike Lockwood28569302010-01-28 11:54:40 -05004668 /** {@inheritDoc} */
4669 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004670 // ***************************************
4671 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
4672 // ***************************************
4673 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
4674 // WITH ITS LOCKS HELD.
4675 //
4676 // This code must be VERY careful about the locks
4677 // it acquires.
4678 // In fact, the current code acquires way too many,
4679 // and probably has lurking deadlocks.
4680
Mike Lockwood28569302010-01-28 11:54:40 -05004681 synchronized (mScreenLockTimeout) {
4682 if (mLockScreenTimerActive) {
4683 // reset the timer
4684 mHandler.removeCallbacks(mScreenLockTimeout);
4685 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4686 }
4687 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04004688 }
4689
Adam Cohenf7522022012-10-03 20:03:18 -07004690 class ScreenLockTimeout implements Runnable {
4691 Bundle options;
4692
4693 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05004694 public void run() {
4695 synchronized (this) {
4696 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08004697 if (mKeyguardDelegate != null) {
4698 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004699 }
Mike Lockwood28569302010-01-28 11:54:40 -05004700 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07004701 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05004702 }
4703 }
Mike Lockwood28569302010-01-28 11:54:40 -05004704
Adam Cohenf7522022012-10-03 20:03:18 -07004705 public void setLockOptions(Bundle options) {
4706 this.options = options;
4707 }
4708 }
4709
4710 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
4711
4712 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08004713 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
4714 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07004715 if (options != null) {
4716 // In case multiple calls are made to lockNow, we don't wipe out the options
4717 // until the runnable actually executes.
4718 mScreenLockTimeout.setLockOptions(options);
4719 }
Jim Miller93c518e2012-01-17 15:55:31 -08004720 mHandler.post(mScreenLockTimeout);
4721 }
4722
Mike Lockwood28569302010-01-28 11:54:40 -05004723 private void updateLockScreenTimeout() {
4724 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004725 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08004726 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05004727 if (mLockScreenTimerActive != enable) {
4728 if (enable) {
4729 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
4730 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4731 } else {
4732 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
4733 mHandler.removeCallbacks(mScreenLockTimeout);
4734 }
4735 mLockScreenTimerActive = enable;
4736 }
4737 }
4738 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004739
4740 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004741 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004742 public void enableScreenAfterBoot() {
4743 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07004744 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004745 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004746 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07004747
Jeff Brownc458ce92012-04-30 14:58:40 -07004748 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07004749 if (mLidState == LID_CLOSED && mLidControlsSleep) {
4750 mPowerManager.goToSleep(SystemClock.uptimeMillis());
4751 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004752 }
4753
4754 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004755 try {
4756 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004757 mWindowManager.updateRotation(alwaysSendConfiguration, false);
4758 } catch (RemoteException e) {
4759 // Ignore
4760 }
4761 }
4762
4763 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
4764 try {
4765 //set orientation on WindowManager
4766 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004767 } catch (RemoteException e) {
4768 // Ignore
4769 }
4770 }
4771
Daniel Sandler6396c722013-04-16 20:19:09 -04004772 /**
4773 * Return an Intent to launch the currently active dock app as home. Returns
4774 * null if the standard home should be launched, which is the case if any of the following is
4775 * true:
4776 * <ul>
4777 * <li>The device is not in either car mode or desk mode
4778 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
4779 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
4780 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
4781 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
4782 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07004783 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04004784 */
4785 Intent createHomeDockIntent() {
4786 Intent intent = null;
4787
4788 // What home does is based on the mode, not the dock state. That
4789 // is, when in car mode you should be taken to car home regardless
4790 // of whether we are actually in a car dock.
4791 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
4792 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
4793 intent = mCarDockIntent;
4794 }
4795 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
4796 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
4797 intent = mDeskDockIntent;
4798 }
4799 }
4800
4801 if (intent == null) {
4802 return null;
4803 }
4804
4805 ActivityInfo ai = null;
4806 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
4807 intent,
4808 PackageManager.MATCH_DEFAULT_ONLY,
4809 UserHandle.USER_CURRENT);
4810 if (info != null) {
4811 ai = info.activityInfo;
4812 }
4813 if (ai != null
4814 && ai.metaData != null
4815 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
4816 intent = new Intent(intent);
4817 intent.setClassName(ai.packageName, ai.name);
4818 return intent;
4819 }
4820
4821 return null;
4822 }
4823
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004824 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04004825 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04004826
4827 Intent dock = createHomeDockIntent();
4828 if (dock != null) {
4829 try {
4830 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
4831 return;
4832 } catch (ActivityNotFoundException e) {
4833 }
4834 }
4835
Dianne Hackbornd8883992012-09-07 15:58:52 -07004836 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004837 }
Craig Mautnereda67292013-04-28 13:50:14 -07004838
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004839 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004840 * goes to the home screen
4841 * @return whether it did anything
4842 */
4843 boolean goHome() {
4844 if (false) {
4845 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07004846 try {
4847 ActivityManagerNative.getDefault().stopAppSwitches();
4848 } catch (RemoteException e) {
4849 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004850 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004851 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004852 } else {
4853 // This code brings home to the front or, if it is already
4854 // at the front, puts the device to sleep.
4855 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08004856 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
4857 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
4858 Log.d(TAG, "UTS-TEST-MODE");
4859 } else {
4860 ActivityManagerNative.getDefault().stopAppSwitches();
4861 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04004862 Intent dock = createHomeDockIntent();
4863 if (dock != null) {
4864 int result = ActivityManagerNative.getDefault()
4865 .startActivityAsUser(null, null, dock,
4866 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
4867 null, null, 0,
4868 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
4869 null, null, null, UserHandle.USER_CURRENT);
4870 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
4871 return false;
4872 }
4873 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004874 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004875 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004876 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004877 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07004878 null, null, 0,
4879 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004880 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07004881 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004882 return false;
4883 }
4884 } catch (RemoteException ex) {
4885 // bummer, the activity manager, which is in this process, is dead
4886 }
4887 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004888 return true;
4889 }
Craig Mautnereda67292013-04-28 13:50:14 -07004890
4891 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07004892 public void setCurrentOrientationLw(int newOrientation) {
4893 synchronized (mLock) {
4894 if (newOrientation != mCurrentAppOrientation) {
4895 mCurrentAppOrientation = newOrientation;
4896 updateOrientationListenerLp();
4897 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004898 }
4899 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004900
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07004901 private void performAuditoryFeedbackForAccessibilityIfNeed() {
4902 if (!isGlobalAccessibilityGestureEnabled()) {
4903 return;
4904 }
4905 AudioManager audioManager = (AudioManager) mContext.getSystemService(
4906 Context.AUDIO_SERVICE);
4907 if (audioManager.isSilentMode()) {
4908 return;
4909 }
4910 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
4911 Settings.System.DEFAULT_NOTIFICATION_URI);
4912 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
4913 ringTone.play();
4914 }
Craig Mautnereda67292013-04-28 13:50:14 -07004915
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07004916 private boolean isGlobalAccessibilityGestureEnabled() {
4917 return Settings.Global.getInt(mContext.getContentResolver(),
4918 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
4919 }
4920
Craig Mautnereda67292013-04-28 13:50:14 -07004921 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07004922 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07004923 if (!mVibrator.hasVibrator()) {
4924 return false;
4925 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004926 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
4927 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jim Miller5ecd8112013-01-09 18:50:26 -08004928 if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotHidden())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004929 return false;
4930 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004931 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004932 switch (effectId) {
4933 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004934 pattern = mLongPressVibePattern;
4935 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004936 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004937 pattern = mVirtualKeyVibePattern;
4938 break;
4939 case HapticFeedbackConstants.KEYBOARD_TAP:
4940 pattern = mKeyboardTapVibePattern;
4941 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004942 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004943 pattern = mSafeModeDisabledVibePattern;
4944 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004945 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004946 pattern = mSafeModeEnabledVibePattern;
4947 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08004948 default:
4949 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004950 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004951 int owningUid;
4952 String owningPackage;
4953 if (win != null) {
4954 owningUid = win.getOwningUid();
4955 owningPackage = win.getOwningPackage();
4956 } else {
4957 owningUid = android.os.Process.myUid();
4958 owningPackage = mContext.getBasePackageName();
4959 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004960 if (pattern.length == 1) {
4961 // One-shot vibration
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004962 mVibrator.vibrate(owningUid, owningPackage, pattern[0]);
Amith Yamasanic33cb712010-02-10 15:21:49 -08004963 } else {
4964 // Pattern vibration
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004965 mVibrator.vibrate(owningUid, owningPackage, pattern, -1);
Amith Yamasanic33cb712010-02-10 15:21:49 -08004966 }
4967 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004968 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004969
4970 @Override
4971 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04004972 }
4973
Jeff Brownc38c9be2012-10-04 13:16:19 -07004974 @Override
4975 public void keepScreenOnStoppedLw() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004976 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotHidden()) {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004977 long curTime = SystemClock.uptimeMillis();
Jim Miller25190572013-02-28 17:36:24 -08004978 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004979 }
4980 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04004981
Dianne Hackborndf89e652011-10-06 22:35:11 -07004982 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08004983 // If there is no window focused, there will be nobody to handle the events
4984 // anyway, so just hang on in whatever state we're in until things settle down.
Dianne Hackborndf89e652011-10-06 22:35:11 -07004985 if (mFocusedWindow == null) {
4986 return 0;
4987 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004988 if (mFocusedWindow.getAttrs().type == TYPE_KEYGUARD && mHideLockScreen == true) {
4989 // We are updating at a point where the keyguard has gotten
4990 // focus, but we were last in a state where the top window is
4991 // hiding it. This is probably because the keyguard as been
4992 // shown while the top window was displayed, so we want to ignore
4993 // it here because this is just a very transient change and it
4994 // will quickly lose focus once it correctly gets hidden.
4995 return 0;
4996 }
John Spurlock32beb2c2013-03-11 10:16:47 -04004997
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004998 int tmpVisibility = mFocusedWindow.getSystemUiVisibility()
Dianne Hackborne26ab702011-10-16 13:21:33 -07004999 & ~mResettingSystemUiFlags
5000 & ~mForceClearedSystemUiFlags;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005001 if (mForcingShowNavBar && mFocusedWindow.getSurfaceLayer() < mForcingShowNavBarLayer) {
5002 tmpVisibility &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
5003 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005004 final int visibility = updateHideybarsLw(tmpVisibility);
5005 final int diff = visibility ^ mLastSystemUiFlags;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08005006 final boolean needsMenu = mFocusedWindow.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005007 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
5008 && mFocusedApp == mFocusedWindow.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005009 return 0;
5010 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005011 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005012 mLastFocusNeedsMenu = needsMenu;
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005013 mFocusedApp = mFocusedWindow.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005014 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005015 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005016 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005017 try {
5018 IStatusBarService statusbar = getStatusBarService();
5019 if (statusbar != null) {
5020 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5021 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005022 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005023 } catch (RemoteException e) {
5024 // re-acquire status bar service next time it is needed.
5025 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005026 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005027 }
5028 });
5029 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005030 }
5031
John Spurlockad3e6cb2013-04-30 08:47:43 -04005032 private int updateHideybarsLw(int tmpVisibility) {
John Spurlock245fd012013-05-31 10:31:04 -04005033 if (OverlayTesting.enabled) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005034 tmpVisibility = OverlayTesting.applyForced(mFocusedWindow, tmpVisibility);
5035 }
5036 boolean statusBarHasFocus =
5037 mFocusedWindow.getAttrs().type == TYPE_STATUS_BAR;
5038 if (statusBarHasFocus) {
5039 // prevent status bar interaction from clearing certain flags
5040 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5041 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
5042 | View.SYSTEM_UI_FLAG_ALLOW_OVERLAY;
5043 tmpVisibility = (tmpVisibility & ~flags) | (mLastSystemUiFlags & flags);
5044 }
5045 boolean overlayAllowed = (tmpVisibility & View.SYSTEM_UI_FLAG_ALLOW_OVERLAY) != 0;
5046 if (mStatusHideybar == HIDEYBAR_SHOWING) {
5047 // status hideybar requested
5048 boolean hideStatusBarWM =
5049 (mFocusedWindow.getAttrs().flags
5050 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5051 boolean hideStatusBarSysui =
5052 (tmpVisibility & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
5053
5054 boolean statusHideyAllowed =
5055 hideStatusBarWM
5056 || (hideStatusBarSysui && overlayAllowed)
5057 || statusBarHasFocus;
5058
John Spurlock04db1762013-05-13 12:46:41 -04005059 if (mStatusBar == null || !statusHideyAllowed) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005060 mStatusHideybar = HIDEYBAR_NONE;
John Spurlock04db1762013-05-13 12:46:41 -04005061 if (mStatusBar != null && hideStatusBarSysui) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005062 // clear the clearable flags instead
5063 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5064 if (newVal != mResettingSystemUiFlags) {
5065 mResettingSystemUiFlags = newVal;
5066 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5067 }
5068 }
5069 } else {
5070 // show status hideybar
5071 tmpVisibility |= View.STATUS_BAR_OVERLAY;
5072 if ((mLastSystemUiFlags & View.STATUS_BAR_OVERLAY) == 0) {
John Spurlockd85618e2013-05-28 14:58:50 -04005073 tmpVisibility &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005074 mStatusBar.showLw(true);
5075 }
5076 }
5077 }
5078 if (mNavigationHideybar == HIDEYBAR_SHOWING) {
5079 // navigation hideybar requested
5080 boolean hideNavigationBarSysui =
5081 (tmpVisibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
5082 boolean navigationHideyAllowed =
John Spurlocke3b642e2013-05-09 15:51:32 -04005083 hideNavigationBarSysui && overlayAllowed && mNavigationBar != null;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005084 if (!navigationHideyAllowed) {
5085 mNavigationHideybar = HIDEYBAR_NONE;
5086 } else {
5087 // show navigation hideybar
5088 tmpVisibility |= View.NAVIGATION_BAR_OVERLAY;
5089 if ((mLastSystemUiFlags & View.NAVIGATION_BAR_OVERLAY) == 0) {
John Spurlockd85618e2013-05-28 14:58:50 -04005090 tmpVisibility &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005091 mNavigationBar.showLw(true);
5092 }
5093 }
5094 }
5095 return tmpVisibility;
5096 }
5097
5098 // TODO temporary helper that allows testing overlay bars on existing apps
5099 private static final class OverlayTesting {
John Spurlock245fd012013-05-31 10:31:04 -04005100 static String ENABLED_SETTING = "overlay_testing_enabled";
5101 static boolean enabled = false;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005102 private static final HashSet<String> sForced = new HashSet<String>();
5103
5104 private static String parseActivity(WindowState win) {
5105 if (win != null && win.getAppToken() != null) {
5106 String str = win.getAppToken().toString();
5107 int end = str.lastIndexOf(' ');
5108 if (end > 0) {
5109 int start = str.lastIndexOf(' ', end - 1);
5110 if (start > -1) {
5111 return str.substring(start + 1, end);
5112 }
5113 }
5114 }
5115 return null;
5116 }
5117
5118 public static int applyForced(WindowState focused, int vis) {
5119 if (sForced.contains(parseActivity(focused))) {
5120 vis |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
5121 View.SYSTEM_UI_FLAG_FULLSCREEN |
5122 View.SYSTEM_UI_FLAG_ALLOW_OVERLAY;
5123 }
5124 return vis;
5125 }
5126
5127 public static void toggleForceOverlay(WindowState focused, Context context) {
5128 String activity = parseActivity(focused);
5129 if (activity != null) {
5130 String action;
5131 if (sForced.contains(activity)) {
5132 sForced.remove(activity);
5133 action = "Force overlay disabled";
5134 } else {
5135 sForced.add(activity);
5136 action = "Force overlay enabled";
5137 }
5138 android.widget.Toast.makeText(context,
5139 action + " for " + activity, android.widget.Toast.LENGTH_SHORT).show();
5140 }
5141 }
5142 }
5143
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005144 // Use this instead of checking config_showNavigationBar so that it can be consistently
5145 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005146 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005147 public boolean hasNavigationBar() {
5148 return mHasNavigationBar;
5149 }
5150
satok1bc0a492012-04-25 22:47:12 +09005151 @Override
5152 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5153 mLastInputMethodWindow = ime;
5154 mLastInputMethodTargetWindow = target;
5155 }
5156
Craig Mautnerf1b67412012-09-19 13:18:29 -07005157 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005158 public void setCurrentUserLw(int newUserId) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005159 if (mKeyguardDelegate != null) {
5160 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005161 }
John Spurlock13451a22012-09-28 14:40:41 -04005162 if (mStatusBarService != null) {
5163 try {
5164 mStatusBarService.setCurrentUser(newUserId);
5165 } catch (RemoteException e) {
5166 // oh well
5167 }
5168 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005169 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005170 }
5171
5172 @Override
Jim Miller4eeb4f62012-11-08 00:04:29 -08005173 public void showAssistant() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005174 mKeyguardDelegate.showAssistant();
Jim Miller4eeb4f62012-11-08 00:04:29 -08005175 }
5176
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005177 @Override
5178 public boolean canMagnifyWindow(int windowType) {
5179 switch (windowType) {
5180 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5181 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5182 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5183 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5184 return false;
5185 }
5186 }
5187 return true;
5188 }
5189
5190 @Override
5191 public boolean isTopLevelWindow(int windowType) {
5192 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5193 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5194 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5195 }
5196 return true;
5197 }
5198
Jim Miller4eeb4f62012-11-08 00:04:29 -08005199 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005200 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005201 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005202 pw.print(" mSystemReady="); pw.print(mSystemReady);
5203 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005204 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005205 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5206 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005207 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5208 || mForceClearedSystemUiFlags != 0) {
5209 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5210 pw.print(Integer.toHexString(mLastSystemUiFlags));
5211 pw.print(" mResettingSystemUiFlags=0x");
5212 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5213 pw.print(" mForceClearedSystemUiFlags=0x");
5214 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005215 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005216 if (mLastFocusNeedsMenu) {
5217 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5218 pw.println(mLastFocusNeedsMenu);
5219 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005220 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5221 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005222 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5223 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5224 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5225 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005226 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005227 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005228 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5229 pw.print(mCarDockEnablesAccelerometer);
5230 pw.print(" mDeskDockEnablesAccelerometer=");
5231 pw.println(mDeskDockEnablesAccelerometer);
5232 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5233 pw.print(mLidKeyboardAccessibility);
5234 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005235 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
5236 pw.print(prefix); pw.print("mLongPressOnPowerBehavior=");
5237 pw.print(mLongPressOnPowerBehavior);
5238 pw.print(" mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005239 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5240 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005241 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005242 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5243 pw.print(","); pw.print(mOverscanScreenTop);
5244 pw.print(") "); pw.print(mOverscanScreenWidth);
5245 pw.print("x"); pw.println(mOverscanScreenHeight);
5246 if (mOverscanLeft != 0 || mOverscanTop != 0
5247 || mOverscanRight != 0 || mOverscanBottom != 0) {
5248 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5249 pw.print(" top="); pw.print(mOverscanTop);
5250 pw.print(" right="); pw.print(mOverscanRight);
5251 pw.print(" bottom="); pw.println(mOverscanBottom);
5252 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005253 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5254 pw.print(mRestrictedOverscanScreenLeft);
5255 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5256 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5257 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005258 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5259 pw.print(","); pw.print(mUnrestrictedScreenTop);
5260 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5261 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5262 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5263 pw.print(","); pw.print(mRestrictedScreenTop);
5264 pw.print(") "); pw.print(mRestrictedScreenWidth);
5265 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005266 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5267 pw.print(","); pw.print(mStableFullscreenTop);
5268 pw.print(")-("); pw.print(mStableFullscreenRight);
5269 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005270 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5271 pw.print(","); pw.print(mStableTop);
5272 pw.print(")-("); pw.print(mStableRight);
5273 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005274 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5275 pw.print(","); pw.print(mSystemTop);
5276 pw.print(")-("); pw.print(mSystemRight);
5277 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005278 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5279 pw.print(","); pw.print(mCurTop);
5280 pw.print(")-("); pw.print(mCurRight);
5281 pw.print(","); pw.print(mCurBottom); pw.println(")");
5282 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5283 pw.print(","); pw.print(mContentTop);
5284 pw.print(")-("); pw.print(mContentRight);
5285 pw.print(","); pw.print(mContentBottom); pw.println(")");
5286 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5287 pw.print(","); pw.print(mDockTop);
5288 pw.print(")-("); pw.print(mDockRight);
5289 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005290 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5291 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005292 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5293 pw.print(" mShowingDream="); pw.print(mShowingDream);
5294 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005295 if (mLastInputMethodWindow != null) {
5296 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5297 pw.println(mLastInputMethodWindow);
5298 }
5299 if (mLastInputMethodTargetWindow != null) {
5300 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5301 pw.println(mLastInputMethodTargetWindow);
5302 }
5303 if (mStatusBar != null) {
5304 pw.print(prefix); pw.print("mStatusBar=");
5305 pw.println(mStatusBar);
5306 }
5307 if (mNavigationBar != null) {
5308 pw.print(prefix); pw.print("mNavigationBar=");
5309 pw.println(mNavigationBar);
5310 }
5311 if (mKeyguard != null) {
5312 pw.print(prefix); pw.print("mKeyguard=");
5313 pw.println(mKeyguard);
5314 }
5315 if (mFocusedWindow != null) {
5316 pw.print(prefix); pw.print("mFocusedWindow=");
5317 pw.println(mFocusedWindow);
5318 }
5319 if (mFocusedApp != null) {
5320 pw.print(prefix); pw.print("mFocusedApp=");
5321 pw.println(mFocusedApp);
5322 }
5323 if (mWinDismissingKeyguard != null) {
5324 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5325 pw.println(mWinDismissingKeyguard);
5326 }
5327 if (mTopFullscreenOpaqueWindowState != null) {
5328 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5329 pw.println(mTopFullscreenOpaqueWindowState);
5330 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005331 if (mForcingShowNavBar) {
5332 pw.print(prefix); pw.print("mForcingShowNavBar=");
5333 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5334 pw.println(mForcingShowNavBarLayer);
5335 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005336 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005337 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005338 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5339 pw.print(" mForceStatusBarFromKeyguard=");
5340 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005341 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005342 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005343 pw.print(" mHomePressed="); pw.println(mHomePressed);
5344 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5345 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5346 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5347 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5348 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5349 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5350 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5351 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5352 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5353 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005354 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5355 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5356 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005357 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005358}