blob: 248112f26360731af5d26caa4e95fd6f45d700d3 [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;
John Spurlock97642182013-07-29 17:58:39 -040024import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080025import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070026import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080027import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040028import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080029import android.content.ContentResolver;
30import android.content.Context;
31import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070032import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070033import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080034import android.content.pm.ActivityInfo;
35import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040036import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070037import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080038import android.content.res.Configuration;
39import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070040import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080042import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080043import android.graphics.Rect;
Michael Jurka7a348952012-02-27 13:07:58 -080044import android.media.AudioManager;
45import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070046import android.media.Ringtone;
47import android.media.RingtoneManager;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070048import android.os.Bundle;
Jeff Brown9a538ee2012-08-20 14:56:57 -070049import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080050import android.os.Handler;
51import android.os.IBinder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070052import android.os.IRemoteCallback;
Jeff Brown32cbc38552011-12-01 14:01:49 -080053import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070054import android.os.Message;
55import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080056import android.os.PowerManager;
57import android.os.RemoteException;
58import android.os.ServiceManager;
59import android.os.SystemClock;
60import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080061import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070062import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080063import android.os.Vibrator;
64import android.provider.Settings;
John Spurlockc8b46ca2013-04-08 12:59:26 -040065import android.service.dreams.DreamService;
66import android.service.dreams.IDreamManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070067import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080068import android.util.EventLog;
69import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070070import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080071import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070072import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080073import android.view.Gravity;
74import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080075import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080076import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070077import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070078import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080079import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080080import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080081import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080082import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080083import android.view.KeyEvent;
84import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080085import android.view.Surface;
86import android.view.View;
87import android.view.ViewConfiguration;
88import android.view.Window;
89import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080090import android.view.WindowManagerGlobal;
91import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -080092import android.view.accessibility.AccessibilityEvent;
93import android.view.animation.Animation;
94import android.view.animation.AnimationUtils;
95
96import com.android.internal.R;
97import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -080098import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautnerae446592012-12-06 19:05:05 -080099import com.android.internal.statusbar.IStatusBarService;
100import com.android.internal.telephony.ITelephony;
101import com.android.internal.widget.PointerLocationView;
102
103import java.io.File;
104import java.io.FileReader;
105import java.io.IOException;
106import java.io.PrintWriter;
107
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 =
John Spurlocke1f366f2013-08-05 12:22:40 -0400165 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
166 | View.SYSTEM_UI_FLAG_FULLSCREEN
167 | View.SYSTEM_UI_FLAG_TRANSPARENT_STATUS
168 | View.SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700169
Jim Miller5ecd8112013-01-09 18:50:26 -0800170 /**
171 * Keyguard stuff
172 */
173 private WindowState mKeyguardScrim;
174
Jeff Brown6651a632011-11-28 12:59:11 -0800175 /* Table of Application Launch keys. Maps from key codes to intent categories.
176 *
177 * These are special keys that are used to launch particular kinds of applications,
178 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
179 * usage page. We don't support quite that many yet...
180 */
181 static SparseArray<String> sApplicationLaunchKeyCategories;
182 static {
183 sApplicationLaunchKeyCategories = new SparseArray<String>();
184 sApplicationLaunchKeyCategories.append(
185 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
186 sApplicationLaunchKeyCategories.append(
187 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
188 sApplicationLaunchKeyCategories.append(
189 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
190 sApplicationLaunchKeyCategories.append(
191 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
192 sApplicationLaunchKeyCategories.append(
193 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
194 sApplicationLaunchKeyCategories.append(
195 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
196 }
197
Dianne Hackborndf89e652011-10-06 22:35:11 -0700198 /**
199 * Lock protecting internal state. Must not call out into window
200 * manager with lock held. (This lock will be acquired in places
201 * where the window manager is calling in with its own lock held.)
202 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800203 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700204
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800205 Context mContext;
206 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700207 WindowManagerFuncs mWindowManagerFuncs;
Jeff Brown96307042012-07-27 15:51:34 -0700208 PowerManager mPowerManager;
Joe Onorato93056472010-09-10 10:30:46 -0400209 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700210 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700211 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800212 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700213 SearchManager mSearchManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800214
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700215 // Vibrator pattern for haptic feedback of a long press.
216 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700217
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700218 // Vibrator pattern for haptic feedback of virtual key press.
219 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700220
Amith Yamasanic33cb712010-02-10 15:21:49 -0800221 // Vibrator pattern for a short vibration.
222 long[] mKeyboardTapVibePattern;
223
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700224 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
225 long[] mClockTickVibePattern;
226
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700227 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
228 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700229
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700230 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
231 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700232
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800233 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
234 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400235
236 boolean mHeadless;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800237 boolean mSafeMode;
238 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700239 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400240 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400241 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700242 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400243 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
244 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
245 int[] mNavigationBarHeightForRotation = new int[4];
246 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400247
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800248 WindowState mKeyguard = null;
Jim Miller5ecd8112013-01-09 18:50:26 -0800249 KeyguardServiceDelegate mKeyguardDelegate;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800250 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700251 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
252 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800253 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900254 WindowState mLastInputMethodWindow = null;
255 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800256
Jeff Brown68b909d2011-12-07 16:36:01 -0800257 static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0;
258 static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1;
Jeff Brown602ab322012-05-16 13:33:47 -0700259 static final int RECENT_APPS_BEHAVIOR_DISMISS = 2;
260 static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 3;
Jeff Brown68b909d2011-12-07 16:36:01 -0800261
262 RecentApplicationsDialog mRecentAppsDialog;
263 int mRecentAppsDialogHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700264 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800265
Jeff Brown2e7760e2012-04-11 15:14:55 -0700266 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700267 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800268
Dianne Hackbornc777e072010-02-12 13:07:59 -0800269 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700270 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800271 boolean mHdmiPlugged;
Daniel Sandler6396c722013-04-16 20:19:09 -0400272 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700273 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700274 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400275 int mCarDockRotation;
276 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700277 int mUndockedHdmiRotation;
278 int mDemoHdmiRotation;
279 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400280
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700281 // Default display does not rotate, apps that require non-default orientation will have to
282 // have the orientation emulated.
283 private boolean mForceDefaultOrientation = false;
284
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400285 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
286 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700287 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400288
Jeff Brownd3187e32011-09-21 19:26:44 -0700289 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400290 boolean mCarDockEnablesAccelerometer;
291 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700292 int mLidKeyboardAccessibility;
293 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700294 boolean mLidControlsSleep;
Joe Onoratod208e702010-10-08 16:22:43 -0400295 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700296 boolean mScreenOnEarly = false;
297 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800298 boolean mOrientationSensorEnabled = false;
299 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800300 boolean mHasSoftInput = false;
Craig Mautner967212c2013-04-13 21:10:58 -0700301
Jeff Brown70825162012-03-28 17:27:48 -0700302 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800303
304 // The last window we were told about in focusChanged.
305 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800306 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800307
Craig Mautner037aa8d2013-06-07 10:35:44 -0700308 private final class PointerLocationPointerEventListener implements PointerEventListener {
Jeff Browna41ca772010-08-11 14:46:32 -0700309 @Override
Craig Mautner037aa8d2013-06-07 10:35:44 -0700310 public void onPointerEvent(MotionEvent motionEvent) {
311 if (mPointerLocationView != null) {
312 mPointerLocationView.addPointerEvent(motionEvent);
Jeff Browna41ca772010-08-11 14:46:32 -0700313 }
314 }
Jeff Brown32cbc38552011-12-01 14:01:49 -0800315 }
Jeff Brown70825162012-03-28 17:27:48 -0700316
317 // Pointer location view state, only modified on the mHandler Looper.
Craig Mautner037aa8d2013-06-07 10:35:44 -0700318 PointerLocationPointerEventListener mPointerLocationPointerEventListener;
Jeff Brown70825162012-03-28 17:27:48 -0700319 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800320
Dianne Hackbornc652de82013-02-15 16:32:56 -0800321 // The current size of the screen; really; extends into the overscan area of
322 // the screen and doesn't account for any system elements like the status bar.
323 int mOverscanScreenLeft, mOverscanScreenTop;
324 int mOverscanScreenWidth, mOverscanScreenHeight;
325 // The current visible size of the screen; really; (ir)regardless of whether the status
326 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800327 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
328 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800329 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
330 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
331 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700332 // The current size of the screen; these may be different than (0,0)-(dw,dh)
333 // if the status bar can't be hidden; in that case it effectively carves out
334 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800335 int mRestrictedScreenLeft, mRestrictedScreenTop;
336 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700337 // During layout, the current screen borders accounting for any currently
338 // visible system UI elements.
339 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700340 // For applications requesting stable content insets, these are them.
341 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700342 // For applications requesting stable content insets but have also set the
343 // fullscreen window flag, these are the stable dimensions without the status bar.
344 int mStableFullscreenLeft, mStableFullscreenTop;
345 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800346 // During layout, the current screen borders with all outer decoration
347 // (status bar, input method dock) accounted for.
348 int mCurLeft, mCurTop, mCurRight, mCurBottom;
349 // During layout, the frame in which content should be displayed
350 // to the user, accounting for all screen decoration except for any
351 // space they deem as available for other content. This is usually
352 // the same as mCur*, but may be larger if the screen decor has supplied
353 // content insets.
354 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800355 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800356 // windows are placed.
357 int mDockLeft, mDockTop, mDockRight, mDockBottom;
358 // During layout, the layer at which the doc window is placed.
359 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700360 // During layout, this is the layer of the status bar.
361 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700362 int mLastSystemUiFlags;
363 // Bits that we are in the process of clearing, so we want to prevent
364 // them from being set by applications until everything has been updated
365 // to have them clear.
366 int mResettingSystemUiFlags = 0;
367 // Bits that we are currently always keeping cleared.
368 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800369 // What we last reported to system UI about whether the compatibility
370 // menu needs to be displayed.
371 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700372
373 FakeWindow mHideNavFakeWindow = null;
374
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800375 static final Rect mTmpParentFrame = new Rect();
376 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800377 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800378 static final Rect mTmpContentFrame = new Rect();
379 static final Rect mTmpVisibleFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700380 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700381
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800382 WindowState mTopFullscreenOpaqueWindowState;
Joe Onorato93056472010-09-10 10:30:46 -0400383 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800384 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700385 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700386 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800387 boolean mForcingShowNavBar;
388 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700389
390 // States of keyguard dismiss.
391 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
392 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
393 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
394 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
395
396 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
397 * be done once per window. */
398 private WindowState mWinDismissingKeyguard;
399
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700400 boolean mShowingLockscreen;
401 boolean mShowingDream;
402 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800403 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700404 boolean mHomeConsumed;
405 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800406 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700407 Intent mCarDockIntent;
408 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700409 boolean mSearchKeyShortcutPending;
410 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700411 boolean mAssistKeyLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800412
Mike Lockwood28569302010-01-28 11:54:40 -0500413 // support for activating the lock screen while the screen is on
414 boolean mAllowLockscreenWhenOn;
415 int mLockScreenTimeout;
416 boolean mLockScreenTimerActive;
417
David Brownbaf8d092010-03-08 21:52:59 -0800418 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800419 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800420
421 // Behavior of POWER button while in-call and screen on.
422 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
423 int mIncallPowerBehavior;
424
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700425 Display mDisplay;
426
Dianne Hackborn9d132642011-04-21 17:26:39 -0700427 int mLandscapeRotation = 0; // default landscape rotation
428 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
429 int mPortraitRotation = 0; // default portrait rotation
430 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700431
Dianne Hackbornc652de82013-02-15 16:32:56 -0800432 int mOverscanLeft = 0;
433 int mOverscanTop = 0;
434 int mOverscanRight = 0;
435 int mOverscanBottom = 0;
436
Joe Onorato46b0d682010-11-22 17:37:27 -0800437 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700438 private int mLongPressOnHomeBehavior;
439
440 // What we do when the user double-taps on home
441 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800442
Winson Chung9112ec32011-06-27 13:15:32 -0700443 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700444 // Time to volume and power must be pressed within this interval of each other.
445 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700446 // Increase the chord delay when taking a screenshot from the keyguard
447 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800448 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700449 private boolean mVolumeDownKeyTriggered;
450 private long mVolumeDownKeyTime;
451 private boolean mVolumeDownKeyConsumedByScreenshotChord;
452 private boolean mVolumeUpKeyTriggered;
453 private boolean mPowerKeyTriggered;
454 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700455
Michael Wrightb854e242013-02-05 17:54:02 -0800456 /* The number of steps between min and max brightness */
457 private static final int BRIGHTNESS_STEPS = 10;
458
Christopher Tate5e08af02012-09-21 17:17:22 -0700459 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800460 ShortcutManager mShortcutManager;
461 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700462 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800463
Craig Mautnerd625ab22013-09-06 13:40:31 -0700464 private int mCurrentUserId;
465
Justin Kohd378ad72013-04-01 12:18:26 -0700466 // Maps global key codes to the components that will handle them.
467 private GlobalKeyManager mGlobalKeyManager;
468
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700469 // Fallback actions by key code.
470 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
471 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800472
Jeff Brown70825162012-03-28 17:27:48 -0700473 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
474 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700475 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
476 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Jeff Brown70825162012-03-28 17:27:48 -0700477
478 private class PolicyHandler extends Handler {
479 @Override
480 public void handleMessage(Message msg) {
481 switch (msg.what) {
482 case MSG_ENABLE_POINTER_LOCATION:
483 enablePointerLocation();
484 break;
485 case MSG_DISABLE_POINTER_LOCATION:
486 disablePointerLocation();
487 break;
Jeff Brown40013652012-05-16 21:22:36 -0700488 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
489 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
490 break;
491 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
492 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
493 break;
Jeff Brown70825162012-03-28 17:27:48 -0700494 }
495 }
496 }
497
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800498 private UEventObserver mHDMIObserver = new UEventObserver() {
499 @Override
500 public void onUEvent(UEventObserver.UEvent event) {
501 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
502 }
503 };
504
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800505 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800506 SettingsObserver(Handler handler) {
507 super(handler);
508 }
David Brownbaf8d092010-03-08 21:52:59 -0800509
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800510 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700511 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800512 ContentResolver resolver = mContext.getContentResolver();
513 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700514 Settings.System.END_BUTTON_BEHAVIOR), false, this,
515 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800516 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700517 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
518 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800519 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700520 Settings.System.ACCELEROMETER_ROTATION), false, this,
521 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500522 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700523 Settings.System.USER_ROTATION), false, this,
524 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400525 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700526 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
527 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800528 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700529 Settings.System.POINTER_LOCATION), false, this,
530 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800531 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700532 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
533 UserHandle.USER_ALL);
Dianne Hackborn03759ed2009-03-27 16:04:08 -0700534 resolver.registerContentObserver(Settings.System.getUriFor(
John Spurlockd67ec252013-09-05 11:31:54 -0400535 Settings.Secure.TRANSIENT_NAV_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700536 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800537 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800538 }
539
540 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800541 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700542 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800543 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800544 }
Craig Mautner967212c2013-04-13 21:10:58 -0700545
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800546 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800547 MyOrientationListener(Context context, Handler handler) {
548 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800549 }
Craig Mautner967212c2013-04-13 21:10:58 -0700550
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800551 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700552 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700553 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700554 updateRotation(false);
555 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800556 }
557 MyOrientationListener mOrientationListener;
558
John Spurlock27735a42013-08-14 17:57:38 -0400559 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400560 View.STATUS_BAR_TRANSIENT,
561 View.STATUS_BAR_UNHIDE,
John Spurlockb77edbf2013-08-21 21:04:12 -0400562 View.SYSTEM_UI_FLAG_TRANSPARENT_STATUS,
John Spurlock5b9145b2013-08-20 15:13:47 -0400563 StatusBarManager.WINDOW_STATUS_BAR);
564
John Spurlock27735a42013-08-14 17:57:38 -0400565 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400566 View.NAVIGATION_BAR_TRANSIENT,
567 View.NAVIGATION_BAR_UNHIDE,
John Spurlockb77edbf2013-08-21 21:04:12 -0400568 View.SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION,
John Spurlock5b9145b2013-08-20 15:13:47 -0400569 StatusBarManager.WINDOW_NAVIGATION_BAR);
570
John Spurlock34e13d92013-08-10 06:52:28 -0400571 private TransientNavigationConfirmation mTransientNavigationConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400572
Craig Mautner037aa8d2013-06-07 10:35:44 -0700573 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400574
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700575 IStatusBarService getStatusBarService() {
576 synchronized (mServiceAquireLock) {
577 if (mStatusBarService == null) {
578 mStatusBarService = IStatusBarService.Stub.asInterface(
579 ServiceManager.getService("statusbar"));
580 }
581 return mStatusBarService;
582 }
583 }
584
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700585 /*
586 * We always let the sensor be switched on by default except when
587 * the user has explicitly disabled sensor based rotation or when the
588 * screen is switched off.
589 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700590 boolean needSensorRunningLp() {
Dianne Hackborne5439f22010-10-02 16:53:50 -0700591 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
592 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
593 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
594 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800595 // If the application has explicitly requested to follow the
596 // orientation, then we need to turn the sensor or.
597 return true;
598 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700599 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800600 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
601 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
602 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400603 // enable accelerometer if we are docked in a dock that enables accelerometer
604 // orientation management,
605 return true;
606 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700607 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800608 // If the setting for using the sensor by default is enabled, then
609 // we will always leave it on. Note that the user could go to
610 // a window that forces an orientation that does not use the
611 // sensor and in theory we could turn it off... however, when next
612 // turning it on we won't have a good value for the current
613 // orientation for a little bit, which can cause orientation
614 // changes to lag, so we'd like to keep it always on. (It will
615 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700616 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800617 }
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700618 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800619 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700620
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800621 /*
622 * Various use cases for invoking this function
623 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700624 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800625 * if not already enabled
626 * screen turned on and current app does not have sensor orientation, disable listeners if
627 * already enabled
628 * screen turning on and current app has sensor based orientation, enable listeners if needed
629 * screen turning on and current app has nosensor based orientation, do nothing
630 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700631 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800632 if (!mOrientationListener.canDetectOrientation()) {
633 // If sensor is turned off or nonexistent for some reason
634 return;
635 }
636 //Could have been invoked due to screen turning on or off or
637 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700638 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800639 ", current orientation="+mCurrentAppOrientation+
640 ", SensorEnabled="+mOrientationSensorEnabled);
641 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700642 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700643 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800644 disable = false;
645 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700646 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800647 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700648 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800649 mOrientationSensorEnabled = true;
650 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700651 }
652 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800653 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700654 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800655 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700656 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800657 mOrientationSensorEnabled = false;
658 }
659 }
660
Jeff Brown4d396052010-10-29 21:50:21 -0700661 private void interceptPowerKeyDown(boolean handled) {
662 mPowerKeyHandled = handled;
663 if (!handled) {
664 mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
665 }
666 }
667
668 private boolean interceptPowerKeyUp(boolean canceled) {
669 if (!mPowerKeyHandled) {
670 mHandler.removeCallbacks(mPowerLongPress);
671 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700672 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700673 return false;
674 }
675
676 private void cancelPendingPowerKeyAction() {
677 if (!mPowerKeyHandled) {
678 mHandler.removeCallbacks(mPowerLongPress);
679 }
Jeff Brownff204712011-10-25 21:27:54 -0700680 if (mPowerKeyTriggered) {
681 mPendingPowerKeyUpCanceled = true;
682 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700683 }
684
685 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800686 if (mScreenshotChordEnabled
687 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700688 final long now = SystemClock.uptimeMillis();
689 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
690 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
691 mVolumeDownKeyConsumedByScreenshotChord = true;
692 cancelPendingPowerKeyAction();
693
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800694 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700695 }
696 }
697 }
698
Winson Chung1cea2f32012-10-08 20:42:01 -0700699 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800700 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700701 // Double the time it takes to take a screenshot from the keyguard
702 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
703 ViewConfiguration.getGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700704 }
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800705 return ViewConfiguration.getGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700706 }
707
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700708 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800709 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700710 }
711
712 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700713 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800714 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700715 // The context isn't read
716 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700717 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
718 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400719 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700720 int resolvedBehavior = mLongPressOnPowerBehavior;
721 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
722 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
723 }
724
725 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700726 case LONG_PRESS_POWER_NOTHING:
727 break;
728 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
729 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700730 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
731 performAuditoryFeedbackForAccessibilityIfNeed();
732 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700733 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
734 showGlobalActionsDialog();
735 break;
736 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700737 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700738 mPowerKeyHandled = true;
739 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
740 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700741 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700742 break;
743 }
744 }
745 };
746
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800747 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800748 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700749 public void run() {
750 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800751 }
752 };
753
754 void showGlobalActionsDialog() {
755 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700756 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800757 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700758 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800759 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
760 if (keyguardShowing) {
761 // since it took two seconds of long press to bring this up,
762 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800763 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800764 }
765 }
766
767 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700768 return Settings.Global.getInt(
769 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800770 }
771
Patrick Dubroyece94522011-02-23 18:35:01 -0800772 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800773 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700774 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800775 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800776
Jeff Browncaca8812013-05-09 13:34:33 -0700777 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
778 toggleRecentApps();
779 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
780 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700781 }
782 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800783 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800784
Jeff Browncaca8812013-05-09 13:34:33 -0700785 private void handleDoubleTapOnHome() {
786 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
787 mHomeConsumed = true;
788 toggleRecentApps();
789 }
790 }
791
792 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
793 @Override
794 public void run() {
795 if (mHomeDoubleTapPending) {
796 mHomeDoubleTapPending = false;
797 launchHomeFromHotKey();
798 }
799 }
800 };
801
Patrick Dubroyece94522011-02-23 18:35:01 -0800802 /**
Jeff Brown68b909d2011-12-07 16:36:01 -0800803 * Create (if necessary) and show or dismiss the recent apps dialog according
804 * according to the requested behavior.
Patrick Dubroyece94522011-02-23 18:35:01 -0800805 */
Jeff Brown68b909d2011-12-07 16:36:01 -0800806 void showOrHideRecentAppsDialog(final int behavior) {
Jeff Brownda3d5a92011-03-29 15:11:34 -0700807 mHandler.post(new Runnable() {
808 @Override
809 public void run() {
810 if (mRecentAppsDialog == null) {
Jeff Brown54875002011-04-06 15:33:01 -0700811 mRecentAppsDialog = new RecentApplicationsDialog(mContext);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700812 }
Jeff Brown54875002011-04-06 15:33:01 -0700813 if (mRecentAppsDialog.isShowing()) {
Jeff Brown68b909d2011-12-07 16:36:01 -0800814 switch (behavior) {
815 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
Jeff Brown602ab322012-05-16 13:33:47 -0700816 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800817 mRecentAppsDialog.dismiss();
818 break;
819 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
820 mRecentAppsDialog.dismissAndSwitch();
821 break;
822 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
823 default:
824 break;
Jeff Brown54875002011-04-06 15:33:01 -0700825 }
826 } else {
Jeff Brown68b909d2011-12-07 16:36:01 -0800827 switch (behavior) {
828 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
829 mRecentAppsDialog.show();
830 break;
831 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
832 try {
833 mWindowManager.setInTouchMode(false);
834 } catch (RemoteException e) {
835 }
836 mRecentAppsDialog.show();
837 break;
Jeff Brown602ab322012-05-16 13:33:47 -0700838 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800839 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
840 default:
841 break;
842 }
Jeff Brown54875002011-04-06 15:33:01 -0700843 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700844 }
845 });
Patrick Dubroyece94522011-02-23 18:35:01 -0800846 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700847
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800848 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800849 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800850 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700851 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800852 mContext = context;
853 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700854 mWindowManagerFuncs = windowManagerFuncs;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400855 mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
Jeff Brown70825162012-03-28 17:27:48 -0700856 mHandler = new PolicyHandler();
Craig Mautnereee29c42013-01-17 14:44:34 -0800857 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700858 try {
859 mOrientationListener.setCurrentRotation(windowManager.getRotation());
860 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700861 mSettingsObserver = new SettingsObserver(mHandler);
862 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800863 mShortcutManager = new ShortcutManager(context, mHandler);
864 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400865 mUiMode = context.getResources().getInteger(
866 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800867 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
868 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
869 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
870 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700871 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
872 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
873 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
874 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
875 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
876 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
877 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
878 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700879
Jeff Brown96307042012-07-27 15:51:34 -0700880 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
881 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800882 "PhoneWindowManager.mBroadcastWakeLock");
883 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700884 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400885 com.android.internal.R.integer.config_lidOpenRotation);
886 mCarDockRotation = readRotation(
887 com.android.internal.R.integer.config_carDockRotation);
888 mDeskDockRotation = readRotation(
889 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700890 mUndockedHdmiRotation = readRotation(
891 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400892 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
893 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
894 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
895 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700896 mLidKeyboardAccessibility = mContext.getResources().getInteger(
897 com.android.internal.R.integer.config_lidKeyboardAccessibility);
898 mLidNavigationAccessibility = mContext.getResources().getInteger(
899 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -0700900 mLidControlsSleep = mContext.getResources().getBoolean(
901 com.android.internal.R.bool.config_lidControlsSleep);
Jeff Brownf71343d2013-05-31 17:59:11 -0700902 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -0700903
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700904 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800905 IntentFilter filter = new IntentFilter();
906 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
907 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
908 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
909 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700910 filter.addAction(Intent.ACTION_DOCK_EVENT);
911 Intent intent = context.registerReceiver(mDockReceiver, filter);
912 if (intent != null) {
913 // Retrieve current sticky dock event broadcast.
914 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
915 Intent.EXTRA_DOCK_STATE_UNDOCKED);
916 }
Daniel Sandler7e37df52011-11-16 22:08:23 -0800917
Jeff Brown6aaf2952012-10-05 16:01:08 -0700918 // register for dream-related broadcasts
919 filter = new IntentFilter();
920 filter.addAction(Intent.ACTION_DREAMING_STARTED);
921 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
922 context.registerReceiver(mDreamReceiver, filter);
923
Christopher Tate5e08af02012-09-21 17:17:22 -0700924 // register for multiuser-relevant broadcasts
925 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
926 context.registerReceiver(mMultiuserReceiver, filter);
927
John Spurlock57306e62013-04-22 09:48:49 -0400928 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -0700929 mSystemGestures = new SystemGesturesPointerEventListener(context,
930 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -0400931 @Override
932 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -0400933 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400934 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -0400935 }
John Spurlockad3e6cb2013-04-30 08:47:43 -0400936 }
937 @Override
938 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -0400939 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400940 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400941 }
942 }
943 @Override
944 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -0400945 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400946 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400947 }
948 }
949 @Override
950 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -0400951 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -0400952 }
953 });
John Spurlock4cf6a942013-08-13 20:02:46 -0400954 mTransientNavigationConfirmation = new TransientNavigationConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -0700955 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -0400956
Jeff Brownc2346132012-04-13 01:55:38 -0700957 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700958 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
959 com.android.internal.R.array.config_longPressVibePattern);
960 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
961 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -0800962 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
963 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700964 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
965 com.android.internal.R.array.config_clockTickVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700966 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
967 com.android.internal.R.array.config_safeModeDisabledVibePattern);
968 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
969 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -0400970
Christopher Tatee90585f2012-03-05 18:56:25 -0800971 mScreenshotChordEnabled = mContext.getResources().getBoolean(
972 com.android.internal.R.bool.config_enableScreenshotChord);
973
Justin Kohd378ad72013-04-01 12:18:26 -0700974 mGlobalKeyManager = new GlobalKeyManager(mContext);
975
Joe Onoratoea495d42011-04-06 11:41:11 -0700976 // Controls rotation and the like.
977 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -0700978
979 // Match current screen state.
980 if (mPowerManager.isScreenOn()) {
981 screenTurningOn(null);
982 } else {
983 screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
984 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700985 }
986
Jeff Brownf71343d2013-05-31 17:59:11 -0700987 /**
988 * Read values from config.xml that may be overridden depending on
989 * the configuration of the device.
990 * eg. Disable long press on home goes to recents on sw600dp.
991 */
992 private void readConfigurationDependentBehaviors() {
993 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
994 com.android.internal.R.integer.config_longPressOnHomeBehavior);
995 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
996 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
997 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
998 }
999
1000 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1001 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1002 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1003 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1004 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1005 }
1006 }
1007
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001008 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001009 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001010 // This method might be called before the policy has been fully initialized
1011 // or for other displays we don't care about.
1012 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1013 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001014 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001015 mDisplay = display;
1016
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001017 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001018 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001019 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001020 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001021 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001022 mLandscapeRotation = Surface.ROTATION_0;
1023 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001024 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001025 mPortraitRotation = Surface.ROTATION_90;
1026 mUpsideDownRotation = Surface.ROTATION_270;
1027 } else {
1028 mPortraitRotation = Surface.ROTATION_270;
1029 mUpsideDownRotation = Surface.ROTATION_90;
1030 }
1031 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001032 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001033 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001034 mPortraitRotation = Surface.ROTATION_0;
1035 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001036 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001037 mLandscapeRotation = Surface.ROTATION_270;
1038 mSeascapeRotation = Surface.ROTATION_90;
1039 } else {
1040 mLandscapeRotation = Surface.ROTATION_90;
1041 mSeascapeRotation = Surface.ROTATION_270;
1042 }
1043 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001044
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001045 mStatusBarHeight =
1046 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001047
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001048 // Height of the navigation bar when presented horizontally at bottom
1049 mNavigationBarHeightForRotation[mPortraitRotation] =
1050 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001051 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001052 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001053 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1054 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001055
1056 // Width of the navigation bar when presented vertically along one side
1057 mNavigationBarWidthForRotation[mPortraitRotation] =
1058 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1059 mNavigationBarWidthForRotation[mLandscapeRotation] =
1060 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001061 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001062
1063 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001064 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001065 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001066
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001067 // Allow the navigation bar to move on small devices (phones).
1068 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001069
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001070 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001071 // Allow a system property to override this. Used by the emulator.
1072 // See also hasNavigationBar().
1073 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1074 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001075 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001076 } else if ("0".equals(navBarOverride)) {
1077 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001078 }
1079
John Spurlock80f00c12013-06-13 11:10:51 -04001080 if (mHasNavigationBar) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001081 // The navigation bar is at the right in landscape; it seems always
1082 // useful to hide it for showing a video.
1083 mCanHideNavigationBar = true;
1084 } else {
1085 mCanHideNavigationBar = false;
1086 }
Erik Gilling9a41ef82011-09-26 19:21:03 -07001087
Jeff Brown27f1d672012-10-17 18:32:34 -07001088 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1089 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001090 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001091 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001092 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001093 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001094 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001095 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001096
1097 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1098 // http://developer.android.com/guide/practices/screens_support.html#range
1099 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1100 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1101 // For debug purposes the next line turns this feature off with:
1102 // $ adb shell setprop config.override_forced_orient true
1103 // $ adb shell wm size reset
1104 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1105 }
1106
1107 @Override
1108 public boolean isDefaultOrientationForced() {
1109 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001110 }
1111
Dianne Hackbornc652de82013-02-15 16:32:56 -08001112 @Override
1113 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1114 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1115 mOverscanLeft = left;
1116 mOverscanTop = top;
1117 mOverscanRight = right;
1118 mOverscanBottom = bottom;
1119 }
1120 }
1121
Dianne Hackbornc777e072010-02-12 13:07:59 -08001122 public void updateSettings() {
1123 ContentResolver resolver = mContext.getContentResolver();
1124 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001125 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001126 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001127 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001128 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1129 UserHandle.USER_CURRENT);
1130 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001131 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001132 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1133 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001134
Jeff Brown207673cd2012-06-05 17:47:11 -07001135 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001136 int userRotation = Settings.System.getIntForUser(resolver,
1137 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1138 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001139 if (mUserRotation != userRotation) {
1140 mUserRotation = userRotation;
1141 updateRotation = true;
1142 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001143 int userRotationMode = Settings.System.getIntForUser(resolver,
1144 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001145 WindowManagerPolicy.USER_ROTATION_FREE :
1146 WindowManagerPolicy.USER_ROTATION_LOCKED;
1147 if (mUserRotationMode != userRotationMode) {
1148 mUserRotationMode = userRotationMode;
1149 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001150 updateOrientationListenerLp();
1151 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001152
Dianne Hackbornc777e072010-02-12 13:07:59 -08001153 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001154 int pointerLocation = Settings.System.getIntForUser(resolver,
1155 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001156 if (mPointerLocationMode != pointerLocation) {
1157 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001158 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1159 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001160 }
1161 }
1162 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001163 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1164 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1165 String imId = Settings.Secure.getStringForUser(resolver,
1166 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001167 boolean hasSoftInput = imId != null && imId.length() > 0;
1168 if (mHasSoftInput != hasSoftInput) {
1169 mHasSoftInput = hasSoftInput;
1170 updateRotation = true;
1171 }
John Spurlockd67ec252013-09-05 11:31:54 -04001172 if (mTransientNavigationConfirmation != null) {
1173 mTransientNavigationConfirmation.loadSetting();
1174 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001175 }
1176 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001177 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001178 }
Jeff Brown70825162012-03-28 17:27:48 -07001179 }
1180
1181 private void enablePointerLocation() {
1182 if (mPointerLocationView == null) {
1183 mPointerLocationView = new PointerLocationView(mContext);
1184 mPointerLocationView.setPrintCoords(false);
1185
Dianne Hackbornc777e072010-02-12 13:07:59 -08001186 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1187 WindowManager.LayoutParams.MATCH_PARENT,
1188 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001189 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001190 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1191 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1192 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1193 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001194 if (ActivityManager.isHighEndGfx()) {
1195 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1196 lp.privateFlags |=
1197 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1198 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001199 lp.format = PixelFormat.TRANSLUCENT;
1200 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001201 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001202 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001203 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001204 wm.addView(mPointerLocationView, lp);
1205
Craig Mautner037aa8d2013-06-07 10:35:44 -07001206 mPointerLocationPointerEventListener = new PointerLocationPointerEventListener();
1207 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationPointerEventListener);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001208 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001209 }
Jeff Brown70825162012-03-28 17:27:48 -07001210
1211 private void disablePointerLocation() {
Craig Mautner037aa8d2013-06-07 10:35:44 -07001212 if (mPointerLocationPointerEventListener != null) {
1213 mWindowManagerFuncs.unregisterPointerEventListener(
1214 mPointerLocationPointerEventListener);
1215 mPointerLocationPointerEventListener = null;
Jeff Brown70825162012-03-28 17:27:48 -07001216 }
1217
1218 if (mPointerLocationView != null) {
1219 WindowManager wm = (WindowManager)
1220 mContext.getSystemService(Context.WINDOW_SERVICE);
1221 wm.removeView(mPointerLocationView);
1222 mPointerLocationView = null;
1223 }
1224 }
1225
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001226 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001227 try {
1228 int rotation = mContext.getResources().getInteger(resID);
1229 switch (rotation) {
1230 case 0:
1231 return Surface.ROTATION_0;
1232 case 90:
1233 return Surface.ROTATION_90;
1234 case 180:
1235 return Surface.ROTATION_180;
1236 case 270:
1237 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001238 }
1239 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001240 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001241 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001242 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001243 }
1244
1245 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001246 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001247 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001248 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001249
1250 outAppOp[0] = AppOpsManager.OP_NONE;
1251
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001252 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1253 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001254 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001255 }
1256 String permission = null;
1257 switch (type) {
1258 case TYPE_TOAST:
1259 // XXX right now the app process has complete control over
1260 // this... should introduce a token to let the system
1261 // monitor/control what they are doing.
1262 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001263 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001264 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001265 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001266 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001267 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001268 break;
1269 case TYPE_PHONE:
1270 case TYPE_PRIORITY_PHONE:
1271 case TYPE_SYSTEM_ALERT:
1272 case TYPE_SYSTEM_ERROR:
1273 case TYPE_SYSTEM_OVERLAY:
1274 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001275 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001276 break;
1277 default:
1278 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1279 }
1280 if (permission != null) {
1281 if (mContext.checkCallingOrSelfPermission(permission)
1282 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001283 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001284 }
1285 }
Jeff Brown98365d72012-08-19 20:30:52 -07001286 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001287 }
Craig Mautner88400d32012-09-30 12:35:45 -07001288
1289 @Override
1290 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1291
1292 // If this switch statement is modified, modify the comment in the declarations of
1293 // the type in {@link WindowManager.LayoutParams} as well.
1294 switch (attrs.type) {
1295 default:
1296 // These are the windows that by default are shown only to the user that created
1297 // them. If this needs to be overridden, set
1298 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1299 // {@link WindowManager.LayoutParams}. Note that permission
1300 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1301 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1302 return true;
1303 }
1304 break;
1305
1306 // These are the windows that by default are shown to all users. However, to
1307 // protect against spoofing, check permissions below.
1308 case TYPE_APPLICATION_STARTING:
1309 case TYPE_BOOT_PROGRESS:
1310 case TYPE_DISPLAY_OVERLAY:
1311 case TYPE_HIDDEN_NAV_CONSUMER:
1312 case TYPE_KEYGUARD:
Jim Miller5ecd8112013-01-09 18:50:26 -08001313 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001314 case TYPE_KEYGUARD_DIALOG:
1315 case TYPE_MAGNIFICATION_OVERLAY:
1316 case TYPE_NAVIGATION_BAR:
1317 case TYPE_NAVIGATION_BAR_PANEL:
1318 case TYPE_PHONE:
1319 case TYPE_POINTER:
1320 case TYPE_PRIORITY_PHONE:
1321 case TYPE_RECENTS_OVERLAY:
1322 case TYPE_SEARCH_BAR:
1323 case TYPE_STATUS_BAR:
1324 case TYPE_STATUS_BAR_PANEL:
1325 case TYPE_STATUS_BAR_SUB_PANEL:
1326 case TYPE_SYSTEM_DIALOG:
1327 case TYPE_UNIVERSE_BACKGROUND:
1328 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001329 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001330 break;
1331 }
1332
1333 // Check if third party app has set window to system window type.
1334 return mContext.checkCallingOrSelfPermission(
1335 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1336 != PackageManager.PERMISSION_GRANTED;
1337 }
1338
Craig Mautner967212c2013-04-13 21:10:58 -07001339 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001340 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1341 switch (attrs.type) {
1342 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001343 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001344 // These types of windows can't receive input events.
1345 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1346 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001347 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001348 break;
1349 }
1350 }
1351
1352 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001353 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001354 }
1355
Jeff Browndaa37532012-05-01 15:54:03 -07001356 private boolean isHidden(int accessibilityMode) {
1357 switch (accessibilityMode) {
1358 case 1:
1359 return mLidState == LID_CLOSED;
1360 case 2:
1361 return mLidState == LID_OPEN;
1362 default:
1363 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001364 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001365 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001366
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001367 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001368 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001369 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1370 int navigationPresence) {
1371 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1372
Jeff Brownf71343d2013-05-31 17:59:11 -07001373 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001374 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001375 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001376
Jeff Browndaa37532012-05-01 15:54:03 -07001377 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1378 || (keyboardPresence == PRESENCE_INTERNAL
1379 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001380 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001381 if (!mHasSoftInput) {
1382 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1383 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001384 }
1385
Jeff Browndaa37532012-05-01 15:54:03 -07001386 if (config.navigation == Configuration.NAVIGATION_NONAV
1387 || (navigationPresence == PRESENCE_INTERNAL
1388 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001389 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001390 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001391 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001392
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001393 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001394 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001395 public int windowTypeToLayerLw(int type) {
1396 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001397 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001398 }
1399 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001400 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001401 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001402 case TYPE_PRIVATE_PRESENTATION:
1403 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001404 case TYPE_WALLPAPER:
1405 // wallpaper is at the bottom, though the window manager may move it.
1406 return 2;
1407 case TYPE_PHONE:
1408 return 3;
1409 case TYPE_SEARCH_BAR:
1410 return 4;
Craig Mautner88400d32012-09-30 12:35:45 -07001411 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001412 case TYPE_SYSTEM_DIALOG:
1413 return 5;
1414 case TYPE_TOAST:
1415 // toasts and the plugged-in battery thing
1416 return 6;
1417 case TYPE_PRIORITY_PHONE:
1418 // SIM errors and unlock. Not sure if this really should be in a high layer.
1419 return 7;
1420 case TYPE_DREAM:
1421 // used for Dreams (screensavers with TYPE_DREAM windows)
1422 return 8;
1423 case TYPE_SYSTEM_ALERT:
1424 // like the ANR / app crashed dialogs
1425 return 9;
1426 case TYPE_INPUT_METHOD:
1427 // on-screen keyboards and other such input method user interfaces go here.
1428 return 10;
1429 case TYPE_INPUT_METHOD_DIALOG:
1430 // on-screen keyboards and other such input method user interfaces go here.
1431 return 11;
Jim Miller5ecd8112013-01-09 18:50:26 -08001432 case TYPE_KEYGUARD_SCRIM:
1433 // the safety window that shows behind keyguard while keyguard is starting
1434 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001435 case TYPE_KEYGUARD:
1436 // the keyguard; nothing on top of these can take focus, since they are
1437 // responsible for power management when displayed.
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001438 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001439 case TYPE_KEYGUARD_DIALOG:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001440 return 14;
Jim Miller5ecd8112013-01-09 18:50:26 -08001441 case TYPE_STATUS_BAR_SUB_PANEL:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001442 return 15;
Jim Miller5ecd8112013-01-09 18:50:26 -08001443 case TYPE_STATUS_BAR:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001444 return 16;
Jim Miller5ecd8112013-01-09 18:50:26 -08001445 case TYPE_STATUS_BAR_PANEL:
1446 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001447 case TYPE_VOLUME_OVERLAY:
1448 // the on-screen volume indicator and controller shown when the user
1449 // changes the device volume
Jim Miller5ecd8112013-01-09 18:50:26 -08001450 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001451 case TYPE_SYSTEM_OVERLAY:
1452 // the on-screen volume indicator and controller shown when the user
1453 // changes the device volume
Jim Miller5ecd8112013-01-09 18:50:26 -08001454 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001455 case TYPE_NAVIGATION_BAR:
1456 // the navigation bar, if available, shows atop most things
Jim Miller5ecd8112013-01-09 18:50:26 -08001457 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001458 case TYPE_NAVIGATION_BAR_PANEL:
1459 // some panels (e.g. search) need to show on top of the navigation bar
Jim Miller5ecd8112013-01-09 18:50:26 -08001460 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001461 case TYPE_SYSTEM_ERROR:
1462 // system-level error dialogs
Jim Miller5ecd8112013-01-09 18:50:26 -08001463 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001464 case TYPE_MAGNIFICATION_OVERLAY:
1465 // used to highlight the magnified portion of a display
Jim Miller5ecd8112013-01-09 18:50:26 -08001466 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001467 case TYPE_DISPLAY_OVERLAY:
1468 // used to simulate secondary display devices
Jim Miller5ecd8112013-01-09 18:50:26 -08001469 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001470 case TYPE_DRAG:
1471 // the drag layer: input for drag-and-drop is associated with this window,
1472 // which sits above all other focusable windows
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001473 return 25;
Jim Miller5ecd8112013-01-09 18:50:26 -08001474 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001475 return 26;
Jim Miller5ecd8112013-01-09 18:50:26 -08001476 case TYPE_BOOT_PROGRESS:
1477 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001478 case TYPE_POINTER:
1479 // the (mouse) pointer layer
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001480 return 28;
Jim Miller5ecd8112013-01-09 18:50:26 -08001481 case TYPE_HIDDEN_NAV_CONSUMER:
1482 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001483 }
1484 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001485 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001486 }
1487
1488 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001489 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001490 public int subWindowTypeToLayerLw(int type) {
1491 switch (type) {
1492 case TYPE_APPLICATION_PANEL:
1493 case TYPE_APPLICATION_ATTACHED_DIALOG:
1494 return APPLICATION_PANEL_SUBLAYER;
1495 case TYPE_APPLICATION_MEDIA:
1496 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001497 case TYPE_APPLICATION_MEDIA_OVERLAY:
1498 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001499 case TYPE_APPLICATION_SUB_PANEL:
1500 return APPLICATION_SUB_PANEL_SUBLAYER;
1501 }
1502 Log.e(TAG, "Unknown sub-window type: " + type);
1503 return 0;
1504 }
1505
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001506 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001507 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001508 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001509 }
1510
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001511 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001512 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001513 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001514 }
1515
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001516 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001517 if (mHasNavigationBar) {
1518 // For a basic navigation bar, when we are in landscape mode we place
1519 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001520 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1521 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001522 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001523 }
1524 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001525 }
1526
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001527 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001528 if (mHasNavigationBar) {
1529 // For a basic navigation bar, when we are in portrait mode we place
1530 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001531 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1532 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001533 }
1534 }
1535 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001536 }
1537
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001538 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1539 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001540 }
1541
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001542 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001543 // There is a separate status bar at the top of the display. We don't count that as part
1544 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001545 // we do want to exclude it since applications can't generally use that part
1546 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001547 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001548 }
1549
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001550 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001551 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) {
1552 return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD;
1553 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001554
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001555 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001556 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001557 switch (attrs.type) {
1558 case TYPE_STATUS_BAR:
1559 case TYPE_NAVIGATION_BAR:
1560 case TYPE_WALLPAPER:
1561 case TYPE_DREAM:
1562 case TYPE_UNIVERSE_BACKGROUND:
1563 case TYPE_KEYGUARD:
Jim Miller5ecd8112013-01-09 18:50:26 -08001564 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001565 return false;
1566 default:
1567 return true;
1568 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001569 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001570
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001571 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001572 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001573 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1574 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001575 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001576 if (!SHOW_STARTING_ANIMATIONS) {
1577 return null;
1578 }
1579 if (packageName == null) {
1580 return null;
1581 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001582
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001583 WindowManager wm = null;
1584 View view = null;
1585
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001586 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001587 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001588 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1589 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1590 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001591 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001592 try {
1593 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001594 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001595 } catch (PackageManager.NameNotFoundException e) {
1596 // Ignore
1597 }
1598 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001599
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001600 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001601 final TypedArray ta = win.getWindowStyle();
1602 if (ta.getBoolean(
1603 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1604 || ta.getBoolean(
1605 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001606 return null;
1607 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001608
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001609 Resources r = context.getResources();
1610 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001611
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001612 win.setType(
1613 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1614 // Force the window flags: this is a fake window, so it is not really
1615 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1616 // flag because we do know that the next window will take input
1617 // focus, so we want to get the IME window up on top of us right away.
1618 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001619 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001620 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1621 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1622 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001623 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001624 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1625 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1626 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001627
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001628 if (!compatInfo.supportsScreen()) {
1629 win.addFlags(WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW);
1630 }
1631
Adam Powell04fe6eb2013-05-31 14:39:48 -07001632 win.setDefaultIcon(icon);
1633 win.setDefaultLogo(logo);
1634
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001635 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001636 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001637
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001638 final WindowManager.LayoutParams params = win.getAttributes();
1639 params.token = appToken;
1640 params.packageName = packageName;
1641 params.windowAnimations = win.getWindowStyle().getResourceId(
1642 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001643 params.privateFlags |=
1644 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001645 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001646 params.setTitle("Starting " + packageName);
1647
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001648 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1649 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001650
1651 if (win.isFloating()) {
1652 // Whoops, there is no way to display an animation/preview
1653 // of such a thing! After all that work... let's skip it.
1654 // (Note that we must do this here because it is in
1655 // getDecorView() where the theme is evaluated... maybe
1656 // we should peek the floating attribute from the theme
1657 // earlier.)
1658 return null;
1659 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001660
Craig Mautner6fbda632012-07-03 09:26:39 -07001661 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001662 TAG, "Adding starting window for " + packageName
1663 + " / " + appToken + ": "
1664 + (view.getParent() != null ? view : null));
1665
1666 wm.addView(view, params);
1667
1668 // Only return the view if it was successfully added to the
1669 // window manager... which we can tell by it having a parent.
1670 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001671 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001672 // ignore
1673 Log.w(TAG, appToken + " already running, starting window not displayed");
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001674 } catch (RuntimeException e) {
1675 // don't crash if something else bad happens, for example a
1676 // failure loading resources because we are loading from an app
1677 // on external storage that has been unmounted.
1678 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001679 } finally {
1680 if (view != null && view.getParent() == null) {
1681 Log.w(TAG, "view not successfully added to wm, removing view");
1682 wm.removeViewImmediate(view);
1683 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001684 }
1685
1686 return null;
1687 }
1688
1689 /** {@inheritDoc} */
1690 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001691 if (DEBUG_STARTING_WINDOW) {
1692 RuntimeException e = new RuntimeException("here");
1693 e.fillInStackTrace();
1694 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1695 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001696
1697 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001698 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001699 wm.removeView(window);
1700 }
1701 }
1702
1703 /**
1704 * Preflight adding a window to the system.
1705 *
1706 * Currently enforces that three window types are singletons:
1707 * <ul>
1708 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001709 * <li>KEYGUARD_TYPE</li>
1710 * </ul>
1711 *
1712 * @param win The window to be added
1713 * @param attrs Information about the window to be added
1714 *
Jeff Brown98365d72012-08-19 20:30:52 -07001715 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1716 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001717 */
1718 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1719 switch (attrs.type) {
1720 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001721 mContext.enforceCallingOrSelfPermission(
1722 android.Manifest.permission.STATUS_BAR_SERVICE,
1723 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001724 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001725 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001726 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001727 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001728 }
1729 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001730 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001731 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001732 case TYPE_NAVIGATION_BAR:
1733 mContext.enforceCallingOrSelfPermission(
1734 android.Manifest.permission.STATUS_BAR_SERVICE,
1735 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001736 if (mNavigationBar != null) {
1737 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001738 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001739 }
1740 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001741 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001742 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001743 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001744 break;
Jim Millere898ac52012-04-06 17:10:57 -07001745 case TYPE_NAVIGATION_BAR_PANEL:
1746 mContext.enforceCallingOrSelfPermission(
1747 android.Manifest.permission.STATUS_BAR_SERVICE,
1748 "PhoneWindowManager");
1749 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001750 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001751 mContext.enforceCallingOrSelfPermission(
1752 android.Manifest.permission.STATUS_BAR_SERVICE,
1753 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001754 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001755 case TYPE_STATUS_BAR_SUB_PANEL:
1756 mContext.enforceCallingOrSelfPermission(
1757 android.Manifest.permission.STATUS_BAR_SERVICE,
1758 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001759 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001760 case TYPE_KEYGUARD:
1761 if (mKeyguard != null) {
Jeff Brown98365d72012-08-19 20:30:52 -07001762 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001763 }
1764 mKeyguard = win;
1765 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001766 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001767 if (mKeyguardScrim != null) {
1768 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1769 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001770 mKeyguardScrim = win;
1771 break;
1772
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001773 }
Jeff Brown98365d72012-08-19 20:30:52 -07001774 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001775 }
1776
1777 /** {@inheritDoc} */
1778 public void removeWindowLw(WindowState win) {
1779 if (mStatusBar == win) {
1780 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001781 mStatusBarController.setWindow(null);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001782 } else if (mKeyguard == win) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001783 Log.v(TAG, "Removing keyguard window (Did it crash?)");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001784 mKeyguard = null;
Jim Millerc0b676d2013-03-22 16:11:08 -07001785 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001786 } else if (mKeyguardScrim == win) {
1787 Log.v(TAG, "Removing keyguard scrim");
1788 mKeyguardScrim = null;
1789 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001790 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001791 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001792 }
1793 }
1794
1795 static final boolean PRINT_ANIM = false;
1796
1797 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001798 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001799 public int selectAnimationLw(WindowState win, int transit) {
1800 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1801 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001802 if (win == mStatusBar) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001803 if (transit == TRANSIT_EXIT
1804 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001805 return R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001806 } else if (transit == TRANSIT_ENTER
1807 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001808 return R.anim.dock_top_enter;
1809 }
1810 } else if (win == mNavigationBar) {
1811 // This can be on either the bottom or the right.
1812 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001813 if (transit == TRANSIT_EXIT
1814 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001815 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001816 } else if (transit == TRANSIT_ENTER
1817 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001818 return R.anim.dock_bottom_enter;
1819 }
1820 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001821 if (transit == TRANSIT_EXIT
1822 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001823 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001824 } else if (transit == TRANSIT_ENTER
1825 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001826 return R.anim.dock_right_enter;
1827 }
1828 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001829 }
1830
1831 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001832 if (win.hasAppShownWindows()) {
1833 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1834 return com.android.internal.R.anim.app_starting_exit;
1835 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001836 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001837 && transit == TRANSIT_ENTER) {
1838 // Special case: we are animating in a dream, while the keyguard
1839 // is shown. We don't want an animation on the dream, because
1840 // we need it shown immediately with the keyguard animating away
1841 // to reveal it.
1842 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001843 }
1844
1845 return 0;
1846 }
1847
Craig Mautner3c174372013-02-21 17:54:37 -08001848 @Override
1849 public void selectRotationAnimationLw(int anim[]) {
1850 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
1851 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
1852 + (mTopFullscreenOpaqueWindowState == null ?
1853 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
1854 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
1855 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
1856 case ROTATION_ANIMATION_CROSSFADE:
1857 anim[0] = R.anim.rotation_animation_xfade_exit;
1858 anim[1] = R.anim.rotation_animation_enter;
1859 break;
1860 case ROTATION_ANIMATION_JUMPCUT:
1861 anim[0] = R.anim.rotation_animation_jump_exit;
1862 anim[1] = R.anim.rotation_animation_enter;
1863 break;
1864 case ROTATION_ANIMATION_ROTATE:
1865 default:
1866 anim[0] = anim[1] = 0;
1867 break;
1868 }
1869 } else {
1870 anim[0] = anim[1] = 0;
1871 }
1872 }
1873
1874 @Override
1875 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
1876 boolean forceDefault) {
1877 switch (exitAnimId) {
1878 case R.anim.rotation_animation_xfade_exit:
1879 case R.anim.rotation_animation_jump_exit:
1880 // These are the only cases that matter.
1881 if (forceDefault) {
1882 return false;
1883 }
1884 int anim[] = new int[2];
1885 selectRotationAnimationLw(anim);
1886 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
1887 default:
1888 return true;
1889 }
1890 }
1891
1892 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07001893 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
1894 return AnimationUtils.loadAnimation(mContext, onWallpaper
1895 ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter
1896 : com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001897 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04001898
1899 private static void awakenDreams() {
1900 IDreamManager dreamManager = getDreamManager();
1901 if (dreamManager != null) {
1902 try {
1903 dreamManager.awaken();
1904 } catch (RemoteException e) {
1905 // fine, stay asleep then
1906 }
1907 }
1908 }
1909
1910 static IDreamManager getDreamManager() {
1911 return IDreamManager.Stub.asInterface(
1912 ServiceManager.checkService(DreamService.DREAM_SERVICE));
1913 }
1914
Jeff Brown4d396052010-10-29 21:50:21 -07001915 static ITelephony getTelephonyService() {
Mike Lockwoodf5f4ec92011-11-08 14:05:31 -08001916 return ITelephony.Stub.asInterface(
Jeff Brown4d396052010-10-29 21:50:21 -07001917 ServiceManager.checkService(Context.TELEPHONY_SERVICE));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001918 }
1919
Jeff Brown4d396052010-10-29 21:50:21 -07001920 static IAudioService getAudioService() {
1921 IAudioService audioService = IAudioService.Stub.asInterface(
1922 ServiceManager.checkService(Context.AUDIO_SERVICE));
1923 if (audioService == null) {
1924 Log.w(TAG, "Unable to find IAudioService interface.");
1925 }
1926 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001927 }
1928
1929 boolean keyguardOn() {
1930 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
1931 }
1932
1933 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
1934 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
1935 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
1936 };
1937
1938 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001939 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001940 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001941 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08001942 final int keyCode = event.getKeyCode();
1943 final int repeatCount = event.getRepeatCount();
1944 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001945 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08001946 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
1947 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001948
Jeff Brown40013652012-05-16 21:22:36 -07001949 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001950 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001951 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
1952 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001953 }
1954
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001955 // If we think we might have a volume down & power key chord on the way
1956 // but we're not sure, then tell the dispatcher to wait a little while and
1957 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08001958 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001959 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
1960 final long now = SystemClock.uptimeMillis();
1961 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
1962 if (now < timeoutTime) {
1963 return timeoutTime - now;
1964 }
1965 }
1966 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
1967 && mVolumeDownKeyConsumedByScreenshotChord) {
1968 if (!down) {
1969 mVolumeDownKeyConsumedByScreenshotChord = false;
1970 }
1971 return -1;
1972 }
1973 }
1974
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001975 // First we always handle the home key here, so applications
1976 // can never break it, although if keyguard is on, we do let
1977 // it handle it, because that gives us the correct 5 second
1978 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001979 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001980
Jeff Brown49ed71d2010-12-06 17:13:33 -08001981 // If we have released the home key, and didn't do anything else
1982 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07001983 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07001984 cancelPreloadRecentApps();
1985
Jeff Brown49ed71d2010-12-06 17:13:33 -08001986 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07001987 if (mHomeConsumed) {
1988 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07001989 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001990 }
Jeff Browncaca8812013-05-09 13:34:33 -07001991
1992 if (canceled) {
1993 Log.i(TAG, "Ignoring HOME; event canceled.");
1994 return -1;
1995 }
1996
1997 // If an incoming call is ringing, HOME is totally disabled.
1998 // (The user is already on the InCallScreen at this point,
1999 // and his ONLY options are to answer or reject the call.)
2000 try {
2001 ITelephony telephonyService = getTelephonyService();
2002 if (telephonyService != null && telephonyService.isRinging()) {
2003 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2004 return -1;
2005 }
2006 } catch (RemoteException ex) {
2007 Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
2008 }
2009
2010 // Delay handling home if a double-tap is possible.
2011 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2012 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2013 mHomeDoubleTapPending = true;
2014 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2015 ViewConfiguration.getDoubleTapTimeout());
2016 return -1;
2017 }
2018
2019 // Go home!
2020 launchHomeFromHotKey();
2021 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002022 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002023
2024 // If a system window has focus, then it doesn't make sense
2025 // right now to interact with applications.
2026 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2027 if (attrs != null) {
2028 final int type = attrs.type;
2029 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
Jim Miller5ecd8112013-01-09 18:50:26 -08002030 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002031 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
2032 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002033 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002034 }
2035 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2036 for (int i=0; i<typeCount; i++) {
2037 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2038 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002039 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002040 }
2041 }
2042 }
Jeff Browncaca8812013-05-09 13:34:33 -07002043
2044 // Remember that home is pressed and handle special actions.
2045 if (repeatCount == 0) {
2046 mHomePressed = true;
2047 if (mHomeDoubleTapPending) {
2048 mHomeDoubleTapPending = false;
2049 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2050 handleDoubleTapOnHome();
2051 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2052 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2053 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002054 }
Jeff Browncaca8812013-05-09 13:34:33 -07002055 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2056 if (!keyguardOn) {
2057 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002058 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002059 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002060 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002061 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002062 // Hijack modified menu keys for debugging features
2063 final int chordBug = KeyEvent.META_SHIFT_ON;
2064
2065 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002066 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002067 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002068 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2069 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002070 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002071 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002072 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002073 Intent service = new Intent();
2074 service.setClassName(mContext, "com.android.server.LoadAverageService");
2075 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002076 boolean shown = Settings.Global.getInt(
2077 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002078 if (!shown) {
2079 mContext.startService(service);
2080 } else {
2081 mContext.stopService(service);
2082 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002083 Settings.Global.putInt(
2084 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002085 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002086 }
2087 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002088 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002089 if (down) {
2090 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002091 mSearchKeyShortcutPending = true;
2092 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002093 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002094 } else {
2095 mSearchKeyShortcutPending = false;
2096 if (mConsumeSearchKeyUp) {
2097 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002098 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002099 }
2100 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002101 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002102 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002103 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002104 if (down && repeatCount == 0) {
2105 preloadRecentApps();
2106 } else if (!down) {
2107 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002108 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002109 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002110 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002111 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2112 if (down) {
2113 if (repeatCount == 0) {
2114 mAssistKeyLongPressed = false;
2115 } else if (repeatCount == 1) {
2116 mAssistKeyLongPressed = true;
2117 if (!keyguardOn) {
2118 launchAssistLongPressAction();
2119 }
2120 }
2121 } else {
2122 if (mAssistKeyLongPressed) {
2123 mAssistKeyLongPressed = false;
2124 } else {
2125 if (!keyguardOn) {
2126 launchAssistAction();
2127 }
2128 }
2129 }
2130 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002131 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2132 if (down && repeatCount == 0) {
2133 mHandler.post(mScreenshotRunnable);
2134 }
2135 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002136 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2137 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2138 if (down) {
2139 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2140
2141 // Disable autobrightness if it's on
2142 int auto = Settings.System.getIntForUser(
2143 mContext.getContentResolver(),
2144 Settings.System.SCREEN_BRIGHTNESS_MODE,
2145 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2146 UserHandle.USER_CURRENT_OR_SELF);
2147 if (auto != 0) {
2148 Settings.System.putIntForUser(mContext.getContentResolver(),
2149 Settings.System.SCREEN_BRIGHTNESS_MODE,
2150 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2151 UserHandle.USER_CURRENT_OR_SELF);
2152 }
2153
2154 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2155 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2156 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2157 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2158 Settings.System.SCREEN_BRIGHTNESS,
2159 mPowerManager.getDefaultScreenBrightnessSetting(),
2160 UserHandle.USER_CURRENT_OR_SELF);
2161 brightness += step;
2162 // Make sure we don't go beyond the limits.
2163 brightness = Math.min(max, brightness);
2164 brightness = Math.max(min, brightness);
2165
2166 Settings.System.putIntForUser(mContext.getContentResolver(),
2167 Settings.System.SCREEN_BRIGHTNESS, brightness,
2168 UserHandle.USER_CURRENT_OR_SELF);
2169 Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG);
2170 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF);
2171 }
2172 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002173 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002174
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002175 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002176 // Any printing key that is chorded with Search should be consumed
2177 // even if no shortcut was invoked. This prevents text from being
2178 // inadvertently inserted when using a keyboard that has built-in macro
2179 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002180 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002181 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2182 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002183 mConsumeSearchKeyUp = true;
2184 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002185 if (down && repeatCount == 0 && !keyguardOn) {
2186 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2187 if (shortcutIntent != null) {
2188 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002189 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002190 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002191 } catch (ActivityNotFoundException ex) {
2192 Slog.w(TAG, "Dropping shortcut key combination because "
2193 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002194 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002195 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002196 } else {
2197 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002198 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002199 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002200 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002201 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002202 }
2203 }
2204
Jeff Brown68b909d2011-12-07 16:36:01 -08002205 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002206 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002207 && (metaState & KeyEvent.META_META_ON) != 0) {
2208 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002209 if (kcm.isPrintingKey(keyCode)) {
2210 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2211 metaState & ~(KeyEvent.META_META_ON
2212 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2213 if (shortcutIntent != null) {
2214 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2215 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002216 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002217 } catch (ActivityNotFoundException ex) {
2218 Slog.w(TAG, "Dropping shortcut key combination because "
2219 + "the activity to which it is registered was not found: "
2220 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2221 }
2222 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002223 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002224 }
2225 }
2226
Jeff Brown6651a632011-11-28 12:59:11 -08002227 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002228 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002229 String category = sApplicationLaunchKeyCategories.get(keyCode);
2230 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002231 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002232 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2233 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002234 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002235 } catch (ActivityNotFoundException ex) {
2236 Slog.w(TAG, "Dropping application launch key because "
2237 + "the activity to which it is registered was not found: "
2238 + "keyCode=" + keyCode + ", category=" + category, ex);
2239 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002240 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002241 }
2242 }
2243
Jeff Brown68b909d2011-12-07 16:36:01 -08002244 // Display task switcher for ALT-TAB or Meta-TAB.
2245 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Jeff Brown602ab322012-05-16 13:33:47 -07002246 if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002247 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
2248 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2249 || KeyEvent.metaStateHasModifiers(
2250 shiftlessModifiers, KeyEvent.META_META_ON)) {
2251 mRecentAppsDialogHeldModifiers = shiftlessModifiers;
2252 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW);
2253 return -1;
2254 }
2255 }
2256 } else if (!down && mRecentAppsDialogHeldModifiers != 0
2257 && (metaState & mRecentAppsDialogHeldModifiers) == 0) {
2258 mRecentAppsDialogHeldModifiers = 0;
Jeff Brown602ab322012-05-16 13:33:47 -07002259 showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS :
2260 RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH);
Jeff Brown68b909d2011-12-07 16:36:01 -08002261 }
2262
Jeff Browncf39bdf2012-05-18 14:41:19 -07002263 // Handle keyboard language switching.
2264 if (down && repeatCount == 0
2265 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2266 || (keyCode == KeyEvent.KEYCODE_SPACE
2267 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2268 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2269 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2270 return -1;
2271 }
2272 if (mLanguageSwitchKeyPressed && !down
2273 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2274 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2275 mLanguageSwitchKeyPressed = false;
2276 return -1;
2277 }
2278
Justin Kohd378ad72013-04-01 12:18:26 -07002279 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2280 return -1;
2281 }
2282
Jeff Brown68b909d2011-12-07 16:36:01 -08002283 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002284 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002285 }
2286
Jeff Brown3915bb82010-11-05 15:02:16 -07002287 /** {@inheritDoc} */
2288 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002289 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002290 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002291 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002292 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2293 + ", flags=" + event.getFlags()
2294 + ", keyCode=" + event.getKeyCode()
2295 + ", scanCode=" + event.getScanCode()
2296 + ", metaState=" + event.getMetaState()
2297 + ", repeatCount=" + event.getRepeatCount()
2298 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002299 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002300
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002301 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002302 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2303 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002304 final int keyCode = event.getKeyCode();
2305 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002306 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2307 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002308
Jeff Brown54875002011-04-06 15:33:01 -07002309 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002310 final FallbackAction fallbackAction;
2311 if (initialDown) {
2312 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2313 } else {
2314 fallbackAction = mFallbackActions.get(keyCode);
2315 }
2316
2317 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002318 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002319 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2320 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002321 }
2322
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002323 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2324 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002325 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002326 event.getAction(), fallbackAction.keyCode,
2327 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002328 event.getDeviceId(), event.getScanCode(),
2329 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002330
2331 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2332 fallbackEvent.recycle();
2333 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002334 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002335
2336 if (initialDown) {
2337 mFallbackActions.put(keyCode, fallbackAction);
2338 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2339 mFallbackActions.remove(keyCode);
2340 fallbackAction.recycle();
2341 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002342 }
2343 }
2344
Jeff Brown40013652012-05-16 21:22:36 -07002345 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002346 if (fallbackEvent == null) {
2347 Slog.d(TAG, "No fallback.");
2348 } else {
2349 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2350 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002351 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002352 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002353 }
2354
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002355 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
2356 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true);
2357 if ((actions & ACTION_PASS_TO_USER) != 0) {
2358 long delayMillis = interceptKeyBeforeDispatching(
2359 win, fallbackEvent, policyFlags);
2360 if (delayMillis == 0) {
2361 return true;
2362 }
2363 }
2364 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002365 }
2366
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002367 private void launchAssistLongPressAction() {
2368 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2369 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2370
2371 // launch the search activity
2372 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2373 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2374 try {
Jim Miller45308b12012-06-18 19:23:39 -07002375 // TODO: This only stops the factory-installed search manager.
2376 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002377 SearchManager searchManager = getSearchManager();
2378 if (searchManager != null) {
2379 searchManager.stopSearch();
2380 }
Michael Wright43e27f72013-04-10 14:06:48 -07002381 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002382 } catch (ActivityNotFoundException e) {
2383 Slog.w(TAG, "No activity to handle assist long press action.", e);
2384 }
2385 }
2386
2387 private void launchAssistAction() {
2388 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002389 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002390 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002391 if (intent != null) {
2392 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2393 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2394 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2395 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002396 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002397 } catch (ActivityNotFoundException e) {
2398 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002399 }
2400 }
2401 }
2402
2403 private SearchManager getSearchManager() {
2404 if (mSearchManager == null) {
2405 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2406 }
2407 return mSearchManager;
2408 }
2409
Jeff Browncaca8812013-05-09 13:34:33 -07002410 private void preloadRecentApps() {
2411 mPreloadedRecentApps = true;
2412 try {
2413 IStatusBarService statusbar = getStatusBarService();
2414 if (statusbar != null) {
2415 statusbar.preloadRecentApps();
2416 }
2417 } catch (RemoteException e) {
2418 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2419 // re-acquire status bar service next time it is needed.
2420 mStatusBarService = null;
2421 }
2422 }
2423
2424 private void cancelPreloadRecentApps() {
2425 if (mPreloadedRecentApps) {
2426 mPreloadedRecentApps = false;
2427 try {
2428 IStatusBarService statusbar = getStatusBarService();
2429 if (statusbar != null) {
2430 statusbar.cancelPreloadRecentApps();
2431 }
2432 } catch (RemoteException e) {
2433 Slog.e(TAG, "RemoteException when showing recent apps", e);
2434 // re-acquire status bar service next time it is needed.
2435 mStatusBarService = null;
2436 }
2437 }
2438 }
2439
2440 private void toggleRecentApps() {
2441 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2442 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
2443 try {
2444 IStatusBarService statusbar = getStatusBarService();
2445 if (statusbar != null) {
2446 statusbar.toggleRecentApps();
2447 }
2448 } catch (RemoteException e) {
2449 Slog.e(TAG, "RemoteException when showing recent apps", e);
2450 // re-acquire status bar service next time it is needed.
2451 mStatusBarService = null;
2452 }
2453 }
2454
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002455 /**
2456 * A home key -> launch home action was detected. Take the appropriate action
2457 * given the situation with the keyguard.
2458 */
2459 void launchHomeFromHotKey() {
Jim Miller5ecd8112013-01-09 18:50:26 -08002460 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotHidden()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002461 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002462 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002463 // when in keyguard restricted mode, must first verify unlock
2464 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002465 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002466 public void onKeyguardExitResult(boolean success) {
2467 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002468 try {
2469 ActivityManagerNative.getDefault().stopAppSwitches();
2470 } catch (RemoteException e) {
2471 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002472 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002473 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002474 }
2475 }
2476 });
2477 } else {
2478 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002479 try {
2480 ActivityManagerNative.getDefault().stopAppSwitches();
2481 } catch (RemoteException e) {
2482 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002483 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002484 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002485 }
2486 }
2487
John Spurlock04db1762013-05-13 12:46:41 -04002488 private final Runnable mClearHideNavigationFlag = new Runnable() {
2489 @Override
2490 public void run() {
2491 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2492 // Clear flags.
2493 mForceClearedSystemUiFlags &=
2494 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2495 }
2496 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002497 }
2498 };
2499
2500 /**
2501 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2502 * to determine when the nav bar should be shown and prevent applications from
2503 * receiving those touches.
2504 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002505 final class HideNavInputEventReceiver extends InputEventReceiver {
2506 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2507 super(inputChannel, looper);
2508 }
2509
Dianne Hackborndf89e652011-10-06 22:35:11 -07002510 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002511 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002512 boolean handled = false;
2513 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002514 if (event instanceof MotionEvent
2515 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2516 final MotionEvent motionEvent = (MotionEvent)event;
2517 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002518 // When the user taps down, we re-show the nav bar.
2519 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002520 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002521 // Any user activity always causes us to show the
2522 // navigation controls, if they had been hidden.
2523 // We also clear the low profile and only content
2524 // flags so that tapping on the screen will atomically
2525 // restore all currently hidden screen decorations.
2526 int newVal = mResettingSystemUiFlags |
2527 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2528 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2529 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002530 if (mResettingSystemUiFlags != newVal) {
2531 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002532 changed = true;
2533 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002534 // We don't allow the system's nav bar to be hidden
2535 // again for 1 second, to prevent applications from
2536 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002537 newVal = mForceClearedSystemUiFlags |
2538 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002539 if (mForceClearedSystemUiFlags != newVal) {
2540 mForceClearedSystemUiFlags = newVal;
2541 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002542 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002543 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002544 }
2545 if (changed) {
2546 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2547 }
2548 }
2549 }
2550 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002551 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002552 }
2553 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002554 }
2555 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2556 new InputEventReceiver.Factory() {
2557 @Override
2558 public InputEventReceiver createInputEventReceiver(
2559 InputChannel inputChannel, Looper looper) {
2560 return new HideNavInputEventReceiver(inputChannel, looper);
2561 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002562 };
2563
2564 @Override
2565 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002566 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2567 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
John Spurlock27735a42013-08-14 17:57:38 -04002568
Dianne Hackborndf89e652011-10-06 22:35:11 -07002569 // Reset any bits in mForceClearingStatusBarVisibility that
2570 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002571 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002572 // Clear any bits in the new visibility that are currently being
2573 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002574 return visibility & ~mResettingSystemUiFlags
2575 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002576 }
2577
Craig Mautner69b08182012-09-05 13:07:13 -07002578 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002579 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
2580 final int fl = attrs.flags;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002581 final int systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002582
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002583 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002584 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002585 int availRight, availBottom;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002586 if (mCanHideNavigationBar &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002587 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002588 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2589 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2590 } else {
2591 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2592 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2593 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002594 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2595 if ((fl & FLAG_FULLSCREEN) != 0) {
2596 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2597 availRight - mStableFullscreenRight,
2598 availBottom - mStableFullscreenBottom);
2599 } else {
2600 contentInset.set(mStableLeft, mStableTop,
2601 availRight - mStableRight, availBottom - mStableBottom);
2602 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002603 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002604 contentInset.setEmpty();
2605 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002606 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2607 contentInset.set(mCurLeft, mCurTop,
2608 availRight - mCurRight, availBottom - mCurBottom);
2609 } else {
2610 contentInset.set(mCurLeft, mCurTop,
2611 availRight - mCurRight, availBottom - mCurBottom);
2612 }
2613 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002614 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002615 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002616 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002617
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002618 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002619 @Override
2620 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2621 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002622 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2623 if (isDefaultDisplay) {
2624 switch (displayRotation) {
2625 case Surface.ROTATION_90:
2626 overscanLeft = mOverscanTop;
2627 overscanTop = mOverscanRight;
2628 overscanRight = mOverscanBottom;
2629 overscanBottom = mOverscanLeft;
2630 break;
2631 case Surface.ROTATION_180:
2632 overscanLeft = mOverscanRight;
2633 overscanTop = mOverscanBottom;
2634 overscanRight = mOverscanLeft;
2635 overscanBottom = mOverscanTop;
2636 break;
2637 case Surface.ROTATION_270:
2638 overscanLeft = mOverscanBottom;
2639 overscanTop = mOverscanLeft;
2640 overscanRight = mOverscanTop;
2641 overscanBottom = mOverscanRight;
2642 break;
2643 default:
2644 overscanLeft = mOverscanLeft;
2645 overscanTop = mOverscanTop;
2646 overscanRight = mOverscanRight;
2647 overscanBottom = mOverscanBottom;
2648 break;
2649 }
2650 } else {
2651 overscanLeft = 0;
2652 overscanTop = 0;
2653 overscanRight = 0;
2654 overscanBottom = 0;
2655 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002656 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2657 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2658 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2659 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002660 mSystemLeft = 0;
2661 mSystemTop = 0;
2662 mSystemRight = displayWidth;
2663 mSystemBottom = displayHeight;
2664 mUnrestrictedScreenLeft = overscanLeft;
2665 mUnrestrictedScreenTop = overscanTop;
2666 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2667 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2668 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2669 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002670 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2671 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002672 mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002673 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002674 mDockTop = mContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002675 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002676 mDockRight = mContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002677 = mCurRight = displayWidth - overscanRight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002678 mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002679 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002680 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002681 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002682
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002683 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2684 final Rect pf = mTmpParentFrame;
2685 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002686 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002687 final Rect vf = mTmpVisibleFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002688 pf.left = df.left = of.left = vf.left = mDockLeft;
2689 pf.top = df.top = of.top = vf.top = mDockTop;
2690 pf.right = df.right = of.right = vf.right = mDockRight;
2691 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002692
Craig Mautner69b08182012-09-05 13:07:13 -07002693 if (isDefaultDisplay) {
2694 // For purposes of putting out fake window up to steal focus, we will
2695 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002696 final int sysui = mLastSystemUiFlags;
2697 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
2698 boolean navTransparent = (sysui & View.SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION) != 0;
John Spurlocke47193d2013-08-27 14:23:33 -04002699 boolean transientAllowed = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
John Spurlocke1f366f2013-08-05 12:22:40 -04002700 navTransparent &= !transientAllowed; // transient trumps transparent
Dianne Hackborne26ab702011-10-16 13:21:33 -07002701
Craig Mautner69b08182012-09-05 13:07:13 -07002702 // When the navigation bar isn't visible, we put up a fake
2703 // input window to catch all touch events. This way we can
2704 // detect when the user presses anywhere to bring back the nav
2705 // bar and ensure the application doesn't see the event.
John Spurlocke1f366f2013-08-05 12:22:40 -04002706 if (navVisible || transientAllowed) {
Craig Mautner69b08182012-09-05 13:07:13 -07002707 if (mHideNavFakeWindow != null) {
2708 mHideNavFakeWindow.dismiss();
2709 mHideNavFakeWindow = null;
2710 }
2711 } else if (mHideNavFakeWindow == null) {
2712 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2713 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
2714 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER,
2715 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002716 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002717
Craig Mautner69b08182012-09-05 13:07:13 -07002718 // For purposes of positioning and showing the nav bar, if we have
2719 // decided that it can't be hidden (because of the screen aspect ratio),
2720 // then take that into account.
2721 navVisible |= !mCanHideNavigationBar;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002722
John Spurlockad3e6cb2013-04-30 08:47:43 -04002723 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07002724 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04002725 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07002726 // Force the navigation bar to its appropriate place and
2727 // size. We need to do this directly, instead of relying on
2728 // it to bubble up from the nav bar, because this needs to
2729 // change atomically with screen rotations.
2730 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2731 if (mNavigationBarOnBottom) {
2732 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002733 int top = displayHeight - overscanBottom
2734 - mNavigationBarHeightForRotation[displayRotation];
2735 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07002736 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlocke1f366f2013-08-05 12:22:40 -04002737 if (transientNavBarShowing || navTransparent) {
John Spurlock27735a42013-08-14 17:57:38 -04002738 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002739 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002740 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002741 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08002742 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
2743 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002744 } else {
2745 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002746 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002747 }
John Spurlockb77edbf2013-08-21 21:04:12 -04002748 if (navVisible && !navTransparent && !mNavigationBar.isAnimatingLw()
2749 && !mNavigationBarController.wasRecentlyTransparent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002750 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002751 // and not in the process of animating on or off, then
2752 // we can tell the app that it is covered by it.
2753 mSystemBottom = mTmpNavigationFrame.top;
2754 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002755 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002756 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002757 int left = displayWidth - overscanRight
2758 - mNavigationBarWidthForRotation[displayRotation];
2759 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07002760 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlocke1f366f2013-08-05 12:22:40 -04002761 if (transientNavBarShowing || navTransparent) {
John Spurlock27735a42013-08-14 17:57:38 -04002762 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002763 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002764 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002765 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08002766 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
2767 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07002768 } else {
2769 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002770 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002771 }
John Spurlockb77edbf2013-08-21 21:04:12 -04002772 if (navVisible && !navTransparent && !mNavigationBar.isAnimatingLw()
2773 && !mNavigationBarController.wasRecentlyTransparent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07002774 // If the nav bar is currently requested to be visible,
2775 // and not in the process of animating on or off, then
2776 // we can tell the app that it is covered by it.
2777 mSystemRight = mTmpNavigationFrame.left;
2778 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002779 }
Craig Mautner69b08182012-09-05 13:07:13 -07002780 // Make sure the content and current rectangles are updated to
2781 // account for the restrictions from the navigation bar.
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002782 mContentTop = mCurTop = mDockTop;
2783 mContentBottom = mCurBottom = mDockBottom;
2784 mContentLeft = mCurLeft = mDockLeft;
2785 mContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002786 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2787 // And compute the final frame.
2788 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002789 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07002790 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04002791 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002792 updateSysUiVisibility = true;
2793 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002794 }
Craig Mautnereda67292013-04-28 13:50:14 -07002795 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07002796 mDockLeft, mDockTop, mDockRight, mDockBottom));
2797
2798 // decide where the status bar goes ahead of time
2799 if (mStatusBar != null) {
2800 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002801 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
2802 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2803 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
2804 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
2805 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002806 vf.left = mStableLeft;
2807 vf.top = mStableTop;
2808 vf.right = mStableRight;
2809 vf.bottom = mStableBottom;
2810
2811 mStatusBarLayer = mStatusBar.getSurfaceLayer();
2812
2813 // Let the status bar determine its size.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002814 mStatusBar.computeFrameLw(pf, df, vf, vf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002815
2816 // For layout, the status bar is always at the top with our fixed height.
2817 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
2818
John Spurlocke1f366f2013-08-05 12:22:40 -04002819 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
2820 boolean statusBarTransparent = (sysui & View.SYSTEM_UI_FLAG_TRANSPARENT_STATUS) != 0;
John Spurlock32beb2c2013-03-11 10:16:47 -04002821
Craig Mautner69b08182012-09-05 13:07:13 -07002822 // If the status bar is hidden, we don't want to cause
2823 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04002824 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07002825 // Status bar may go away, so the screen area it occupies
2826 // is available to apps but just covering them when the
2827 // status bar is visible.
2828 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
2829
2830 mContentTop = mCurTop = mDockTop;
2831 mContentBottom = mCurBottom = mDockBottom;
2832 mContentLeft = mCurLeft = mDockLeft;
2833 mContentRight = mCurRight = mDockRight;
2834
Craig Mautnereda67292013-04-28 13:50:14 -07002835 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07002836 String.format(
2837 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
2838 mDockLeft, mDockTop, mDockRight, mDockBottom,
2839 mContentLeft, mContentTop, mContentRight, mContentBottom,
2840 mCurLeft, mCurTop, mCurRight, mCurBottom));
2841 }
John Spurlocke1f366f2013-08-05 12:22:40 -04002842 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockb77edbf2013-08-21 21:04:12 -04002843 && !statusBarTransient && !statusBarTransparent
2844 && !mStatusBarController.wasRecentlyTransparent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002845 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002846 // and not in the process of animating on or off, then
2847 // we can tell the app that it is covered by it.
2848 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
2849 }
John Spurlock27735a42013-08-14 17:57:38 -04002850 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002851 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04002852 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002853 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04002854 if (updateSysUiVisibility) {
2855 updateSystemUiVisibilityLw();
2856 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002857 }
2858 }
2859
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002860 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002861 @Override
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002862 public int getSystemDecorRectLw(Rect systemRect) {
2863 systemRect.left = mSystemLeft;
2864 systemRect.top = mSystemTop;
2865 systemRect.right = mSystemRight;
2866 systemRect.bottom = mSystemBottom;
2867 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
2868 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
2869 return 0;
2870 }
2871
Craig Mautner967212c2013-04-13 21:10:58 -07002872 @Override
2873 public void getContentRectLw(Rect r) {
2874 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
2875 }
2876
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002877 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
2878 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002879 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
2880 // Here's a special case: if this attached window is a panel that is
2881 // above the dock window, and the window it is attached to is below
2882 // the dock window, then the frames we computed for the window it is
2883 // attached to can not be used because the dock is effectively part
2884 // of the underlying window and the attached window is floating on top
2885 // of the whole thing. So, we ignore the attached window and explicitly
2886 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002887 df.left = of.left = cf.left = vf.left = mDockLeft;
2888 df.top = of.top = cf.top = vf.top = mDockTop;
2889 df.right = of.right = cf.right = vf.right = mDockRight;
2890 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002891 } else {
2892 // The effective display frame of the attached window depends on
2893 // whether it is taking care of insetting its content. If not,
2894 // we need to use the parent's content frame so that the entire
2895 // window is positioned within that content. Otherwise we can use
2896 // the display frame and let the attached window take care of
2897 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002898 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002899 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002900 } else {
2901 // If the window is resizing, then we want to base the content
2902 // frame on our attached content frame to resize... however,
2903 // things can be tricky if the attached window is NOT in resize
2904 // mode, in which case its content frame will be larger.
2905 // Ungh. So to deal with that, make sure the content frame
2906 // we end up using is not covering the IM dock.
2907 cf.set(attached.getContentFrameLw());
2908 if (attached.getSurfaceLayer() < mDockLayer) {
2909 if (cf.left < mContentLeft) cf.left = mContentLeft;
2910 if (cf.top < mContentTop) cf.top = mContentTop;
2911 if (cf.right > mContentRight) cf.right = mContentRight;
2912 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
2913 }
2914 }
2915 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002916 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002917 vf.set(attached.getVisibleFrameLw());
2918 }
2919 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
2920 // window should be positioned relative to its parent or the entire
2921 // screen.
2922 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
2923 ? attached.getFrameLw() : df);
2924 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002925
2926 private void applyStableConstraints(int sysui, int fl, Rect r) {
2927 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2928 // If app is requesting a stable layout, don't let the
2929 // content insets go below the stable values.
2930 if ((fl & FLAG_FULLSCREEN) != 0) {
2931 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
2932 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
2933 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
2934 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
2935 } else {
2936 if (r.left < mStableLeft) r.left = mStableLeft;
2937 if (r.top < mStableTop) r.top = mStableTop;
2938 if (r.right > mStableRight) r.right = mStableRight;
2939 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
2940 }
2941 }
2942 }
2943
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002944 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002945 @Override
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07002946 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
2947 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002948 // we've already done the status bar
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002949 if (win == mStatusBar || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002950 return;
2951 }
Craig Mautner69b08182012-09-05 13:07:13 -07002952 final boolean isDefaultDisplay = win.isDefaultDisplay();
2953 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09002954 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
2955 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07002956 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09002957 offsetInputMethodWindowLw(mLastInputMethodWindow);
2958 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002959
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002960 final int fl = attrs.flags;
2961 final int sim = attrs.softInputMode;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002962 final int sysUiFl = win.getSystemUiVisibility();
2963
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002964 final Rect pf = mTmpParentFrame;
2965 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002966 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002967 final Rect cf = mTmpContentFrame;
2968 final Rect vf = mTmpVisibleFrame;
Craig Mautner69b08182012-09-05 13:07:13 -07002969
2970 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04002971 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002972
Craig Mautnerf683b562012-10-02 11:10:57 -07002973 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
2974
Craig Mautner69b08182012-09-05 13:07:13 -07002975 if (!isDefaultDisplay) {
2976 if (attached != null) {
2977 // If this window is attached to another, our display
2978 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002979 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002980 } else {
2981 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002982 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
2983 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
2984 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08002985 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002986 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002987 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07002988 }
2989 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002990 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
2991 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
2992 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockd4e65752013-08-28 14:17:09 -04002993 // IM dock windows always go above the nav bar.
2994 pf.bottom = df.bottom = of.bottom = cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002995 // IM dock windows always go to the bottom of the screen.
2996 attrs.gravity = Gravity.BOTTOM;
2997 mDockLayer = win.getSurfaceLayer();
2998 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002999 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3000 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Craig Mautnereda67292013-04-28 13:50:14 -07003001 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003002 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003003 // This is the case for a normal activity window: we want it
3004 // to cover all of the screen space, and it can take care of
3005 // moving its contents to account for screen decorations that
3006 // intrude into that space.
3007 if (attached != null) {
3008 // If this window is attached to another, our display
3009 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003010 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003011 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003012 if (attrs.type == TYPE_STATUS_BAR_PANEL
3013 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003014 // Status bar panels are the only windows who can go on top of
3015 // the status bar. They are protected by the STATUS_BAR_SERVICE
3016 // permission, so they have the same privileges as the status
3017 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003018 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003019 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003020
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003021 pf.left = df.left = of.left = hasNavBar
3022 ? mDockLeft : mUnrestrictedScreenLeft;
3023 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3024 pf.right = df.right = of.right = hasNavBar
3025 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3026 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3027 pf.bottom = df.bottom = of.bottom = hasNavBar
3028 ? mRestrictedScreenTop+mRestrictedScreenHeight
3029 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003030
Craig Mautnereda67292013-04-28 13:50:14 -07003031 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003032 "Laying out status bar window: (%d,%d - %d,%d)",
3033 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackbornc652de82013-02-15 16:32:56 -08003034 } else if ((attrs.flags&FLAG_LAYOUT_IN_OVERSCAN) != 0
3035 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3036 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3037 // Asking to layout into the overscan region, so give it that pure
3038 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003039 pf.left = df.left = of.left = mOverscanScreenLeft;
3040 pf.top = df.top = of.top = mOverscanScreenTop;
3041 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3042 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3043 + mOverscanScreenHeight;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003044 } else if (mCanHideNavigationBar
3045 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003046 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3047 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3048 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003049 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003050 // only do this for application windows to ensure no window that
3051 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003052 pf.left = df.left = mOverscanScreenLeft;
3053 pf.top = df.top = mOverscanScreenTop;
3054 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3055 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003056 // We need to tell the app about where the frame inside the overscan
3057 // is, so it can inset its content by that amount -- it didn't ask
3058 // to actually extend itself into the overscan region.
3059 of.left = mUnrestrictedScreenLeft;
3060 of.top = mUnrestrictedScreenTop;
3061 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3062 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003063 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003064 pf.left = df.left = mRestrictedOverscanScreenLeft;
3065 pf.top = df.top = mRestrictedOverscanScreenTop;
3066 pf.right = df.right = mRestrictedOverscanScreenLeft
3067 + mRestrictedOverscanScreenWidth;
3068 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3069 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003070 // We need to tell the app about where the frame inside the overscan
3071 // is, so it can inset its content by that amount -- it didn't ask
3072 // to actually extend itself into the overscan region.
3073 of.left = mUnrestrictedScreenLeft;
3074 of.top = mUnrestrictedScreenTop;
3075 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3076 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003077 }
Craig Mautner69b08182012-09-05 13:07:13 -07003078
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003079 if ((attrs.flags&FLAG_FULLSCREEN) == 0) {
3080 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3081 cf.left = mDockLeft;
3082 cf.top = mDockTop;
3083 cf.right = mDockRight;
3084 cf.bottom = mDockBottom;
3085 } else {
3086 cf.left = mContentLeft;
3087 cf.top = mContentTop;
3088 cf.right = mContentRight;
3089 cf.bottom = mContentBottom;
3090 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003091 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003092 // Full screen windows are always given a layout that is as if the
3093 // status bar and other transient decors are gone. This is to avoid
3094 // bad states when moving from a window that is not hding the
3095 // status bar to one that is.
3096 cf.left = mRestrictedScreenLeft;
3097 cf.top = mRestrictedScreenTop;
3098 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3099 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003100 }
Craig Mautner69b08182012-09-05 13:07:13 -07003101
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003102 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003103 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3104 vf.left = mCurLeft;
3105 vf.top = mCurTop;
3106 vf.right = mCurRight;
3107 vf.bottom = mCurBottom;
3108 } else {
3109 vf.set(cf);
3110 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003111 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003112 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3113 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3114 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003115 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3116 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003117 // A window that has requested to fill the entire screen just
3118 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003119 if (attrs.type == TYPE_STATUS_BAR_PANEL
3120 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003121 pf.left = df.left = of.left = cf.left = hasNavBar
3122 ? mDockLeft : mUnrestrictedScreenLeft;
3123 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3124 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003125 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003126 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003127 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003128 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003129 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003130 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003131 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3132 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003133 } else if (attrs.type == TYPE_NAVIGATION_BAR
3134 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003135 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003136 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3137 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3138 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3139 + mUnrestrictedScreenWidth;
3140 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3141 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003142 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003143 "Laying out navigation bar window: (%d,%d - %d,%d)",
3144 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003145 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3146 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003147 && ((fl & FLAG_FULLSCREEN) != 0)) {
3148 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003149 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3150 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3151 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3152 + mOverscanScreenWidth;
3153 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3154 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003155 } else if (attrs.type == TYPE_BOOT_PROGRESS
3156 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003157 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003158 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3159 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3160 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3161 + mOverscanScreenWidth;
3162 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3163 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003164 } else if (attrs.type == TYPE_WALLPAPER) {
3165 // The wallpaper also has Real Ultimate Power.
3166 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3167 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003168 pf.right = df.right = of.right = cf.right
John Spurlockef4adae2013-08-26 17:58:58 -04003169 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003170 pf.bottom = df.bottom = of.bottom = cf.bottom
John Spurlockef4adae2013-08-26 17:58:58 -04003171 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003172 } else if ((attrs.flags & FLAG_LAYOUT_IN_OVERSCAN) != 0
3173 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3174 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3175 // Asking to layout into the overscan region, so give it that pure
3176 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003177 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3178 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3179 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003180 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003181 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003182 = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003183 } else if (mCanHideNavigationBar
3184 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
John Spurlock34e13d92013-08-10 06:52:28 -04003185 && (attrs.type == TYPE_TOAST
3186 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3187 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003188 // Asking for layout as if the nav bar is hidden, lets the
3189 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003190 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003191 // can be above the nav bar can do this.
3192 // XXX This assumes that an app asking for this will also
3193 // ask for layout in only content. We can't currently figure out
3194 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003195 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3196 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3197 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3198 + mUnrestrictedScreenWidth;
3199 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3200 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003201 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003202 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3203 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3204 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3205 + mRestrictedScreenWidth;
3206 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3207 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003208 }
Craig Mautner69b08182012-09-05 13:07:13 -07003209
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003210 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003211
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003212 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3213 vf.left = mCurLeft;
3214 vf.top = mCurTop;
3215 vf.right = mCurRight;
3216 vf.bottom = mCurBottom;
3217 } else {
3218 vf.set(cf);
3219 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003220 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003221 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3222 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003223 // A child window should be placed inside of the same visible
3224 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003225 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003226 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003227 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3228 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003229 // Otherwise, a normal window must be placed inside the content
3230 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003231 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3232 // Status bar panels are the only windows who can go on top of
3233 // the status bar. They are protected by the STATUS_BAR_SERVICE
3234 // permission, so they have the same privileges as the status
3235 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003236 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3237 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3238 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3239 + mRestrictedScreenWidth;
3240 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3241 + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003242 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003243 pf.left = mContentLeft;
3244 pf.top = mContentTop;
3245 pf.right = mContentRight;
3246 pf.bottom = mContentBottom;
3247 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003248 df.left = of.left = cf.left = mDockLeft;
3249 df.top = of.top = cf.top = mDockTop;
3250 df.right = of.right = cf.right = mDockRight;
3251 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003252 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003253 df.left = of.left = cf.left = mContentLeft;
3254 df.top = of.top = cf.top = mContentTop;
3255 df.right = of.right = cf.right = mContentRight;
3256 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003257 }
3258 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3259 vf.left = mCurLeft;
3260 vf.top = mCurTop;
3261 vf.right = mCurRight;
3262 vf.bottom = mCurBottom;
3263 } else {
3264 vf.set(cf);
3265 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003266 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003267 }
3268 }
Craig Mautner69b08182012-09-05 13:07:13 -07003269
Craig Mautnerb816bed2013-07-23 10:26:17 -07003270 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3271 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003272 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3273 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3274 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003275 }
3276
Craig Mautnereda67292013-04-28 13:50:14 -07003277 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003278 + ": sim=#" + Integer.toHexString(sim)
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003279 + " attach=" + attached + " type=" + attrs.type
3280 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003281 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003282 + " of=" + of.toShortString()
The Android Open Source Project11267662009-03-18 17:39:47 -07003283 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003284
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003285 win.computeFrameLw(pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003286
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003287 // Dock windows carve out the bottom of the screen, so normal windows
3288 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003289 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3290 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003291 setLastInputMethodWindowLw(null, null);
3292 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003293 }
3294 }
3295
satok1bc0a492012-04-25 22:47:12 +09003296 private void offsetInputMethodWindowLw(WindowState win) {
3297 int top = win.getContentFrameLw().top;
3298 top += win.getGivenContentInsetsLw().top;
3299 if (mContentBottom > top) {
3300 mContentBottom = top;
3301 }
3302 top = win.getVisibleFrameLw().top;
3303 top += win.getGivenVisibleInsetsLw().top;
3304 if (mCurBottom > top) {
3305 mCurBottom = top;
3306 }
Craig Mautnereda67292013-04-28 13:50:14 -07003307 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003308 + mDockBottom + " mContentBottom="
3309 + mContentBottom + " mCurBottom=" + mCurBottom);
3310 }
3311
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003312 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003313 @Override
3314 public void finishLayoutLw() {
3315 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003316 }
3317
3318 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003319 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003320 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003321 mTopFullscreenOpaqueWindowState = null;
3322 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003323 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003324 mForcingShowNavBar = false;
3325 mForcingShowNavBarLayer = -1;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003326
3327 mHideLockScreen = false;
3328 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003329 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003330 mShowingLockscreen = false;
3331 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003332 }
3333
3334 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003335 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003336 public void applyPostLayoutPolicyLw(WindowState win,
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003337 WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003338 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3339 + win.isVisibleOrBehindKeyguardLw());
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003340 if (mTopFullscreenOpaqueWindowState == null && (win.getAttrs().privateFlags
John Spurlock9e7884a2013-09-05 09:37:56 -04003341 &WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_SHOW_NAV_BAR) != 0
3342 || (win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD)) {
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003343 if (mForcingShowNavBarLayer < 0) {
3344 mForcingShowNavBar = true;
3345 mForcingShowNavBarLayer = win.getSurfaceLayer();
3346 }
3347 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003348 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003349 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003350 if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003351 if (attrs.type == TYPE_KEYGUARD) {
3352 mForceStatusBarFromKeyguard = true;
3353 } else {
3354 mForceStatusBar = true;
3355 }
3356 }
3357 if (attrs.type == TYPE_KEYGUARD) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003358 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003359 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003360 boolean applyWindow = attrs.type >= FIRST_APPLICATION_WINDOW
3361 && attrs.type <= LAST_APPLICATION_WINDOW;
3362 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003363 // If the lockscreen was showing when the dream started then wait
3364 // for the dream to draw before hiding the lockscreen.
3365 if (!mDreamingLockscreen
3366 || (win.isVisibleLw() && win.hasDrawnLw())) {
3367 mShowingDream = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003368 applyWindow = true;
3369 }
3370 }
3371 if (applyWindow
Dianne Hackborn6493e642010-10-01 13:06:30 -07003372 && attrs.x == 0 && attrs.y == 0
3373 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3374 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
Craig Mautnereda67292013-04-28 13:50:14 -07003375 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003376 mTopFullscreenOpaqueWindowState = win;
3377 if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003378 if (DEBUG_LAYOUT) Slog.v(TAG, "Setting mHideLockScreen to true by win " + win);
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003379 mHideLockScreen = true;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003380 mForceStatusBarFromKeyguard = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003381 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003382 if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0
3383 && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautnereda67292013-04-28 13:50:14 -07003384 if (DEBUG_LAYOUT) Slog.v(TAG, "Setting mDismissKeyguard true by win " + win);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003385 mDismissKeyguard = mWinDismissingKeyguard == win ?
3386 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3387 mWinDismissingKeyguard = win;
Craig Mautnereda67292013-04-28 13:50:14 -07003388 mForceStatusBarFromKeyguard = mShowingLockscreen && isKeyguardSecure();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003389 }
3390 if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
3391 mAllowLockscreenWhenOn = true;
3392 }
3393 }
3394 }
3395 }
3396
3397 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003398 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003399 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003400 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003401 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003402
3403 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3404 ? mTopFullscreenOpaqueWindowState.getAttrs()
3405 : null;
3406
Jeff Brownc8018eb2012-10-29 21:33:27 -07003407 // If we are not currently showing a dream then remember the current
3408 // lockscreen state. We will use this to determine whether the dream
3409 // started while the lockscreen was showing and remember this state
3410 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003411 if (!mShowingDream) {
3412 mDreamingLockscreen = mShowingLockscreen;
3413 }
3414
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003415 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003416 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003417 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003418 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003419 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003420 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003421 if (mStatusBarController.setBarShowingLw(true)) {
3422 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3423 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003424 } else if (mTopFullscreenOpaqueWindowState != null) {
Joe Onorato93056472010-09-10 10:30:46 -04003425 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003426 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003427 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003428 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
Joe Onorato93056472010-09-10 10:30:46 -04003429 + " lp.flags=0x" + Integer.toHexString(lp.flags));
3430 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003431 topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
3432 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003433 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3434 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3435 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3436 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003437 if (mStatusBarController.isTransientShowing()) {
3438 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003439 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3440 }
3441 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003442 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003443 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003444 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003445 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003446 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003447 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003448 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003449 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003450 if (mStatusBarController.setBarShowingLw(true)) {
3451 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3452 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003453 }
3454 }
3455 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003456
Joe Onorato644f9c32011-01-25 12:06:23 -08003457 mTopIsFullscreen = topIsFullscreen;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003458
Craig Mautner39834192012-09-02 07:47:24 -07003459 // Hide the key guard if a visible window explicitly specifies that it wants to be
3460 // displayed when the screen is locked.
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003461 if (mKeyguard != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003462 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
Craig Mautner39834192012-09-02 07:47:24 -07003463 + mHideLockScreen);
Jim Miller5ecd8112013-01-09 18:50:26 -08003464 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardDelegate.isSecure()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003465 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003466 changes |= FINISH_LAYOUT_REDO_LAYOUT
3467 | FINISH_LAYOUT_REDO_CONFIG
3468 | FINISH_LAYOUT_REDO_WALLPAPER;
3469 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003470 if (mKeyguardDelegate.isShowing()) {
Dianne Hackbornb446e972009-09-20 15:23:25 -07003471 mHandler.post(new Runnable() {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003472 @Override
Dianne Hackbornb446e972009-09-20 15:23:25 -07003473 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08003474 mKeyguardDelegate.keyguardDone(false, false);
Dianne Hackbornb446e972009-09-20 15:23:25 -07003475 }
3476 });
3477 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003478 } else if (mHideLockScreen) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003479 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003480 changes |= FINISH_LAYOUT_REDO_LAYOUT
3481 | FINISH_LAYOUT_REDO_CONFIG
3482 | FINISH_LAYOUT_REDO_WALLPAPER;
3483 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003484 mKeyguardDelegate.setHidden(true);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003485 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3486 // This is the case of keyguard isSecure() and not mHideLockScreen.
3487 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3488 // Only launch the next keyguard unlock window once per window.
3489 if (mKeyguard.showLw(true)) {
3490 changes |= FINISH_LAYOUT_REDO_LAYOUT
3491 | FINISH_LAYOUT_REDO_CONFIG
3492 | FINISH_LAYOUT_REDO_WALLPAPER;
3493 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003494 mKeyguardDelegate.setHidden(false);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003495 mHandler.post(new Runnable() {
3496 @Override
3497 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08003498 mKeyguardDelegate.dismiss();
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003499 }
3500 });
3501 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003502 } else {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003503 mWinDismissingKeyguard = null;
Dianne Hackborn08743722009-12-21 12:16:51 -08003504 if (mKeyguard.showLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003505 changes |= FINISH_LAYOUT_REDO_LAYOUT
3506 | FINISH_LAYOUT_REDO_CONFIG
3507 | FINISH_LAYOUT_REDO_WALLPAPER;
3508 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003509 mKeyguardDelegate.setHidden(false);
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003510 }
3511 }
Joe Onorato664644d2011-01-23 17:53:23 -08003512
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003513 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003514 // If the navigation bar has been hidden or shown, we need to do another
3515 // layout pass to update that window.
3516 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3517 }
Joe Onorato664644d2011-01-23 17:53:23 -08003518
Mike Lockwood28569302010-01-28 11:54:40 -05003519 // update since mAllowLockscreenWhenOn might have changed
3520 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003521 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003522 }
3523
Dianne Hackborn08743722009-12-21 12:16:51 -08003524 public boolean allowAppAnimationsLw() {
Craig Mautnerf03e4c52012-06-14 14:11:27 -07003525 if (mKeyguard != null && mKeyguard.isVisibleLw() && !mKeyguard.isAnimatingLw()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003526 // If keyguard is currently visible, no reason to animate
3527 // behind it.
3528 return false;
3529 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003530 return true;
3531 }
3532
Dianne Hackborndf89e652011-10-06 22:35:11 -07003533 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003534 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003535 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003536 // If the navigation bar has been hidden or shown, we need to do another
3537 // layout pass to update that window.
3538 return FINISH_LAYOUT_REDO_LAYOUT;
3539 }
3540 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003541 }
3542
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003543 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07003544 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003545 // do nothing if headless
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003546 if (mHeadless) return;
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003547
Jeff Brown46b9ac02010-04-22 18:58:52 -07003548 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003549 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3550 if (newLidState == mLidState) {
3551 return;
3552 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003553
Jeff Brownc458ce92012-04-30 14:58:40 -07003554 mLidState = newLidState;
3555 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003556 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003557
3558 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07003559 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07003560 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003561 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003562 }
3563 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003564
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003565 void setHdmiPlugged(boolean plugged) {
3566 if (mHdmiPlugged != plugged) {
3567 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003568 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003569 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003570 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003571 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003572 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003573 }
3574 }
3575
Joe Onoratoea495d42011-04-06 11:41:11 -07003576 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003577 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003578 // watch for HDMI plug messages if the hdmi switch exists
3579 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3580 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3581
Joe Onoratoea495d42011-04-06 11:41:11 -07003582 final String filename = "/sys/class/switch/hdmi/state";
3583 FileReader reader = null;
3584 try {
3585 reader = new FileReader(filename);
3586 char[] buf = new char[15];
3587 int n = reader.read(buf);
3588 if (n > 1) {
3589 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3590 }
3591 } catch (IOException ex) {
3592 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3593 } catch (NumberFormatException ex) {
3594 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3595 } finally {
3596 if (reader != null) {
3597 try {
3598 reader.close();
3599 } catch (IOException ex) {
3600 }
Joe Onoratodc100302011-01-11 17:07:41 -08003601 }
3602 }
3603 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07003604 // This dance forces the code in setHdmiPlugged to run.
3605 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
3606 mHdmiPlugged = !plugged;
3607 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08003608 }
3609
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003610 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003611 * @return Whether music is being played right now.
3612 */
3613 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07003614 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
3615 if (am == null) {
3616 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003617 return false;
3618 }
Eric Laurent413cb9d2009-07-17 11:52:43 -07003619 return am.isMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003620 }
3621
3622 /**
3623 * Tell the audio service to adjust the volume appropriate to the event.
3624 * @param keycode
3625 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04003626 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07003627 IAudioService audioService = getAudioService();
3628 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003629 return;
3630 }
3631 try {
3632 // since audio is playing, we shouldn't have to hold a wake lock
3633 // during the call, but we do it as a precaution for the rare possibility
3634 // that the music stops right before we call this
Jeff Brownb0418da2010-11-01 15:24:01 -07003635 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003636 mBroadcastWakeLock.acquire();
Jeff Brown4d396052010-10-29 21:50:21 -07003637 audioService.adjustStreamVolume(stream,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003638 keycode == KeyEvent.KEYCODE_VOLUME_UP
3639 ? AudioManager.ADJUST_RAISE
3640 : AudioManager.ADJUST_LOWER,
Dianne Hackbornba50b97c2013-04-30 15:04:46 -07003641 0,
Dianne Hackborn95d78532013-09-11 09:51:14 -07003642 mContext.getOpPackageName());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003643 } catch (RemoteException e) {
3644 Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e);
3645 } finally {
3646 mBroadcastWakeLock.release();
3647 }
3648 }
Jeff Brown4d396052010-10-29 21:50:21 -07003649
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07003650 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003651 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003652
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003653 final Runnable mScreenshotTimeout = new Runnable() {
3654 @Override public void run() {
3655 synchronized (mScreenshotLock) {
3656 if (mScreenshotConnection != null) {
3657 mContext.unbindService(mScreenshotConnection);
3658 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003659 }
Winson Chung9112ec32011-06-27 13:15:32 -07003660 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003661 }
3662 };
3663
3664 // Assume this is called from the Handler thread.
3665 private void takeScreenshot() {
3666 synchronized (mScreenshotLock) {
3667 if (mScreenshotConnection != null) {
3668 return;
3669 }
3670 ComponentName cn = new ComponentName("com.android.systemui",
3671 "com.android.systemui.screenshot.TakeScreenshotService");
3672 Intent intent = new Intent();
3673 intent.setComponent(cn);
3674 ServiceConnection conn = new ServiceConnection() {
3675 @Override
3676 public void onServiceConnected(ComponentName name, IBinder service) {
3677 synchronized (mScreenshotLock) {
3678 if (mScreenshotConnection != this) {
3679 return;
3680 }
3681 Messenger messenger = new Messenger(service);
3682 Message msg = Message.obtain(null, 1);
3683 final ServiceConnection myConn = this;
3684 Handler h = new Handler(mHandler.getLooper()) {
3685 @Override
3686 public void handleMessage(Message msg) {
3687 synchronized (mScreenshotLock) {
3688 if (mScreenshotConnection == myConn) {
3689 mContext.unbindService(mScreenshotConnection);
3690 mScreenshotConnection = null;
3691 mHandler.removeCallbacks(mScreenshotTimeout);
3692 }
3693 }
3694 }
3695 };
3696 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07003697 msg.arg1 = msg.arg2 = 0;
3698 if (mStatusBar != null && mStatusBar.isVisibleLw())
3699 msg.arg1 = 1;
3700 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
3701 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003702 try {
3703 messenger.send(msg);
3704 } catch (RemoteException e) {
3705 }
3706 }
3707 }
3708 @Override
3709 public void onServiceDisconnected(ComponentName name) {}
3710 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08003711 if (mContext.bindServiceAsUser(
3712 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003713 mScreenshotConnection = conn;
3714 mHandler.postDelayed(mScreenshotTimeout, 10000);
3715 }
3716 }
Winson Chung9112ec32011-06-27 13:15:32 -07003717 }
3718
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003719 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003720 @Override
Jeff Brown1f245102010-11-18 20:53:46 -08003721 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
Jeff Brown96307042012-07-27 15:51:34 -07003722 if (!mSystemBooted) {
3723 // If we have not yet booted, don't let key events do anything.
3724 return 0;
3725 }
3726
Jeff Brown1f245102010-11-18 20:53:46 -08003727 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3728 final boolean canceled = event.isCanceled();
3729 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07003730
Jeff Brown3122e442010-10-11 23:32:49 -07003731 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07003732
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05003733 // If screen is off then we treat the case where the keyguard is open but hidden
3734 // the same as if it were open and in front.
3735 // This will prevent any keys other than the power button from waking the screen
3736 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08003737 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003738 (isScreenOn ?
Jim Miller5ecd8112013-01-09 18:50:26 -08003739 mKeyguardDelegate.isShowingAndNotHidden() :
3740 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003741
Jeff Brown96307042012-07-27 15:51:34 -07003742 if (keyCode == KeyEvent.KEYCODE_POWER) {
3743 policyFlags |= WindowManagerPolicy.FLAG_WAKE;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003744 }
Jeff Brown96307042012-07-27 15:51:34 -07003745 final boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE
3746 | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003747
Jeff Brown40013652012-05-16 21:22:36 -07003748 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003749 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown96307042012-07-27 15:51:34 -07003750 + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive
3751 + " policyFlags=" + Integer.toHexString(policyFlags)
3752 + " isWakeKey=" + isWakeKey);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003753 }
3754
Jeff Brown98392ef2011-09-12 18:24:59 -07003755 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
3756 && event.getRepeatCount() == 0) {
Jeff Brown4d396052010-10-29 21:50:21 -07003757 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
3758 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003759
Jeff Brown4d396052010-10-29 21:50:21 -07003760 // Basic policy based on screen state and keyguard.
3761 // FIXME: This policy isn't quite correct. We shouldn't care whether the screen
3762 // is on or off, really. We should care about whether the device is in an
3763 // interactive state or is in suspend pretending to be "off".
3764 // The primary screen might be turned off due to proximity sensor or
3765 // because we are presenting media on an auxiliary screen or remotely controlling
3766 // the device some other way (which is why we have an exemption here for injected
3767 // events).
3768 int result;
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003769 if ((isScreenOn && !mHeadless) || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003770 // When the screen is on or if the key is injected pass the key to the application.
3771 result = ACTION_PASS_TO_USER;
3772 } else {
3773 // When the screen is off and the key is not injected, determine whether
3774 // to wake the device but don't pass the key to the application.
3775 result = 0;
Jeff Brown1c2e4942012-11-06 16:32:01 -08003776 if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07003777 result |= ACTION_WAKE_UP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003778 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003779 }
3780
Justin Kohd378ad72013-04-01 12:18:26 -07003781 // If the key would be handled globally, just return the result, don't worry about special
3782 // key processing.
3783 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
3784 return result;
3785 }
3786
Jeff Brown4d396052010-10-29 21:50:21 -07003787 // Handle special keys.
3788 switch (keyCode) {
3789 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07003790 case KeyEvent.KEYCODE_VOLUME_UP:
3791 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003792 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
3793 if (down) {
3794 if (isScreenOn && !mVolumeDownKeyTriggered
3795 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3796 mVolumeDownKeyTriggered = true;
3797 mVolumeDownKeyTime = event.getDownTime();
3798 mVolumeDownKeyConsumedByScreenshotChord = false;
3799 cancelPendingPowerKeyAction();
3800 interceptScreenshotChord();
3801 }
3802 } else {
3803 mVolumeDownKeyTriggered = false;
3804 cancelPendingScreenshotChordAction();
3805 }
3806 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
3807 if (down) {
3808 if (isScreenOn && !mVolumeUpKeyTriggered
3809 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3810 mVolumeUpKeyTriggered = true;
3811 cancelPendingPowerKeyAction();
3812 cancelPendingScreenshotChordAction();
3813 }
3814 } else {
3815 mVolumeUpKeyTriggered = false;
3816 cancelPendingScreenshotChordAction();
3817 }
3818 }
Jeff Brown4d396052010-10-29 21:50:21 -07003819 if (down) {
3820 ITelephony telephonyService = getTelephonyService();
3821 if (telephonyService != null) {
3822 try {
3823 if (telephonyService.isRinging()) {
3824 // If an incoming call is ringing, either VOLUME key means
3825 // "silence ringer". We handle these keys here, rather than
3826 // in the InCallScreen, to make sure we'll respond to them
3827 // even if the InCallScreen hasn't come to the foreground yet.
3828 // Look for the DOWN event here, to agree with the "fallback"
3829 // behavior in the InCallScreen.
3830 Log.i(TAG, "interceptKeyBeforeQueueing:"
3831 + " VOLUME key-down while ringing: Silence ringer!");
3832
3833 // Silence the ringer. (It's safe to call this
3834 // even if the ringer has already been silenced.)
3835 telephonyService.silenceRinger();
3836
3837 // And *don't* pass this key thru to the current activity
3838 // (which is probably the InCallScreen.)
3839 result &= ~ACTION_PASS_TO_USER;
3840 break;
3841 }
3842 if (telephonyService.isOffhook()
3843 && (result & ACTION_PASS_TO_USER) == 0) {
3844 // If we are in call but we decided not to pass the key to
3845 // the application, handle the volume change here.
3846 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
3847 break;
3848 }
3849 } catch (RemoteException ex) {
3850 Log.w(TAG, "ITelephony threw RemoteException", ex);
3851 }
3852 }
3853
3854 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
3855 // If music is playing but we decided not to pass the key to the
3856 // application, handle the volume change here.
3857 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
3858 break;
3859 }
3860 }
3861 break;
3862 }
3863
3864 case KeyEvent.KEYCODE_ENDCALL: {
3865 result &= ~ACTION_PASS_TO_USER;
3866 if (down) {
3867 ITelephony telephonyService = getTelephonyService();
3868 boolean hungUp = false;
3869 if (telephonyService != null) {
3870 try {
3871 hungUp = telephonyService.endCall();
3872 } catch (RemoteException ex) {
3873 Log.w(TAG, "ITelephony threw RemoteException", ex);
3874 }
3875 }
3876 interceptPowerKeyDown(!isScreenOn || hungUp);
3877 } else {
3878 if (interceptPowerKeyUp(canceled)) {
3879 if ((mEndcallBehavior
3880 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
3881 if (goHome()) {
3882 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07003883 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003884 }
Jeff Brown4d396052010-10-29 21:50:21 -07003885 if ((mEndcallBehavior
3886 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown96307042012-07-27 15:51:34 -07003887 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
Jeff Brown4d396052010-10-29 21:50:21 -07003888 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003889 }
Jeff Brown4d396052010-10-29 21:50:21 -07003890 }
3891 break;
3892 }
3893
3894 case KeyEvent.KEYCODE_POWER: {
3895 result &= ~ACTION_PASS_TO_USER;
3896 if (down) {
John Spurlockd67ec252013-09-05 11:31:54 -04003897 mTransientNavigationConfirmation.onPowerKeyDown(isScreenOn, event.getDownTime(),
3898 isTransientNavigationAllowed(mLastSystemUiFlags));
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003899 if (isScreenOn && !mPowerKeyTriggered
3900 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3901 mPowerKeyTriggered = true;
3902 mPowerKeyTime = event.getDownTime();
3903 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07003904 }
Winson Chung9112ec32011-06-27 13:15:32 -07003905
Jeff Brown4d396052010-10-29 21:50:21 -07003906 ITelephony telephonyService = getTelephonyService();
3907 boolean hungUp = false;
3908 if (telephonyService != null) {
3909 try {
3910 if (telephonyService.isRinging()) {
3911 // Pressing Power while there's a ringing incoming
3912 // call should silence the ringer.
3913 telephonyService.silenceRinger();
3914 } else if ((mIncallPowerBehavior
3915 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
3916 && telephonyService.isOffhook()) {
3917 // Otherwise, if "Power button ends call" is enabled,
3918 // the Power button will hang up any current active call.
3919 hungUp = telephonyService.endCall();
3920 }
3921 } catch (RemoteException ex) {
3922 Log.w(TAG, "ITelephony threw RemoteException", ex);
3923 }
3924 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003925 interceptPowerKeyDown(!isScreenOn || hungUp
3926 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003927 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003928 mPowerKeyTriggered = false;
3929 cancelPendingScreenshotChordAction();
3930 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown96307042012-07-27 15:51:34 -07003931 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003932 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003933 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07003934 }
3935 break;
3936 }
3937
3938 case KeyEvent.KEYCODE_MEDIA_PLAY:
3939 case KeyEvent.KEYCODE_MEDIA_PAUSE:
3940 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3941 if (down) {
3942 ITelephony telephonyService = getTelephonyService();
3943 if (telephonyService != null) {
3944 try {
3945 if (!telephonyService.isIdle()) {
3946 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
3947 // to avoid music playback.
3948 break;
3949 }
3950 } catch (RemoteException ex) {
3951 Log.w(TAG, "ITelephony threw RemoteException", ex);
Jeff Brown3122e442010-10-11 23:32:49 -07003952 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003953 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003954 }
Jeff Brown4d396052010-10-29 21:50:21 -07003955 case KeyEvent.KEYCODE_HEADSETHOOK:
3956 case KeyEvent.KEYCODE_MUTE:
3957 case KeyEvent.KEYCODE_MEDIA_STOP:
3958 case KeyEvent.KEYCODE_MEDIA_NEXT:
3959 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
3960 case KeyEvent.KEYCODE_MEDIA_REWIND:
3961 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09003962 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
3963 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07003964 if ((result & ACTION_PASS_TO_USER) == 0) {
3965 // Only do this if we would otherwise not pass it to the user. In that
3966 // case, the PhoneWindow class will do the same thing, except it will
3967 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07003968 // Note that we need to make a copy of the key event here because the
3969 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07003970 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07003971 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
3972 new KeyEvent(event));
3973 msg.setAsynchronous(true);
3974 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07003975 }
3976 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003977 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003978
Jeff Brown4d396052010-10-29 21:50:21 -07003979 case KeyEvent.KEYCODE_CALL: {
3980 if (down) {
3981 ITelephony telephonyService = getTelephonyService();
3982 if (telephonyService != null) {
3983 try {
3984 if (telephonyService.isRinging()) {
3985 Log.i(TAG, "interceptKeyBeforeQueueing:"
3986 + " CALL key-down while ringing: Answer the call!");
3987 telephonyService.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003988
Jeff Brown4d396052010-10-29 21:50:21 -07003989 // And *don't* pass this key thru to the current activity
3990 // (which is presumably the InCallScreen.)
3991 result &= ~ACTION_PASS_TO_USER;
3992 }
3993 } catch (RemoteException ex) {
3994 Log.w(TAG, "ITelephony threw RemoteException", ex);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003995 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003996 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003997 }
Jeff Brown4d396052010-10-29 21:50:21 -07003998 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003999 }
4000 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004001 return result;
4002 }
4003
Jeff Brown1c2e4942012-11-06 16:32:01 -08004004 /**
4005 * When the screen is off we ignore some keys that might otherwise typically
4006 * be considered wake keys. We filter them out here.
4007 *
4008 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4009 * is always considered a wake key.
4010 */
4011 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4012 switch (keyCode) {
4013 // ignore volume keys unless docked
4014 case KeyEvent.KEYCODE_VOLUME_UP:
4015 case KeyEvent.KEYCODE_VOLUME_DOWN:
4016 case KeyEvent.KEYCODE_VOLUME_MUTE:
4017 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4018
4019 // ignore media and camera keys
4020 case KeyEvent.KEYCODE_MUTE:
4021 case KeyEvent.KEYCODE_HEADSETHOOK:
4022 case KeyEvent.KEYCODE_MEDIA_PLAY:
4023 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4024 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4025 case KeyEvent.KEYCODE_MEDIA_STOP:
4026 case KeyEvent.KEYCODE_MEDIA_NEXT:
4027 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4028 case KeyEvent.KEYCODE_MEDIA_REWIND:
4029 case KeyEvent.KEYCODE_MEDIA_RECORD:
4030 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004031 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004032 case KeyEvent.KEYCODE_CAMERA:
4033 return false;
4034 }
4035 return true;
4036 }
4037
4038
Jeff Brown56194eb2011-03-02 19:23:13 -08004039 /** {@inheritDoc} */
4040 @Override
4041 public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
4042 int result = 0;
4043
4044 final boolean isWakeMotion = (policyFlags
4045 & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
4046 if (isWakeMotion) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07004047 result |= ACTION_WAKE_UP;
Jeff Brown56194eb2011-03-02 19:23:13 -08004048 }
4049 return result;
4050 }
4051
Jeff Brown40013652012-05-16 21:22:36 -07004052 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4053 if (DEBUG_INPUT) {
4054 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004055 }
4056
Jeff Brown40013652012-05-16 21:22:36 -07004057 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4058 if (DEBUG_INPUT) {
4059 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4060 }
4061
4062 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4063 mHavePendingMediaKeyRepeatWithWakeLock = false;
4064 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4065 }
4066
4067 dispatchMediaKeyWithWakeLockToAudioService(event);
4068
4069 if (event.getAction() == KeyEvent.ACTION_DOWN
4070 && event.getRepeatCount() == 0) {
4071 mHavePendingMediaKeyRepeatWithWakeLock = true;
4072
4073 Message msg = mHandler.obtainMessage(
4074 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4075 msg.setAsynchronous(true);
4076 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4077 } else {
4078 mBroadcastWakeLock.release();
4079 }
4080 }
4081
4082 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4083 mHavePendingMediaKeyRepeatWithWakeLock = false;
4084
4085 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4086 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4087 if (DEBUG_INPUT) {
4088 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4089 }
4090
4091 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4092 mBroadcastWakeLock.release();
4093 }
4094
4095 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4096 if (ActivityManagerNative.isSystemReady()) {
4097 IAudioService audioService = getAudioService();
4098 if (audioService != null) {
4099 try {
4100 audioService.dispatchMediaKeyEventUnderWakelock(event);
4101 } catch (RemoteException e) {
4102 Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
Jean-Michel Trivic6802222012-04-30 11:15:03 -07004103 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004104 }
4105 }
4106 }
4107
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004108 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004109 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004110 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004111 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4112 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4113 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004114 } else {
4115 try {
4116 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4117 ServiceManager.getService(Context.UI_MODE_SERVICE));
4118 mUiMode = uiModeService.getCurrentModeType();
4119 } catch (RemoteException e) {
4120 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004121 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004122 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004123 synchronized (mLock) {
4124 updateOrientationListenerLp();
4125 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004126 }
4127 };
4128
Jeff Brown6aaf2952012-10-05 16:01:08 -07004129 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4130 @Override
4131 public void onReceive(Context context, Intent intent) {
4132 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004133 if (mKeyguardDelegate != null) {
4134 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004135 }
4136 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004137 if (mKeyguardDelegate != null) {
4138 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004139 }
4140 }
4141 }
4142 };
4143
Christopher Tate5e08af02012-09-21 17:17:22 -07004144 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4145 @Override
4146 public void onReceive(Context context, Intent intent) {
4147 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4148 // tickle the settings observer: this first ensures that we're
4149 // observing the relevant settings for the newly-active user,
4150 // and then updates our own bookkeeping based on the now-
4151 // current user.
4152 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004153
4154 // force a re-application of focused window sysui visibility.
4155 // the window may never have been shown for this user
4156 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004157 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004158 mLastSystemUiFlags = 0;
4159 updateSystemUiVisibilityLw();
4160 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004161 }
4162 }
4163 };
4164
John Spurlocke1f366f2013-08-05 12:22:40 -04004165 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004166 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlock27735a42013-08-14 17:57:38 -04004167 boolean sb = mStatusBarController.checkShowTransientBarLw();
4168 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004169 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004170 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4171 if (sb ^ nb && barTarget != swipeTarget) {
4172 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004173 return;
4174 }
John Spurlock27735a42013-08-14 17:57:38 -04004175 if (sb) mStatusBarController.showTransient();
4176 if (nb) mNavigationBarController.showTransient();
John Spurlockd67ec252013-09-05 11:31:54 -04004177 mTransientNavigationConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004178 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004179 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004180 }
4181 }
4182
Jeff Brownc38c9be2012-10-04 13:16:19 -07004183 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004184 public void screenTurnedOff(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004185 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004186 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004187 mScreenOnEarly = false;
4188 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004189 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004190 if (mKeyguardDelegate != null) {
4191 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004192 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004193 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07004194 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004195 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004196 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004197 }
4198
Jeff Brownc38c9be2012-10-04 13:16:19 -07004199 @Override
Dianne Hackborn38e29a62011-09-18 14:43:08 -07004200 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004201 EventLog.writeEvent(70000, 1);
Dianne Hackborn40011092011-09-22 13:37:48 -07004202 if (false) {
4203 RuntimeException here = new RuntimeException("here");
4204 here.fillInStackTrace();
4205 Slog.i(TAG, "Screen turning on...", here);
4206 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004207
The Android Open Source Project0727d222009-03-11 12:11:58 -07004208 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004209 mScreenOnEarly = true;
The Android Open Source Project0727d222009-03-11 12:11:58 -07004210 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004211 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004212 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004213
Jeff Brownc38c9be2012-10-04 13:16:19 -07004214 waitForKeyguard(screenOnListener);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004215 }
4216
Jeff Brownc38c9be2012-10-04 13:16:19 -07004217 private void waitForKeyguard(final ScreenOnListener screenOnListener) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004218 if (mKeyguardDelegate != null) {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004219 if (screenOnListener != null) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004220 mKeyguardDelegate.onScreenTurnedOn(new KeyguardServiceDelegate.ShowListener() {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004221 @Override
4222 public void onShown(IBinder windowToken) {
4223 waitForKeyguardWindowDrawn(windowToken, screenOnListener);
4224 }
4225 });
4226 return;
4227 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -08004228 mKeyguardDelegate.onScreenTurnedOn(null);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004229 }
4230 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -08004231 Slog.i(TAG, "No keyguard interface!");
Jeff Brownc38c9be2012-10-04 13:16:19 -07004232 }
4233 finishScreenTurningOn(screenOnListener);
4234 }
4235
4236 private void waitForKeyguardWindowDrawn(IBinder windowToken,
4237 final ScreenOnListener screenOnListener) {
4238 if (windowToken != null) {
4239 try {
4240 if (mWindowManager.waitForWindowDrawn(
4241 windowToken, new IRemoteCallback.Stub() {
4242 @Override
4243 public void sendResult(Bundle data) {
4244 Slog.i(TAG, "Lock screen displayed!");
4245 finishScreenTurningOn(screenOnListener);
4246 }
4247 })) {
4248 return;
4249 }
4250 } catch (RemoteException ex) {
4251 // Can't happen in system process.
4252 }
4253 }
4254
4255 Slog.i(TAG, "No lock screen!");
4256 finishScreenTurningOn(screenOnListener);
4257 }
4258
4259 private void finishScreenTurningOn(ScreenOnListener screenOnListener) {
4260 synchronized (mLock) {
4261 mScreenOnFully = true;
4262 }
4263
Jeff Brown4fc45272012-10-10 18:28:14 -07004264 try {
4265 mWindowManager.setEventDispatching(true);
4266 } catch (RemoteException unhandled) {
4267 }
4268
Jeff Brownc38c9be2012-10-04 13:16:19 -07004269 if (screenOnListener != null) {
4270 screenOnListener.onScreenOn();
4271 }
4272 }
4273
4274 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004275 public boolean isScreenOnEarly() {
4276 return mScreenOnEarly;
4277 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004278
4279 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004280 public boolean isScreenOnFully() {
4281 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004282 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004283
Dianne Hackborn08743722009-12-21 12:16:51 -08004284 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004285 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004286 if (mKeyguardDelegate != null) {
4287 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004288 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004289 }
4290
4291 /** {@inheritDoc} */
4292 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004293 if (mKeyguardDelegate != null) {
4294 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004295 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004296 }
4297
Mike Lockwoodf7913302009-11-28 22:27:10 -05004298 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004299 if (mKeyguardDelegate == null) return false;
4300 return mKeyguardDelegate.isShowingAndNotHidden();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004301 }
4302
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004303
4304 /** {@inheritDoc} */
4305 public boolean isKeyguardLocked() {
4306 return keyguardOn();
4307 }
4308
4309 /** {@inheritDoc} */
4310 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004311 if (mKeyguardDelegate == null) return false;
4312 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004313 }
4314
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004315 /** {@inheritDoc} */
4316 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004317 if (mKeyguardDelegate == null) return false;
4318 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004319 }
4320
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004321 public void dismissKeyguardLw() {
Jim Miller195b5512013-02-28 03:35:57 -08004322 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004323 mHandler.post(new Runnable() {
4324 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004325 if (mKeyguardDelegate.isDismissable()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004326 // Can we just finish the keyguard straight away?
Jim Miller5ecd8112013-01-09 18:50:26 -08004327 mKeyguardDelegate.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004328 } else {
4329 // ask the keyguard to prompt the user to authenticate if necessary
Jim Miller5ecd8112013-01-09 18:50:26 -08004330 mKeyguardDelegate.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004331 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004332 }
4333 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004334 }
4335 }
4336
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004337 void sendCloseSystemWindows() {
4338 sendCloseSystemWindows(mContext, null);
4339 }
4340
4341 void sendCloseSystemWindows(String reason) {
4342 sendCloseSystemWindows(mContext, reason);
4343 }
4344
4345 static void sendCloseSystemWindows(Context context, String reason) {
4346 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004347 try {
4348 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4349 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004350 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004351 }
4352 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004353
Jeff Brown01a98dd2011-09-20 15:08:29 -07004354 @Override
4355 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004356 if (false) {
4357 Slog.v(TAG, "rotationForOrientationLw(orient="
4358 + orientation + ", last=" + lastRotation
4359 + "); user=" + mUserRotation + " "
4360 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4361 ? "USER_ROTATION_LOCKED" : "")
4362 );
4363 }
4364
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004365 if (mForceDefaultOrientation) {
4366 return Surface.ROTATION_0;
4367 }
4368
The Android Open Source Project0727d222009-03-11 12:11:58 -07004369 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004370 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4371 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004372 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004373 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004374
Jeff Browndec6cf42011-11-15 14:08:20 -08004375 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004376 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004377 // Ignore sensor when lid switch is open and rotation is forced.
4378 preferredRotation = mLidOpenRotation;
4379 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004380 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004381 // Ignore sensor when in car dock unless explicitly enabled.
4382 // This case can override the behavior of NOSENSOR, and can also
4383 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004384 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004385 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004386 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4387 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4388 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004389 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004390 // Ignore sensor when in desk dock unless explicitly enabled.
4391 // This case can override the behavior of NOSENSOR, and can also
4392 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004393 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004394 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004395 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4396 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004397 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004398 preferredRotation = mDemoHdmiRotation;
4399 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4400 && mUndockedHdmiRotation >= 0) {
4401 // Ignore sensor when plugged into HDMI and an undocked orientation has
4402 // been specified in the configuration (only for legacy devices without
4403 // full multi-display support).
4404 // Note that the dock orientation overrides the HDMI orientation.
4405 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004406 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4407 // Application just wants to remain locked in the last rotation.
4408 preferredRotation = lastRotation;
Jeff Brown207673cd2012-06-05 17:47:11 -07004409 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004410 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004411 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4412 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4413 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4414 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004415 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4416 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4417 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4418 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4419 // Otherwise, use sensor only if requested by the application or enabled
4420 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004421 if (mAllowAllRotations < 0) {
4422 // Can't read this during init() because the context doesn't
4423 // have display metrics at that time so we cannot determine
4424 // tablet vs. phone then.
4425 mAllowAllRotations = mContext.getResources().getBoolean(
4426 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4427 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004428 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004429 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004430 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4431 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004432 preferredRotation = sensorRotation;
4433 } else {
4434 preferredRotation = lastRotation;
4435 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004436 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4437 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4438 // Apply rotation lock. Does not apply to NOSENSOR.
4439 // The idea is that the user rotation expresses a weak preference for the direction
4440 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4441 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004442 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004443 } else {
4444 // No overriding preference.
4445 // We will do exactly what the application asked us to do.
4446 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004447 }
4448
Dianne Hackborne5439f22010-10-02 16:53:50 -07004449 switch (orientation) {
4450 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004451 // Return portrait unless overridden.
4452 if (isAnyPortrait(preferredRotation)) {
4453 return preferredRotation;
4454 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004455 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004456
Jeff Brown01a98dd2011-09-20 15:08:29 -07004457 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004458 // Return landscape unless overridden.
4459 if (isLandscapeOrSeascape(preferredRotation)) {
4460 return preferredRotation;
4461 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004462 return mLandscapeRotation;
4463
4464 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004465 // Return reverse portrait unless overridden.
4466 if (isAnyPortrait(preferredRotation)) {
4467 return preferredRotation;
4468 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004469 return mUpsideDownRotation;
4470
4471 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004472 // Return seascape unless overridden.
4473 if (isLandscapeOrSeascape(preferredRotation)) {
4474 return preferredRotation;
4475 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004476 return mSeascapeRotation;
4477
4478 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004479 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004480 // Return either landscape rotation.
4481 if (isLandscapeOrSeascape(preferredRotation)) {
4482 return preferredRotation;
4483 }
4484 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004485 return lastRotation;
4486 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004487 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004488
Jeff Brown01a98dd2011-09-20 15:08:29 -07004489 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004490 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004491 // Return either portrait rotation.
4492 if (isAnyPortrait(preferredRotation)) {
4493 return preferredRotation;
4494 }
4495 if (isAnyPortrait(lastRotation)) {
4496 return lastRotation;
4497 }
4498 return mPortraitRotation;
4499
4500 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004501 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4502 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004503 if (preferredRotation >= 0) {
4504 return preferredRotation;
4505 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004506 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004507 }
4508 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004509 }
4510
Jeff Brown01a98dd2011-09-20 15:08:29 -07004511 @Override
4512 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4513 switch (orientation) {
4514 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4515 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4516 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4517 return isAnyPortrait(rotation);
4518
4519 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4520 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4521 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4522 return isLandscapeOrSeascape(rotation);
4523
4524 default:
4525 return true;
4526 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004527 }
4528
Jeff Brownc0347aa2011-09-23 17:26:09 -07004529 @Override
4530 public void setRotationLw(int rotation) {
4531 mOrientationListener.setCurrentRotation(rotation);
4532 }
4533
Jeff Brown01a98dd2011-09-20 15:08:29 -07004534 private boolean isLandscapeOrSeascape(int rotation) {
4535 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004536 }
4537
Jeff Brown01a98dd2011-09-20 15:08:29 -07004538 private boolean isAnyPortrait(int rotation) {
4539 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004540 }
4541
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004542 public int getUserRotationMode() {
4543 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07004544 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
4545 WindowManagerPolicy.USER_ROTATION_FREE :
4546 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004547 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004548
4549 // User rotation: to be used when all else fails in assigning an orientation to the device
4550 public void setUserRotationMode(int mode, int rot) {
4551 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004552
4553 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004554 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004555 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004556 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004557 rot,
4558 UserHandle.USER_CURRENT);
4559 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004560 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004561 0,
4562 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004563 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004564 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004565 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004566 1,
4567 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004568 }
4569 }
4570
Jeff Brownac143512012-04-05 18:57:33 -07004571 public void setSafeMode(boolean safeMode) {
4572 mSafeMode = safeMode;
4573 performHapticFeedbackLw(null, safeMode
4574 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4575 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004576 }
Craig Mautnereda67292013-04-28 13:50:14 -07004577
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004578 static long[] getLongIntArray(Resources r, int resid) {
4579 int[] ar = r.getIntArray(resid);
4580 if (ar == null) {
4581 return null;
4582 }
4583 long[] out = new long[ar.length];
4584 for (int i=0; i<ar.length; i++) {
4585 out[i] = ar[i];
4586 }
4587 return out;
4588 }
Craig Mautnereda67292013-04-28 13:50:14 -07004589
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004590 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004591 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004592 public void systemReady() {
Jim Miller195b5512013-02-28 03:35:57 -08004593 if (!mHeadless) {
4594 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
Jim Miller5ecd8112013-01-09 18:50:26 -08004595 mKeyguardDelegate.onSystemReady();
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004596 }
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004597 synchronized (mLock) {
4598 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08004599 mSystemReady = true;
4600 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07004601 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08004602 public void run() {
4603 updateSettings();
4604 }
4605 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004606 }
4607 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07004608
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004609 /** {@inheritDoc} */
4610 public void systemBooted() {
4611 synchronized (mLock) {
4612 mSystemBooted = true;
4613 }
4614 }
4615
Dianne Hackborn661cd522011-08-22 00:26:20 -07004616 ProgressDialog mBootMsgDialog = null;
4617
4618 /** {@inheritDoc} */
4619 public void showBootMessage(final CharSequence msg, final boolean always) {
Mike Lockwoodaa5bf142011-09-21 13:03:40 -04004620 if (mHeadless) return;
Dianne Hackborn661cd522011-08-22 00:26:20 -07004621 mHandler.post(new Runnable() {
4622 @Override public void run() {
4623 if (mBootMsgDialog == null) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07004624 mBootMsgDialog = new ProgressDialog(mContext) {
4625 // This dialog will consume all events coming in to
4626 // it, to avoid it trying to do things too early in boot.
4627 @Override public boolean dispatchKeyEvent(KeyEvent event) {
4628 return true;
4629 }
4630 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
4631 return true;
4632 }
4633 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
4634 return true;
4635 }
4636 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
4637 return true;
4638 }
4639 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
4640 return true;
4641 }
4642 @Override public boolean dispatchPopulateAccessibilityEvent(
4643 AccessibilityEvent event) {
4644 return true;
4645 }
4646 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07004647 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
4648 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
4649 mBootMsgDialog.setIndeterminate(true);
4650 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004651 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004652 mBootMsgDialog.getWindow().addFlags(
4653 WindowManager.LayoutParams.FLAG_DIM_BEHIND
4654 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
4655 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08004656 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
4657 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
4658 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004659 mBootMsgDialog.setCancelable(false);
4660 mBootMsgDialog.show();
4661 }
4662 mBootMsgDialog.setMessage(msg);
4663 }
4664 });
4665 }
4666
4667 /** {@inheritDoc} */
4668 public void hideBootMessages() {
4669 mHandler.post(new Runnable() {
4670 @Override public void run() {
4671 if (mBootMsgDialog != null) {
4672 mBootMsgDialog.dismiss();
4673 mBootMsgDialog = null;
4674 }
4675 }
4676 });
4677 }
4678
Mike Lockwood28569302010-01-28 11:54:40 -05004679 /** {@inheritDoc} */
4680 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004681 // ***************************************
4682 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
4683 // ***************************************
4684 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
4685 // WITH ITS LOCKS HELD.
4686 //
4687 // This code must be VERY careful about the locks
4688 // it acquires.
4689 // In fact, the current code acquires way too many,
4690 // and probably has lurking deadlocks.
4691
Mike Lockwood28569302010-01-28 11:54:40 -05004692 synchronized (mScreenLockTimeout) {
4693 if (mLockScreenTimerActive) {
4694 // reset the timer
4695 mHandler.removeCallbacks(mScreenLockTimeout);
4696 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4697 }
4698 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04004699 }
4700
Adam Cohenf7522022012-10-03 20:03:18 -07004701 class ScreenLockTimeout implements Runnable {
4702 Bundle options;
4703
4704 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05004705 public void run() {
4706 synchronized (this) {
4707 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08004708 if (mKeyguardDelegate != null) {
4709 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004710 }
Mike Lockwood28569302010-01-28 11:54:40 -05004711 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07004712 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05004713 }
4714 }
Mike Lockwood28569302010-01-28 11:54:40 -05004715
Adam Cohenf7522022012-10-03 20:03:18 -07004716 public void setLockOptions(Bundle options) {
4717 this.options = options;
4718 }
4719 }
4720
4721 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
4722
4723 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08004724 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
4725 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07004726 if (options != null) {
4727 // In case multiple calls are made to lockNow, we don't wipe out the options
4728 // until the runnable actually executes.
4729 mScreenLockTimeout.setLockOptions(options);
4730 }
Jim Miller93c518e2012-01-17 15:55:31 -08004731 mHandler.post(mScreenLockTimeout);
4732 }
4733
Mike Lockwood28569302010-01-28 11:54:40 -05004734 private void updateLockScreenTimeout() {
4735 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004736 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08004737 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05004738 if (mLockScreenTimerActive != enable) {
4739 if (enable) {
4740 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
4741 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4742 } else {
4743 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
4744 mHandler.removeCallbacks(mScreenLockTimeout);
4745 }
4746 mLockScreenTimerActive = enable;
4747 }
4748 }
4749 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004750
4751 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004752 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004753 public void enableScreenAfterBoot() {
4754 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07004755 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004756 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004757 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07004758
Jeff Brownc458ce92012-04-30 14:58:40 -07004759 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07004760 if (mLidState == LID_CLOSED && mLidControlsSleep) {
4761 mPowerManager.goToSleep(SystemClock.uptimeMillis());
4762 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004763 }
4764
4765 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004766 try {
4767 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004768 mWindowManager.updateRotation(alwaysSendConfiguration, false);
4769 } catch (RemoteException e) {
4770 // Ignore
4771 }
4772 }
4773
4774 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
4775 try {
4776 //set orientation on WindowManager
4777 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004778 } catch (RemoteException e) {
4779 // Ignore
4780 }
4781 }
4782
Daniel Sandler6396c722013-04-16 20:19:09 -04004783 /**
4784 * Return an Intent to launch the currently active dock app as home. Returns
4785 * null if the standard home should be launched, which is the case if any of the following is
4786 * true:
4787 * <ul>
4788 * <li>The device is not in either car mode or desk mode
4789 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
4790 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
4791 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
4792 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
4793 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07004794 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04004795 */
4796 Intent createHomeDockIntent() {
4797 Intent intent = null;
4798
4799 // What home does is based on the mode, not the dock state. That
4800 // is, when in car mode you should be taken to car home regardless
4801 // of whether we are actually in a car dock.
4802 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
4803 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
4804 intent = mCarDockIntent;
4805 }
4806 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
4807 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
4808 intent = mDeskDockIntent;
4809 }
4810 }
4811
4812 if (intent == null) {
4813 return null;
4814 }
4815
4816 ActivityInfo ai = null;
4817 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
4818 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04004819 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07004820 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04004821 if (info != null) {
4822 ai = info.activityInfo;
4823 }
4824 if (ai != null
4825 && ai.metaData != null
4826 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
4827 intent = new Intent(intent);
4828 intent.setClassName(ai.packageName, ai.name);
4829 return intent;
4830 }
4831
4832 return null;
4833 }
4834
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004835 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04004836 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04004837
4838 Intent dock = createHomeDockIntent();
4839 if (dock != null) {
4840 try {
4841 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
4842 return;
4843 } catch (ActivityNotFoundException e) {
4844 }
4845 }
4846
Dianne Hackbornd8883992012-09-07 15:58:52 -07004847 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004848 }
Craig Mautnereda67292013-04-28 13:50:14 -07004849
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004850 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004851 * goes to the home screen
4852 * @return whether it did anything
4853 */
4854 boolean goHome() {
4855 if (false) {
4856 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07004857 try {
4858 ActivityManagerNative.getDefault().stopAppSwitches();
4859 } catch (RemoteException e) {
4860 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004861 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004862 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004863 } else {
4864 // This code brings home to the front or, if it is already
4865 // at the front, puts the device to sleep.
4866 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08004867 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
4868 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
4869 Log.d(TAG, "UTS-TEST-MODE");
4870 } else {
4871 ActivityManagerNative.getDefault().stopAppSwitches();
4872 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04004873 Intent dock = createHomeDockIntent();
4874 if (dock != null) {
4875 int result = ActivityManagerNative.getDefault()
4876 .startActivityAsUser(null, null, dock,
4877 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
4878 null, null, 0,
4879 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
4880 null, null, null, UserHandle.USER_CURRENT);
4881 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
4882 return false;
4883 }
4884 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004885 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004886 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004887 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004888 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07004889 null, null, 0,
4890 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004891 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07004892 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004893 return false;
4894 }
4895 } catch (RemoteException ex) {
4896 // bummer, the activity manager, which is in this process, is dead
4897 }
4898 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004899 return true;
4900 }
Craig Mautnereda67292013-04-28 13:50:14 -07004901
4902 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07004903 public void setCurrentOrientationLw(int newOrientation) {
4904 synchronized (mLock) {
4905 if (newOrientation != mCurrentAppOrientation) {
4906 mCurrentAppOrientation = newOrientation;
4907 updateOrientationListenerLp();
4908 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004909 }
4910 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004911
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07004912 private void performAuditoryFeedbackForAccessibilityIfNeed() {
4913 if (!isGlobalAccessibilityGestureEnabled()) {
4914 return;
4915 }
4916 AudioManager audioManager = (AudioManager) mContext.getSystemService(
4917 Context.AUDIO_SERVICE);
4918 if (audioManager.isSilentMode()) {
4919 return;
4920 }
4921 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
4922 Settings.System.DEFAULT_NOTIFICATION_URI);
4923 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
4924 ringTone.play();
4925 }
Craig Mautnereda67292013-04-28 13:50:14 -07004926
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07004927 private boolean isGlobalAccessibilityGestureEnabled() {
4928 return Settings.Global.getInt(mContext.getContentResolver(),
4929 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
4930 }
4931
Craig Mautnereda67292013-04-28 13:50:14 -07004932 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07004933 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07004934 if (!mVibrator.hasVibrator()) {
4935 return false;
4936 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004937 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
4938 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jim Miller5ecd8112013-01-09 18:50:26 -08004939 if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotHidden())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004940 return false;
4941 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004942 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004943 switch (effectId) {
4944 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004945 pattern = mLongPressVibePattern;
4946 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004947 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004948 pattern = mVirtualKeyVibePattern;
4949 break;
4950 case HapticFeedbackConstants.KEYBOARD_TAP:
4951 pattern = mKeyboardTapVibePattern;
4952 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07004953 case HapticFeedbackConstants.CLOCK_TICK:
4954 pattern = mClockTickVibePattern;
4955 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004956 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004957 pattern = mSafeModeDisabledVibePattern;
4958 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004959 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004960 pattern = mSafeModeEnabledVibePattern;
4961 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08004962 default:
4963 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004964 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004965 int owningUid;
4966 String owningPackage;
4967 if (win != null) {
4968 owningUid = win.getOwningUid();
4969 owningPackage = win.getOwningPackage();
4970 } else {
4971 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07004972 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004973 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004974 if (pattern.length == 1) {
4975 // One-shot vibration
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004976 mVibrator.vibrate(owningUid, owningPackage, pattern[0]);
Amith Yamasanic33cb712010-02-10 15:21:49 -08004977 } else {
4978 // Pattern vibration
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004979 mVibrator.vibrate(owningUid, owningPackage, pattern, -1);
Amith Yamasanic33cb712010-02-10 15:21:49 -08004980 }
4981 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004982 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004983
4984 @Override
4985 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04004986 }
4987
Jeff Brownc38c9be2012-10-04 13:16:19 -07004988 @Override
4989 public void keepScreenOnStoppedLw() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004990 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotHidden()) {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004991 long curTime = SystemClock.uptimeMillis();
Jim Miller25190572013-02-28 17:36:24 -08004992 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004993 }
4994 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04004995
Dianne Hackborndf89e652011-10-06 22:35:11 -07004996 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08004997 // If there is no window focused, there will be nobody to handle the events
4998 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04004999 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5000 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005001 return 0;
5002 }
John Spurlock79da8332013-09-20 12:04:47 -04005003 if (win.getAttrs().type == TYPE_KEYGUARD && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005004 // We are updating at a point where the keyguard has gotten
5005 // focus, but we were last in a state where the top window is
5006 // hiding it. This is probably because the keyguard as been
5007 // shown while the top window was displayed, so we want to ignore
5008 // it here because this is just a very transient change and it
5009 // will quickly lose focus once it correctly gets hidden.
5010 return 0;
5011 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005012
John Spurlock79da8332013-09-20 12:04:47 -04005013 int tmpVisibility = win.getSystemUiVisibility()
Dianne Hackborne26ab702011-10-16 13:21:33 -07005014 & ~mResettingSystemUiFlags
5015 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005016 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005017 tmpVisibility &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
5018 }
John Spurlock79da8332013-09-20 12:04:47 -04005019 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005020 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005021 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005022 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005023 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005024 return 0;
5025 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005026 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005027 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005028 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005029 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005030 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005031 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005032 try {
5033 IStatusBarService statusbar = getStatusBarService();
5034 if (statusbar != null) {
5035 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5036 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005037 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005038 } catch (RemoteException e) {
5039 // re-acquire status bar service next time it is needed.
5040 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005041 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005042 }
5043 });
5044 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005045 }
5046
John Spurlock79da8332013-09-20 12:04:47 -04005047 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlock27735a42013-08-14 17:57:38 -04005048 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005049 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005050 if (statusBarHasFocus) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005051 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5052 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005053 | View.SYSTEM_UI_FLAG_IMMERSIVE
5054 | View.SYSTEM_UI_FLAG_TRANSPARENT_STATUS
5055 | View.SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION;
John Spurlocke1f366f2013-08-05 12:22:40 -04005056 vis = (vis & ~flags) | (mLastSystemUiFlags & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005057 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005058
John Spurlock27735a42013-08-14 17:57:38 -04005059 // update status bar
5060 boolean transientAllowed =
John Spurlocke47193d2013-08-27 14:23:33 -04005061 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005062 boolean hideStatusBarWM =
John Spurlock79da8332013-09-20 12:04:47 -04005063 (win.getAttrs().flags
John Spurlock27735a42013-08-14 17:57:38 -04005064 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5065 boolean hideStatusBarSysui =
5066 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005067
John Spurlock27735a42013-08-14 17:57:38 -04005068 boolean transientStatusBarAllowed =
5069 mStatusBar != null && (
5070 hideStatusBarWM
5071 || (hideStatusBarSysui && transientAllowed)
5072 || statusBarHasFocus);
5073
5074 if (mStatusBarController.isTransientShowing()
5075 && !transientStatusBarAllowed && hideStatusBarSysui) {
5076 // clear the clearable flags instead
5077 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5078 if (newVal != mResettingSystemUiFlags) {
5079 mResettingSystemUiFlags = newVal;
5080 mWindowManagerFuncs.reevaluateStatusBarVisibility();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005081 }
5082 }
John Spurlock27735a42013-08-14 17:57:38 -04005083
5084 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5085
5086 // update navigation bar
5087 boolean oldTransientNav = isTransientNavigationAllowed(oldVis);
5088 boolean isTransientNav = isTransientNavigationAllowed(vis);
John Spurlock79da8332013-09-20 12:04:47 -04005089 if (win != null && oldTransientNav != isTransientNav) {
5090 final String pkg = win.getOwningPackage();
John Spurlockd67ec252013-09-05 11:31:54 -04005091 mTransientNavigationConfirmation.transientNavigationChanged(pkg, isTransientNav);
John Spurlock34e13d92013-08-10 06:52:28 -04005092 }
John Spurlock27735a42013-08-14 17:57:38 -04005093 vis = mNavigationBarController.updateVisibilityLw(isTransientNav, oldVis, vis);
5094
John Spurlock5b9145b2013-08-20 15:13:47 -04005095 // don't send low profile updates if the system bars are hidden
5096 if (mStatusBarController.isHidden() && mNavigationBarController.isHidden()) {
5097 vis &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
5098 }
John Spurlocke1f366f2013-08-05 12:22:40 -04005099 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005100 }
5101
John Spurlock27735a42013-08-14 17:57:38 -04005102 private boolean isTransientNavigationAllowed(int vis) {
John Spurlock34e13d92013-08-10 06:52:28 -04005103 return mNavigationBar != null
5104 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
John Spurlocke47193d2013-08-27 14:23:33 -04005105 && (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
John Spurlock34e13d92013-08-10 06:52:28 -04005106 }
5107
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005108 // Use this instead of checking config_showNavigationBar so that it can be consistently
5109 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005110 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005111 public boolean hasNavigationBar() {
5112 return mHasNavigationBar;
5113 }
5114
satok1bc0a492012-04-25 22:47:12 +09005115 @Override
5116 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5117 mLastInputMethodWindow = ime;
5118 mLastInputMethodTargetWindow = target;
5119 }
5120
Craig Mautnerf1b67412012-09-19 13:18:29 -07005121 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005122 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005123 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005124 if (mKeyguardDelegate != null) {
5125 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005126 }
John Spurlock13451a22012-09-28 14:40:41 -04005127 if (mStatusBarService != null) {
5128 try {
5129 mStatusBarService.setCurrentUser(newUserId);
5130 } catch (RemoteException e) {
5131 // oh well
5132 }
5133 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005134 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005135 }
5136
5137 @Override
Jim Miller4eeb4f62012-11-08 00:04:29 -08005138 public void showAssistant() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005139 mKeyguardDelegate.showAssistant();
Jim Miller4eeb4f62012-11-08 00:04:29 -08005140 }
5141
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005142 @Override
5143 public boolean canMagnifyWindow(int windowType) {
5144 switch (windowType) {
5145 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5146 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5147 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5148 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5149 return false;
5150 }
5151 }
5152 return true;
5153 }
5154
5155 @Override
5156 public boolean isTopLevelWindow(int windowType) {
5157 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5158 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5159 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5160 }
5161 return true;
5162 }
5163
Jim Miller4eeb4f62012-11-08 00:04:29 -08005164 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005165 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005166 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005167 pw.print(" mSystemReady="); pw.print(mSystemReady);
5168 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005169 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005170 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5171 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005172 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5173 || mForceClearedSystemUiFlags != 0) {
5174 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5175 pw.print(Integer.toHexString(mLastSystemUiFlags));
5176 pw.print(" mResettingSystemUiFlags=0x");
5177 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5178 pw.print(" mForceClearedSystemUiFlags=0x");
5179 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005180 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005181 if (mLastFocusNeedsMenu) {
5182 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5183 pw.println(mLastFocusNeedsMenu);
5184 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005185 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5186 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005187 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5188 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5189 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5190 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005191 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005192 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005193 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5194 pw.print(mCarDockEnablesAccelerometer);
5195 pw.print(" mDeskDockEnablesAccelerometer=");
5196 pw.println(mDeskDockEnablesAccelerometer);
5197 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5198 pw.print(mLidKeyboardAccessibility);
5199 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005200 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
5201 pw.print(prefix); pw.print("mLongPressOnPowerBehavior=");
5202 pw.print(mLongPressOnPowerBehavior);
5203 pw.print(" mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005204 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5205 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005206 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005207 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5208 pw.print(","); pw.print(mOverscanScreenTop);
5209 pw.print(") "); pw.print(mOverscanScreenWidth);
5210 pw.print("x"); pw.println(mOverscanScreenHeight);
5211 if (mOverscanLeft != 0 || mOverscanTop != 0
5212 || mOverscanRight != 0 || mOverscanBottom != 0) {
5213 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5214 pw.print(" top="); pw.print(mOverscanTop);
5215 pw.print(" right="); pw.print(mOverscanRight);
5216 pw.print(" bottom="); pw.println(mOverscanBottom);
5217 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005218 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5219 pw.print(mRestrictedOverscanScreenLeft);
5220 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5221 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5222 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005223 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5224 pw.print(","); pw.print(mUnrestrictedScreenTop);
5225 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5226 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5227 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5228 pw.print(","); pw.print(mRestrictedScreenTop);
5229 pw.print(") "); pw.print(mRestrictedScreenWidth);
5230 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005231 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5232 pw.print(","); pw.print(mStableFullscreenTop);
5233 pw.print(")-("); pw.print(mStableFullscreenRight);
5234 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005235 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5236 pw.print(","); pw.print(mStableTop);
5237 pw.print(")-("); pw.print(mStableRight);
5238 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005239 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5240 pw.print(","); pw.print(mSystemTop);
5241 pw.print(")-("); pw.print(mSystemRight);
5242 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005243 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5244 pw.print(","); pw.print(mCurTop);
5245 pw.print(")-("); pw.print(mCurRight);
5246 pw.print(","); pw.print(mCurBottom); pw.println(")");
5247 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5248 pw.print(","); pw.print(mContentTop);
5249 pw.print(")-("); pw.print(mContentRight);
5250 pw.print(","); pw.print(mContentBottom); pw.println(")");
5251 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5252 pw.print(","); pw.print(mDockTop);
5253 pw.print(")-("); pw.print(mDockRight);
5254 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005255 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5256 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005257 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5258 pw.print(" mShowingDream="); pw.print(mShowingDream);
5259 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005260 if (mLastInputMethodWindow != null) {
5261 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5262 pw.println(mLastInputMethodWindow);
5263 }
5264 if (mLastInputMethodTargetWindow != null) {
5265 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5266 pw.println(mLastInputMethodTargetWindow);
5267 }
5268 if (mStatusBar != null) {
5269 pw.print(prefix); pw.print("mStatusBar=");
5270 pw.println(mStatusBar);
5271 }
5272 if (mNavigationBar != null) {
5273 pw.print(prefix); pw.print("mNavigationBar=");
5274 pw.println(mNavigationBar);
5275 }
5276 if (mKeyguard != null) {
5277 pw.print(prefix); pw.print("mKeyguard=");
5278 pw.println(mKeyguard);
5279 }
5280 if (mFocusedWindow != null) {
5281 pw.print(prefix); pw.print("mFocusedWindow=");
5282 pw.println(mFocusedWindow);
5283 }
5284 if (mFocusedApp != null) {
5285 pw.print(prefix); pw.print("mFocusedApp=");
5286 pw.println(mFocusedApp);
5287 }
5288 if (mWinDismissingKeyguard != null) {
5289 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5290 pw.println(mWinDismissingKeyguard);
5291 }
5292 if (mTopFullscreenOpaqueWindowState != null) {
5293 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5294 pw.println(mTopFullscreenOpaqueWindowState);
5295 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005296 if (mForcingShowNavBar) {
5297 pw.print(prefix); pw.print("mForcingShowNavBar=");
5298 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5299 pw.println(mForcingShowNavBarLayer);
5300 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005301 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005302 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005303 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5304 pw.print(" mForceStatusBarFromKeyguard=");
5305 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005306 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005307 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005308 pw.print(" mHomePressed="); pw.println(mHomePressed);
5309 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5310 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5311 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5312 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5313 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5314 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5315 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5316 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5317 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5318 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005319 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5320 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5321 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
John Spurlock27735a42013-08-14 17:57:38 -04005322 mStatusBarController.dump(pw, prefix);
5323 mNavigationBarController.dump(pw, prefix);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005324 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005325}