blob: 8fc61155b7764411c6a40a6895b049d4e5baf75f [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;
John Spurlockf56bef12013-07-09 09:51:46 -040037import android.content.pm.UserInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070038import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080039import android.content.res.Configuration;
40import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070041import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080042import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080043import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.graphics.Rect;
Michael Jurka7a348952012-02-27 13:07:58 -080045import android.media.AudioManager;
46import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070047import android.media.Ringtone;
48import android.media.RingtoneManager;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070049import android.os.Bundle;
Jeff Brown9a538ee2012-08-20 14:56:57 -070050import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080051import android.os.Handler;
52import android.os.IBinder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070053import android.os.IRemoteCallback;
Jeff Brown32cbc38552011-12-01 14:01:49 -080054import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070055import android.os.Message;
56import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080057import android.os.PowerManager;
58import android.os.RemoteException;
59import android.os.ServiceManager;
60import android.os.SystemClock;
61import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080062import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070063import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080064import android.os.Vibrator;
65import android.provider.Settings;
John Spurlockc8b46ca2013-04-08 12:59:26 -040066import android.service.dreams.DreamService;
67import android.service.dreams.IDreamManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070068import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080069import android.util.EventLog;
70import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070071import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080072import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070073import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080074import android.view.Gravity;
75import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080076import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080077import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070078import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070079import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080080import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080081import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080082import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080083import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.view.KeyEvent;
85import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080086import android.view.Surface;
87import android.view.View;
88import android.view.ViewConfiguration;
89import android.view.Window;
90import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080091import android.view.WindowManagerGlobal;
92import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -080093import android.view.accessibility.AccessibilityEvent;
94import android.view.animation.Animation;
95import android.view.animation.AnimationUtils;
96
97import com.android.internal.R;
98import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -080099import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautnerae446592012-12-06 19:05:05 -0800100import com.android.internal.statusbar.IStatusBarService;
101import com.android.internal.telephony.ITelephony;
102import com.android.internal.widget.PointerLocationView;
103
104import java.io.File;
105import java.io.FileReader;
106import java.io.IOException;
107import java.io.PrintWriter;
John Spurlockad3e6cb2013-04-30 08:47:43 -0400108import java.util.HashSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800109
Dianne Hackbornc652de82013-02-15 16:32:56 -0800110import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700111import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
112import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
113import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800114
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800115/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700116 * WindowManagerPolicy implementation for the Android phone UI. This
117 * introduces a new method suffix, Lp, for an internal lock of the
118 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400119 * 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 -0700120 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800121 */
122public class PhoneWindowManager implements WindowManagerPolicy {
123 static final String TAG = "WindowManager";
124 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700125 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700126 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700127 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700128 static final boolean DEBUG_STARTING_WINDOW = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800129 static final boolean SHOW_STARTING_ANIMATIONS = true;
130 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400131
Daniel Sandler6396c722013-04-16 20:19:09 -0400132 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
133 // No longer recommended for desk docks; still useful in car docks.
134 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
135 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
136
Joe Onoratod208e702010-10-08 16:22:43 -0400137 static final int LONG_PRESS_POWER_NOTHING = 0;
138 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
139 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700140 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700141
142 // These need to match the documentation/constant in
143 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800144 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800145 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700146 static final int LONG_PRESS_HOME_ASSIST = 2;
147
148 static final int DOUBLE_TAP_HOME_NOTHING = 0;
149 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800150
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700151 static final int APPLICATION_MEDIA_SUBLAYER = -2;
152 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800153 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800154 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700155
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800156 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
157 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
158 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500159 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700160 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800161
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700162 /**
163 * These are the system UI flags that, when changing, can cause the layout
164 * of the screen to change.
165 */
166 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400167 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
168 | View.SYSTEM_UI_FLAG_FULLSCREEN
169 | View.SYSTEM_UI_FLAG_TRANSPARENT_STATUS
170 | View.SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700171
Jim Miller5ecd8112013-01-09 18:50:26 -0800172 /**
173 * Keyguard stuff
174 */
175 private WindowState mKeyguardScrim;
176
Jeff Brown6651a632011-11-28 12:59:11 -0800177 /* Table of Application Launch keys. Maps from key codes to intent categories.
178 *
179 * These are special keys that are used to launch particular kinds of applications,
180 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
181 * usage page. We don't support quite that many yet...
182 */
183 static SparseArray<String> sApplicationLaunchKeyCategories;
184 static {
185 sApplicationLaunchKeyCategories = new SparseArray<String>();
186 sApplicationLaunchKeyCategories.append(
187 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
188 sApplicationLaunchKeyCategories.append(
189 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
190 sApplicationLaunchKeyCategories.append(
191 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
192 sApplicationLaunchKeyCategories.append(
193 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
194 sApplicationLaunchKeyCategories.append(
195 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
196 sApplicationLaunchKeyCategories.append(
197 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
198 }
199
Dianne Hackborndf89e652011-10-06 22:35:11 -0700200 /**
201 * Lock protecting internal state. Must not call out into window
202 * manager with lock held. (This lock will be acquired in places
203 * where the window manager is calling in with its own lock held.)
204 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800205 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700206
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800207 Context mContext;
208 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700209 WindowManagerFuncs mWindowManagerFuncs;
Jeff Brown96307042012-07-27 15:51:34 -0700210 PowerManager mPowerManager;
Joe Onorato93056472010-09-10 10:30:46 -0400211 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700212 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700213 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800214 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700215 SearchManager mSearchManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800216
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700217 // Vibrator pattern for haptic feedback of a long press.
218 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700219
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700220 // Vibrator pattern for haptic feedback of virtual key press.
221 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700222
Amith Yamasanic33cb712010-02-10 15:21:49 -0800223 // Vibrator pattern for a short vibration.
224 long[] mKeyboardTapVibePattern;
225
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700226 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
227 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700228
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700229 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
230 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700231
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800232 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
233 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400234
235 boolean mHeadless;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800236 boolean mSafeMode;
237 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700238 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400239 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400240 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700241 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400242 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
243 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
244 int[] mNavigationBarHeightForRotation = new int[4];
245 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400246
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800247 WindowState mKeyguard = null;
Jim Miller5ecd8112013-01-09 18:50:26 -0800248 KeyguardServiceDelegate mKeyguardDelegate;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800249 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700250 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
251 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800252 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900253 WindowState mLastInputMethodWindow = null;
254 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800255
Jeff Brown68b909d2011-12-07 16:36:01 -0800256 static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0;
257 static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1;
Jeff Brown602ab322012-05-16 13:33:47 -0700258 static final int RECENT_APPS_BEHAVIOR_DISMISS = 2;
259 static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 3;
Jeff Brown68b909d2011-12-07 16:36:01 -0800260
261 RecentApplicationsDialog mRecentAppsDialog;
262 int mRecentAppsDialogHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700263 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800264
Jeff Brown2e7760e2012-04-11 15:14:55 -0700265 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700266 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800267
Dianne Hackbornc777e072010-02-12 13:07:59 -0800268 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700269 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800270 boolean mHdmiPlugged;
Daniel Sandler6396c722013-04-16 20:19:09 -0400271 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700272 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700273 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400274 int mCarDockRotation;
275 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700276 int mUndockedHdmiRotation;
277 int mDemoHdmiRotation;
278 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400279
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700280 // Default display does not rotate, apps that require non-default orientation will have to
281 // have the orientation emulated.
282 private boolean mForceDefaultOrientation = false;
283
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400284 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
285 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700286 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400287
Jeff Brownd3187e32011-09-21 19:26:44 -0700288 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400289 boolean mCarDockEnablesAccelerometer;
290 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700291 int mLidKeyboardAccessibility;
292 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700293 boolean mLidControlsSleep;
Joe Onoratod208e702010-10-08 16:22:43 -0400294 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700295 boolean mScreenOnEarly = false;
296 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800297 boolean mOrientationSensorEnabled = false;
298 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800299 boolean mHasSoftInput = false;
Craig Mautner967212c2013-04-13 21:10:58 -0700300
Jeff Brown70825162012-03-28 17:27:48 -0700301 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800302
303 // The last window we were told about in focusChanged.
304 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800305 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800306
Craig Mautner037aa8d2013-06-07 10:35:44 -0700307 private final class PointerLocationPointerEventListener implements PointerEventListener {
Jeff Browna41ca772010-08-11 14:46:32 -0700308 @Override
Craig Mautner037aa8d2013-06-07 10:35:44 -0700309 public void onPointerEvent(MotionEvent motionEvent) {
310 if (mPointerLocationView != null) {
311 mPointerLocationView.addPointerEvent(motionEvent);
Jeff Browna41ca772010-08-11 14:46:32 -0700312 }
313 }
Jeff Brown32cbc38552011-12-01 14:01:49 -0800314 }
Jeff Brown70825162012-03-28 17:27:48 -0700315
316 // Pointer location view state, only modified on the mHandler Looper.
Craig Mautner037aa8d2013-06-07 10:35:44 -0700317 PointerLocationPointerEventListener mPointerLocationPointerEventListener;
Jeff Brown70825162012-03-28 17:27:48 -0700318 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800319
Dianne Hackbornc652de82013-02-15 16:32:56 -0800320 // The current size of the screen; really; extends into the overscan area of
321 // the screen and doesn't account for any system elements like the status bar.
322 int mOverscanScreenLeft, mOverscanScreenTop;
323 int mOverscanScreenWidth, mOverscanScreenHeight;
324 // The current visible size of the screen; really; (ir)regardless of whether the status
325 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800326 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
327 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800328 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
329 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
330 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700331 // The current size of the screen; these may be different than (0,0)-(dw,dh)
332 // if the status bar can't be hidden; in that case it effectively carves out
333 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800334 int mRestrictedScreenLeft, mRestrictedScreenTop;
335 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700336 // During layout, the current screen borders accounting for any currently
337 // visible system UI elements.
338 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700339 // For applications requesting stable content insets, these are them.
340 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700341 // For applications requesting stable content insets but have also set the
342 // fullscreen window flag, these are the stable dimensions without the status bar.
343 int mStableFullscreenLeft, mStableFullscreenTop;
344 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800345 // During layout, the current screen borders with all outer decoration
346 // (status bar, input method dock) accounted for.
347 int mCurLeft, mCurTop, mCurRight, mCurBottom;
348 // During layout, the frame in which content should be displayed
349 // to the user, accounting for all screen decoration except for any
350 // space they deem as available for other content. This is usually
351 // the same as mCur*, but may be larger if the screen decor has supplied
352 // content insets.
353 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800354 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800355 // windows are placed.
356 int mDockLeft, mDockTop, mDockRight, mDockBottom;
357 // During layout, the layer at which the doc window is placed.
358 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700359 // During layout, this is the layer of the status bar.
360 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700361 int mLastSystemUiFlags;
362 // Bits that we are in the process of clearing, so we want to prevent
363 // them from being set by applications until everything has been updated
364 // to have them clear.
365 int mResettingSystemUiFlags = 0;
366 // Bits that we are currently always keeping cleared.
367 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800368 // What we last reported to system UI about whether the compatibility
369 // menu needs to be displayed.
370 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700371
372 FakeWindow mHideNavFakeWindow = null;
373
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800374 static final Rect mTmpParentFrame = new Rect();
375 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800376 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800377 static final Rect mTmpContentFrame = new Rect();
378 static final Rect mTmpVisibleFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700379 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700380
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800381 WindowState mTopFullscreenOpaqueWindowState;
Joe Onorato93056472010-09-10 10:30:46 -0400382 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800383 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700384 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700385 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800386 boolean mForcingShowNavBar;
387 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700388
389 // States of keyguard dismiss.
390 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
391 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
392 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
393 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
394
395 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
396 * be done once per window. */
397 private WindowState mWinDismissingKeyguard;
398
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700399 boolean mShowingLockscreen;
400 boolean mShowingDream;
401 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800402 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700403 boolean mHomeConsumed;
404 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800405 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700406 Intent mCarDockIntent;
407 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700408 boolean mSearchKeyShortcutPending;
409 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700410 boolean mAssistKeyLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800411
Mike Lockwood28569302010-01-28 11:54:40 -0500412 // support for activating the lock screen while the screen is on
413 boolean mAllowLockscreenWhenOn;
414 int mLockScreenTimeout;
415 boolean mLockScreenTimerActive;
416
David Brownbaf8d092010-03-08 21:52:59 -0800417 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800418 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800419
420 // Behavior of POWER button while in-call and screen on.
421 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
422 int mIncallPowerBehavior;
423
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700424 Display mDisplay;
425
Dianne Hackborn9d132642011-04-21 17:26:39 -0700426 int mLandscapeRotation = 0; // default landscape rotation
427 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
428 int mPortraitRotation = 0; // default portrait rotation
429 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700430
Dianne Hackbornc652de82013-02-15 16:32:56 -0800431 int mOverscanLeft = 0;
432 int mOverscanTop = 0;
433 int mOverscanRight = 0;
434 int mOverscanBottom = 0;
435
Joe Onorato46b0d682010-11-22 17:37:27 -0800436 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700437 private int mLongPressOnHomeBehavior;
438
439 // What we do when the user double-taps on home
440 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800441
Winson Chung9112ec32011-06-27 13:15:32 -0700442 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700443 // Time to volume and power must be pressed within this interval of each other.
444 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700445 // Increase the chord delay when taking a screenshot from the keyguard
446 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800447 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700448 private boolean mVolumeDownKeyTriggered;
449 private long mVolumeDownKeyTime;
450 private boolean mVolumeDownKeyConsumedByScreenshotChord;
451 private boolean mVolumeUpKeyTriggered;
452 private boolean mPowerKeyTriggered;
453 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700454
Michael Wrightb854e242013-02-05 17:54:02 -0800455 /* The number of steps between min and max brightness */
456 private static final int BRIGHTNESS_STEPS = 10;
457
Christopher Tate5e08af02012-09-21 17:17:22 -0700458 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800459 ShortcutManager mShortcutManager;
460 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700461 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800462
Justin Kohd378ad72013-04-01 12:18:26 -0700463 // Maps global key codes to the components that will handle them.
464 private GlobalKeyManager mGlobalKeyManager;
465
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700466 // Fallback actions by key code.
467 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
468 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800469
Jeff Brown70825162012-03-28 17:27:48 -0700470 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
471 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700472 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
473 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Jeff Brown70825162012-03-28 17:27:48 -0700474
475 private class PolicyHandler extends Handler {
476 @Override
477 public void handleMessage(Message msg) {
478 switch (msg.what) {
479 case MSG_ENABLE_POINTER_LOCATION:
480 enablePointerLocation();
481 break;
482 case MSG_DISABLE_POINTER_LOCATION:
483 disablePointerLocation();
484 break;
Jeff Brown40013652012-05-16 21:22:36 -0700485 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
486 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
487 break;
488 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
489 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
490 break;
Jeff Brown70825162012-03-28 17:27:48 -0700491 }
492 }
493 }
494
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800495 private UEventObserver mHDMIObserver = new UEventObserver() {
496 @Override
497 public void onUEvent(UEventObserver.UEvent event) {
498 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
499 }
500 };
501
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800502 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800503 SettingsObserver(Handler handler) {
504 super(handler);
505 }
David Brownbaf8d092010-03-08 21:52:59 -0800506
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800507 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700508 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800509 ContentResolver resolver = mContext.getContentResolver();
510 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700511 Settings.System.END_BUTTON_BEHAVIOR), false, this,
512 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800513 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700514 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
515 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800516 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700517 Settings.System.ACCELEROMETER_ROTATION), false, this,
518 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500519 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700520 Settings.System.USER_ROTATION), false, this,
521 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400522 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700523 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
524 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800525 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700526 Settings.System.POINTER_LOCATION), false, this,
527 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800528 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700529 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
530 UserHandle.USER_ALL);
Dianne Hackborn03759ed2009-03-27 16:04:08 -0700531 resolver.registerContentObserver(Settings.System.getUriFor(
John Spurlocke1f366f2013-08-05 12:22:40 -0400532 ImmersiveModeTesting.ENABLED_SETTING), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700533 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800534 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800535 }
536
537 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800538 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700539 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800540 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800541 }
Craig Mautner967212c2013-04-13 21:10:58 -0700542
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800543 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800544 MyOrientationListener(Context context, Handler handler) {
545 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800546 }
Craig Mautner967212c2013-04-13 21:10:58 -0700547
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800548 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700549 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700550 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700551 updateRotation(false);
552 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800553 }
554 MyOrientationListener mOrientationListener;
555
John Spurlock27735a42013-08-14 17:57:38 -0400556 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400557 View.STATUS_BAR_TRANSIENT,
558 View.STATUS_BAR_UNHIDE,
John Spurlockb77edbf2013-08-21 21:04:12 -0400559 View.SYSTEM_UI_FLAG_TRANSPARENT_STATUS,
John Spurlock5b9145b2013-08-20 15:13:47 -0400560 StatusBarManager.WINDOW_STATUS_BAR);
561
John Spurlock27735a42013-08-14 17:57:38 -0400562 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400563 View.NAVIGATION_BAR_TRANSIENT,
564 View.NAVIGATION_BAR_UNHIDE,
John Spurlockb77edbf2013-08-21 21:04:12 -0400565 View.SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION,
John Spurlock5b9145b2013-08-20 15:13:47 -0400566 StatusBarManager.WINDOW_NAVIGATION_BAR);
567
John Spurlock34e13d92013-08-10 06:52:28 -0400568 private TransientNavigationConfirmation mTransientNavigationConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400569
Craig Mautner037aa8d2013-06-07 10:35:44 -0700570 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400571
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700572 IStatusBarService getStatusBarService() {
573 synchronized (mServiceAquireLock) {
574 if (mStatusBarService == null) {
575 mStatusBarService = IStatusBarService.Stub.asInterface(
576 ServiceManager.getService("statusbar"));
577 }
578 return mStatusBarService;
579 }
580 }
581
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700582 /*
583 * We always let the sensor be switched on by default except when
584 * the user has explicitly disabled sensor based rotation or when the
585 * screen is switched off.
586 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700587 boolean needSensorRunningLp() {
Dianne Hackborne5439f22010-10-02 16:53:50 -0700588 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
589 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
590 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
591 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800592 // If the application has explicitly requested to follow the
593 // orientation, then we need to turn the sensor or.
594 return true;
595 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700596 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800597 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
598 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
599 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400600 // enable accelerometer if we are docked in a dock that enables accelerometer
601 // orientation management,
602 return true;
603 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700604 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800605 // If the setting for using the sensor by default is enabled, then
606 // we will always leave it on. Note that the user could go to
607 // a window that forces an orientation that does not use the
608 // sensor and in theory we could turn it off... however, when next
609 // turning it on we won't have a good value for the current
610 // orientation for a little bit, which can cause orientation
611 // changes to lag, so we'd like to keep it always on. (It will
612 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700613 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800614 }
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700615 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800616 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700617
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800618 /*
619 * Various use cases for invoking this function
620 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700621 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800622 * if not already enabled
623 * screen turned on and current app does not have sensor orientation, disable listeners if
624 * already enabled
625 * screen turning on and current app has sensor based orientation, enable listeners if needed
626 * screen turning on and current app has nosensor based orientation, do nothing
627 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700628 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800629 if (!mOrientationListener.canDetectOrientation()) {
630 // If sensor is turned off or nonexistent for some reason
631 return;
632 }
633 //Could have been invoked due to screen turning on or off or
634 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700635 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800636 ", current orientation="+mCurrentAppOrientation+
637 ", SensorEnabled="+mOrientationSensorEnabled);
638 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700639 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700640 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800641 disable = false;
642 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700643 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800644 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700645 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800646 mOrientationSensorEnabled = true;
647 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700648 }
649 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800650 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700651 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800652 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700653 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800654 mOrientationSensorEnabled = false;
655 }
656 }
657
Jeff Brown4d396052010-10-29 21:50:21 -0700658 private void interceptPowerKeyDown(boolean handled) {
659 mPowerKeyHandled = handled;
660 if (!handled) {
661 mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
662 }
663 }
664
665 private boolean interceptPowerKeyUp(boolean canceled) {
666 if (!mPowerKeyHandled) {
667 mHandler.removeCallbacks(mPowerLongPress);
668 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700669 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700670 return false;
671 }
672
673 private void cancelPendingPowerKeyAction() {
674 if (!mPowerKeyHandled) {
675 mHandler.removeCallbacks(mPowerLongPress);
676 }
Jeff Brownff204712011-10-25 21:27:54 -0700677 if (mPowerKeyTriggered) {
678 mPendingPowerKeyUpCanceled = true;
679 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700680 }
681
682 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800683 if (mScreenshotChordEnabled
684 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700685 final long now = SystemClock.uptimeMillis();
686 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
687 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
688 mVolumeDownKeyConsumedByScreenshotChord = true;
689 cancelPendingPowerKeyAction();
690
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800691 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700692 }
693 }
694 }
695
Winson Chung1cea2f32012-10-08 20:42:01 -0700696 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800697 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700698 // Double the time it takes to take a screenshot from the keyguard
699 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
700 ViewConfiguration.getGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700701 }
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800702 return ViewConfiguration.getGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700703 }
704
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700705 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800706 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700707 }
708
709 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700710 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800711 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700712 // The context isn't read
713 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700714 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
715 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400716 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700717 int resolvedBehavior = mLongPressOnPowerBehavior;
718 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
719 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
720 }
721
722 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700723 case LONG_PRESS_POWER_NOTHING:
724 break;
725 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
726 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700727 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
728 performAuditoryFeedbackForAccessibilityIfNeed();
729 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700730 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
731 showGlobalActionsDialog();
732 break;
733 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700734 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700735 mPowerKeyHandled = true;
736 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
737 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700738 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700739 break;
740 }
741 }
742 };
743
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800744 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800745 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700746 public void run() {
747 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800748 }
749 };
750
751 void showGlobalActionsDialog() {
752 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700753 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800754 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700755 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800756 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
757 if (keyguardShowing) {
758 // since it took two seconds of long press to bring this up,
759 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800760 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800761 }
762 }
763
764 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700765 return Settings.Global.getInt(
766 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800767 }
768
Patrick Dubroyece94522011-02-23 18:35:01 -0800769 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800770 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700771 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800772 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800773
Jeff Browncaca8812013-05-09 13:34:33 -0700774 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
775 toggleRecentApps();
776 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
777 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700778 }
779 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800780 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800781
Jeff Browncaca8812013-05-09 13:34:33 -0700782 private void handleDoubleTapOnHome() {
783 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
784 mHomeConsumed = true;
785 toggleRecentApps();
786 }
787 }
788
789 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
790 @Override
791 public void run() {
792 if (mHomeDoubleTapPending) {
793 mHomeDoubleTapPending = false;
794 launchHomeFromHotKey();
795 }
796 }
797 };
798
Patrick Dubroyece94522011-02-23 18:35:01 -0800799 /**
Jeff Brown68b909d2011-12-07 16:36:01 -0800800 * Create (if necessary) and show or dismiss the recent apps dialog according
801 * according to the requested behavior.
Patrick Dubroyece94522011-02-23 18:35:01 -0800802 */
Jeff Brown68b909d2011-12-07 16:36:01 -0800803 void showOrHideRecentAppsDialog(final int behavior) {
Jeff Brownda3d5a92011-03-29 15:11:34 -0700804 mHandler.post(new Runnable() {
805 @Override
806 public void run() {
807 if (mRecentAppsDialog == null) {
Jeff Brown54875002011-04-06 15:33:01 -0700808 mRecentAppsDialog = new RecentApplicationsDialog(mContext);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700809 }
Jeff Brown54875002011-04-06 15:33:01 -0700810 if (mRecentAppsDialog.isShowing()) {
Jeff Brown68b909d2011-12-07 16:36:01 -0800811 switch (behavior) {
812 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
Jeff Brown602ab322012-05-16 13:33:47 -0700813 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800814 mRecentAppsDialog.dismiss();
815 break;
816 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
817 mRecentAppsDialog.dismissAndSwitch();
818 break;
819 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
820 default:
821 break;
Jeff Brown54875002011-04-06 15:33:01 -0700822 }
823 } else {
Jeff Brown68b909d2011-12-07 16:36:01 -0800824 switch (behavior) {
825 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
826 mRecentAppsDialog.show();
827 break;
828 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
829 try {
830 mWindowManager.setInTouchMode(false);
831 } catch (RemoteException e) {
832 }
833 mRecentAppsDialog.show();
834 break;
Jeff Brown602ab322012-05-16 13:33:47 -0700835 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800836 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
837 default:
838 break;
839 }
Jeff Brown54875002011-04-06 15:33:01 -0700840 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700841 }
842 });
Patrick Dubroyece94522011-02-23 18:35:01 -0800843 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700844
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800845 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800846 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800847 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700848 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800849 mContext = context;
850 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700851 mWindowManagerFuncs = windowManagerFuncs;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400852 mHeadless = "1".equals(SystemProperties.get("ro.config.headless", "0"));
Jeff Brown70825162012-03-28 17:27:48 -0700853 mHandler = new PolicyHandler();
Craig Mautnereee29c42013-01-17 14:44:34 -0800854 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700855 try {
856 mOrientationListener.setCurrentRotation(windowManager.getRotation());
857 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700858 mSettingsObserver = new SettingsObserver(mHandler);
859 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800860 mShortcutManager = new ShortcutManager(context, mHandler);
861 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400862 mUiMode = context.getResources().getInteger(
863 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800864 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
865 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
866 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
867 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700868 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
869 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
870 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
871 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
872 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
873 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
874 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
875 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700876
Jeff Brown96307042012-07-27 15:51:34 -0700877 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
878 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800879 "PhoneWindowManager.mBroadcastWakeLock");
880 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700881 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400882 com.android.internal.R.integer.config_lidOpenRotation);
883 mCarDockRotation = readRotation(
884 com.android.internal.R.integer.config_carDockRotation);
885 mDeskDockRotation = readRotation(
886 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700887 mUndockedHdmiRotation = readRotation(
888 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400889 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
890 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
891 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
892 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700893 mLidKeyboardAccessibility = mContext.getResources().getInteger(
894 com.android.internal.R.integer.config_lidKeyboardAccessibility);
895 mLidNavigationAccessibility = mContext.getResources().getInteger(
896 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -0700897 mLidControlsSleep = mContext.getResources().getBoolean(
898 com.android.internal.R.bool.config_lidControlsSleep);
Jeff Brownf71343d2013-05-31 17:59:11 -0700899 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -0700900
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700901 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800902 IntentFilter filter = new IntentFilter();
903 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
904 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
905 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
906 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700907 filter.addAction(Intent.ACTION_DOCK_EVENT);
908 Intent intent = context.registerReceiver(mDockReceiver, filter);
909 if (intent != null) {
910 // Retrieve current sticky dock event broadcast.
911 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
912 Intent.EXTRA_DOCK_STATE_UNDOCKED);
913 }
Daniel Sandler7e37df52011-11-16 22:08:23 -0800914
Jeff Brown6aaf2952012-10-05 16:01:08 -0700915 // register for dream-related broadcasts
916 filter = new IntentFilter();
917 filter.addAction(Intent.ACTION_DREAMING_STARTED);
918 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
919 context.registerReceiver(mDreamReceiver, filter);
920
Christopher Tate5e08af02012-09-21 17:17:22 -0700921 // register for multiuser-relevant broadcasts
922 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
923 context.registerReceiver(mMultiuserReceiver, filter);
924
John Spurlock57306e62013-04-22 09:48:49 -0400925 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -0700926 mSystemGestures = new SystemGesturesPointerEventListener(context,
927 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -0400928 @Override
929 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -0400930 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400931 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -0400932 }
John Spurlockad3e6cb2013-04-30 08:47:43 -0400933 }
934 @Override
935 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -0400936 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400937 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400938 }
939 }
940 @Override
941 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -0400942 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400943 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400944 }
945 }
946 @Override
947 public void onDebug() {
John Spurlocke1f366f2013-08-05 12:22:40 -0400948 if (ImmersiveModeTesting.enabled) {
949 ImmersiveModeTesting.toggleForceImmersiveMode(mFocusedWindow, mContext);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400950 }
951 }
952 });
John Spurlock4cf6a942013-08-13 20:02:46 -0400953 mTransientNavigationConfirmation = new TransientNavigationConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -0700954 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -0400955
Jeff Brownc2346132012-04-13 01:55:38 -0700956 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700957 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
958 com.android.internal.R.array.config_longPressVibePattern);
959 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
960 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -0800961 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
962 com.android.internal.R.array.config_keyboardTapVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700963 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
964 com.android.internal.R.array.config_safeModeDisabledVibePattern);
965 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
966 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -0400967
Christopher Tatee90585f2012-03-05 18:56:25 -0800968 mScreenshotChordEnabled = mContext.getResources().getBoolean(
969 com.android.internal.R.bool.config_enableScreenshotChord);
970
Justin Kohd378ad72013-04-01 12:18:26 -0700971 mGlobalKeyManager = new GlobalKeyManager(mContext);
972
Joe Onoratoea495d42011-04-06 11:41:11 -0700973 // Controls rotation and the like.
974 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -0700975
976 // Match current screen state.
977 if (mPowerManager.isScreenOn()) {
978 screenTurningOn(null);
979 } else {
980 screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
981 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700982 }
983
Jeff Brownf71343d2013-05-31 17:59:11 -0700984 /**
985 * Read values from config.xml that may be overridden depending on
986 * the configuration of the device.
987 * eg. Disable long press on home goes to recents on sw600dp.
988 */
989 private void readConfigurationDependentBehaviors() {
990 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
991 com.android.internal.R.integer.config_longPressOnHomeBehavior);
992 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
993 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
994 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
995 }
996
997 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
998 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
999 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1000 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1001 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1002 }
1003 }
1004
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001005 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001006 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001007 // This method might be called before the policy has been fully initialized
1008 // or for other displays we don't care about.
1009 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1010 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001011 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001012 mDisplay = display;
1013
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001014 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001015 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001016 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001017 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001018 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001019 mLandscapeRotation = Surface.ROTATION_0;
1020 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001021 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001022 mPortraitRotation = Surface.ROTATION_90;
1023 mUpsideDownRotation = Surface.ROTATION_270;
1024 } else {
1025 mPortraitRotation = Surface.ROTATION_270;
1026 mUpsideDownRotation = Surface.ROTATION_90;
1027 }
1028 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001029 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001030 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001031 mPortraitRotation = Surface.ROTATION_0;
1032 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001033 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001034 mLandscapeRotation = Surface.ROTATION_270;
1035 mSeascapeRotation = Surface.ROTATION_90;
1036 } else {
1037 mLandscapeRotation = Surface.ROTATION_90;
1038 mSeascapeRotation = Surface.ROTATION_270;
1039 }
1040 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001041
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001042 mStatusBarHeight =
1043 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001044
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001045 // Height of the navigation bar when presented horizontally at bottom
1046 mNavigationBarHeightForRotation[mPortraitRotation] =
1047 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001048 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001049 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001050 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1051 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001052
1053 // Width of the navigation bar when presented vertically along one side
1054 mNavigationBarWidthForRotation[mPortraitRotation] =
1055 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1056 mNavigationBarWidthForRotation[mLandscapeRotation] =
1057 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001058 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001059
1060 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001061 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001062 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001063
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001064 // Allow the navigation bar to move on small devices (phones).
1065 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001066
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001067 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001068 // Allow a system property to override this. Used by the emulator.
1069 // See also hasNavigationBar().
1070 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1071 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001072 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001073 } else if ("0".equals(navBarOverride)) {
1074 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001075 }
1076
John Spurlock80f00c12013-06-13 11:10:51 -04001077 if (mHasNavigationBar) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001078 // The navigation bar is at the right in landscape; it seems always
1079 // useful to hide it for showing a video.
1080 mCanHideNavigationBar = true;
1081 } else {
1082 mCanHideNavigationBar = false;
1083 }
Erik Gilling9a41ef82011-09-26 19:21:03 -07001084
Jeff Brown27f1d672012-10-17 18:32:34 -07001085 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1086 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001087 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001088 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001089 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001090 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001091 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001092 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001093
1094 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1095 // http://developer.android.com/guide/practices/screens_support.html#range
1096 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1097 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1098 // For debug purposes the next line turns this feature off with:
1099 // $ adb shell setprop config.override_forced_orient true
1100 // $ adb shell wm size reset
1101 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1102 }
1103
1104 @Override
1105 public boolean isDefaultOrientationForced() {
1106 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001107 }
1108
Dianne Hackbornc652de82013-02-15 16:32:56 -08001109 @Override
1110 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1111 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1112 mOverscanLeft = left;
1113 mOverscanTop = top;
1114 mOverscanRight = right;
1115 mOverscanBottom = bottom;
1116 }
1117 }
1118
Dianne Hackbornc777e072010-02-12 13:07:59 -08001119 public void updateSettings() {
1120 ContentResolver resolver = mContext.getContentResolver();
1121 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001122 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001123 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001124 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001125 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1126 UserHandle.USER_CURRENT);
1127 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001128 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001129 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1130 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001131
Jeff Brown207673cd2012-06-05 17:47:11 -07001132 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001133 int userRotation = Settings.System.getIntForUser(resolver,
1134 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1135 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001136 if (mUserRotation != userRotation) {
1137 mUserRotation = userRotation;
1138 updateRotation = true;
1139 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001140 int userRotationMode = Settings.System.getIntForUser(resolver,
1141 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001142 WindowManagerPolicy.USER_ROTATION_FREE :
1143 WindowManagerPolicy.USER_ROTATION_LOCKED;
1144 if (mUserRotationMode != userRotationMode) {
1145 mUserRotationMode = userRotationMode;
1146 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001147 updateOrientationListenerLp();
1148 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001149
Dianne Hackbornc777e072010-02-12 13:07:59 -08001150 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001151 int pointerLocation = Settings.System.getIntForUser(resolver,
1152 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001153 if (mPointerLocationMode != pointerLocation) {
1154 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001155 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1156 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001157 }
1158 }
1159 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001160 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1161 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1162 String imId = Settings.Secure.getStringForUser(resolver,
1163 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001164 boolean hasSoftInput = imId != null && imId.length() > 0;
1165 if (mHasSoftInput != hasSoftInput) {
1166 mHasSoftInput = hasSoftInput;
1167 updateRotation = true;
1168 }
John Spurlocke1f366f2013-08-05 12:22:40 -04001169 ImmersiveModeTesting.enabled = Settings.System.getIntForUser(resolver,
1170 ImmersiveModeTesting.ENABLED_SETTING, 0, UserHandle.USER_CURRENT) != 0;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001171 }
1172 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001173 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001174 }
Jeff Brown70825162012-03-28 17:27:48 -07001175 }
1176
1177 private void enablePointerLocation() {
1178 if (mPointerLocationView == null) {
1179 mPointerLocationView = new PointerLocationView(mContext);
1180 mPointerLocationView.setPrintCoords(false);
1181
Dianne Hackbornc777e072010-02-12 13:07:59 -08001182 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1183 WindowManager.LayoutParams.MATCH_PARENT,
1184 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001185 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001186 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1187 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1188 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1189 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001190 if (ActivityManager.isHighEndGfx()) {
1191 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1192 lp.privateFlags |=
1193 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1194 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001195 lp.format = PixelFormat.TRANSLUCENT;
1196 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001197 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001198 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001199 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001200 wm.addView(mPointerLocationView, lp);
1201
Craig Mautner037aa8d2013-06-07 10:35:44 -07001202 mPointerLocationPointerEventListener = new PointerLocationPointerEventListener();
1203 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationPointerEventListener);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001204 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001205 }
Jeff Brown70825162012-03-28 17:27:48 -07001206
1207 private void disablePointerLocation() {
Craig Mautner037aa8d2013-06-07 10:35:44 -07001208 if (mPointerLocationPointerEventListener != null) {
1209 mWindowManagerFuncs.unregisterPointerEventListener(
1210 mPointerLocationPointerEventListener);
1211 mPointerLocationPointerEventListener = null;
Jeff Brown70825162012-03-28 17:27:48 -07001212 }
1213
1214 if (mPointerLocationView != null) {
1215 WindowManager wm = (WindowManager)
1216 mContext.getSystemService(Context.WINDOW_SERVICE);
1217 wm.removeView(mPointerLocationView);
1218 mPointerLocationView = null;
1219 }
1220 }
1221
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001222 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001223 try {
1224 int rotation = mContext.getResources().getInteger(resID);
1225 switch (rotation) {
1226 case 0:
1227 return Surface.ROTATION_0;
1228 case 90:
1229 return Surface.ROTATION_90;
1230 case 180:
1231 return Surface.ROTATION_180;
1232 case 270:
1233 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001234 }
1235 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001236 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001237 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001238 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001239 }
1240
1241 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001242 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001243 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001244 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001245
1246 outAppOp[0] = AppOpsManager.OP_NONE;
1247
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001248 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1249 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001250 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001251 }
1252 String permission = null;
1253 switch (type) {
1254 case TYPE_TOAST:
1255 // XXX right now the app process has complete control over
1256 // this... should introduce a token to let the system
1257 // monitor/control what they are doing.
1258 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001259 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001260 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001261 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001262 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001263 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001264 break;
1265 case TYPE_PHONE:
1266 case TYPE_PRIORITY_PHONE:
1267 case TYPE_SYSTEM_ALERT:
1268 case TYPE_SYSTEM_ERROR:
1269 case TYPE_SYSTEM_OVERLAY:
1270 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001271 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001272 break;
1273 default:
1274 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1275 }
1276 if (permission != null) {
1277 if (mContext.checkCallingOrSelfPermission(permission)
1278 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001279 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001280 }
1281 }
Jeff Brown98365d72012-08-19 20:30:52 -07001282 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001283 }
Craig Mautner88400d32012-09-30 12:35:45 -07001284
1285 @Override
1286 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1287
1288 // If this switch statement is modified, modify the comment in the declarations of
1289 // the type in {@link WindowManager.LayoutParams} as well.
1290 switch (attrs.type) {
1291 default:
1292 // These are the windows that by default are shown only to the user that created
1293 // them. If this needs to be overridden, set
1294 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1295 // {@link WindowManager.LayoutParams}. Note that permission
1296 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1297 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1298 return true;
1299 }
1300 break;
1301
1302 // These are the windows that by default are shown to all users. However, to
1303 // protect against spoofing, check permissions below.
1304 case TYPE_APPLICATION_STARTING:
1305 case TYPE_BOOT_PROGRESS:
1306 case TYPE_DISPLAY_OVERLAY:
1307 case TYPE_HIDDEN_NAV_CONSUMER:
1308 case TYPE_KEYGUARD:
Jim Miller5ecd8112013-01-09 18:50:26 -08001309 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001310 case TYPE_KEYGUARD_DIALOG:
1311 case TYPE_MAGNIFICATION_OVERLAY:
1312 case TYPE_NAVIGATION_BAR:
1313 case TYPE_NAVIGATION_BAR_PANEL:
1314 case TYPE_PHONE:
1315 case TYPE_POINTER:
1316 case TYPE_PRIORITY_PHONE:
1317 case TYPE_RECENTS_OVERLAY:
1318 case TYPE_SEARCH_BAR:
1319 case TYPE_STATUS_BAR:
1320 case TYPE_STATUS_BAR_PANEL:
1321 case TYPE_STATUS_BAR_SUB_PANEL:
1322 case TYPE_SYSTEM_DIALOG:
1323 case TYPE_UNIVERSE_BACKGROUND:
1324 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001325 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001326 break;
1327 }
1328
1329 // Check if third party app has set window to system window type.
1330 return mContext.checkCallingOrSelfPermission(
1331 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1332 != PackageManager.PERMISSION_GRANTED;
1333 }
1334
Craig Mautner967212c2013-04-13 21:10:58 -07001335 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001336 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1337 switch (attrs.type) {
1338 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001339 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001340 // These types of windows can't receive input events.
1341 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1342 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001343 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001344 break;
1345 }
1346 }
1347
1348 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001349 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001350 }
1351
Jeff Browndaa37532012-05-01 15:54:03 -07001352 private boolean isHidden(int accessibilityMode) {
1353 switch (accessibilityMode) {
1354 case 1:
1355 return mLidState == LID_CLOSED;
1356 case 2:
1357 return mLidState == LID_OPEN;
1358 default:
1359 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001360 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001361 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001362
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001363 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001364 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001365 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1366 int navigationPresence) {
1367 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1368
Jeff Brownf71343d2013-05-31 17:59:11 -07001369 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001370 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001371 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001372
Jeff Browndaa37532012-05-01 15:54:03 -07001373 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1374 || (keyboardPresence == PRESENCE_INTERNAL
1375 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001376 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001377 if (!mHasSoftInput) {
1378 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1379 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001380 }
1381
Jeff Browndaa37532012-05-01 15:54:03 -07001382 if (config.navigation == Configuration.NAVIGATION_NONAV
1383 || (navigationPresence == PRESENCE_INTERNAL
1384 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001385 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001386 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001387 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001388
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001389 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001390 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001391 public int windowTypeToLayerLw(int type) {
1392 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001393 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001394 }
1395 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001396 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001397 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001398 case TYPE_PRIVATE_PRESENTATION:
1399 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001400 case TYPE_WALLPAPER:
1401 // wallpaper is at the bottom, though the window manager may move it.
1402 return 2;
1403 case TYPE_PHONE:
1404 return 3;
1405 case TYPE_SEARCH_BAR:
1406 return 4;
Craig Mautner88400d32012-09-30 12:35:45 -07001407 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001408 case TYPE_SYSTEM_DIALOG:
1409 return 5;
1410 case TYPE_TOAST:
1411 // toasts and the plugged-in battery thing
1412 return 6;
1413 case TYPE_PRIORITY_PHONE:
1414 // SIM errors and unlock. Not sure if this really should be in a high layer.
1415 return 7;
1416 case TYPE_DREAM:
1417 // used for Dreams (screensavers with TYPE_DREAM windows)
1418 return 8;
1419 case TYPE_SYSTEM_ALERT:
1420 // like the ANR / app crashed dialogs
1421 return 9;
1422 case TYPE_INPUT_METHOD:
1423 // on-screen keyboards and other such input method user interfaces go here.
1424 return 10;
1425 case TYPE_INPUT_METHOD_DIALOG:
1426 // on-screen keyboards and other such input method user interfaces go here.
1427 return 11;
Jim Miller5ecd8112013-01-09 18:50:26 -08001428 case TYPE_KEYGUARD_SCRIM:
1429 // the safety window that shows behind keyguard while keyguard is starting
1430 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001431 case TYPE_KEYGUARD:
1432 // the keyguard; nothing on top of these can take focus, since they are
1433 // responsible for power management when displayed.
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001434 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001435 case TYPE_KEYGUARD_DIALOG:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001436 return 14;
Jim Miller5ecd8112013-01-09 18:50:26 -08001437 case TYPE_STATUS_BAR_SUB_PANEL:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001438 return 15;
Jim Miller5ecd8112013-01-09 18:50:26 -08001439 case TYPE_STATUS_BAR:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001440 return 16;
Jim Miller5ecd8112013-01-09 18:50:26 -08001441 case TYPE_STATUS_BAR_PANEL:
1442 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001443 case TYPE_VOLUME_OVERLAY:
1444 // the on-screen volume indicator and controller shown when the user
1445 // changes the device volume
Jim Miller5ecd8112013-01-09 18:50:26 -08001446 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001447 case TYPE_SYSTEM_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 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001451 case TYPE_NAVIGATION_BAR:
1452 // the navigation bar, if available, shows atop most things
Jim Miller5ecd8112013-01-09 18:50:26 -08001453 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001454 case TYPE_NAVIGATION_BAR_PANEL:
1455 // some panels (e.g. search) need to show on top of the navigation bar
Jim Miller5ecd8112013-01-09 18:50:26 -08001456 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001457 case TYPE_SYSTEM_ERROR:
1458 // system-level error dialogs
Jim Miller5ecd8112013-01-09 18:50:26 -08001459 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001460 case TYPE_MAGNIFICATION_OVERLAY:
1461 // used to highlight the magnified portion of a display
Jim Miller5ecd8112013-01-09 18:50:26 -08001462 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001463 case TYPE_DISPLAY_OVERLAY:
1464 // used to simulate secondary display devices
Jim Miller5ecd8112013-01-09 18:50:26 -08001465 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001466 case TYPE_DRAG:
1467 // the drag layer: input for drag-and-drop is associated with this window,
1468 // which sits above all other focusable windows
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001469 return 25;
Jim Miller5ecd8112013-01-09 18:50:26 -08001470 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001471 return 26;
Jim Miller5ecd8112013-01-09 18:50:26 -08001472 case TYPE_BOOT_PROGRESS:
1473 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001474 case TYPE_POINTER:
1475 // the (mouse) pointer layer
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001476 return 28;
Jim Miller5ecd8112013-01-09 18:50:26 -08001477 case TYPE_HIDDEN_NAV_CONSUMER:
1478 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001479 }
1480 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001481 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001482 }
1483
1484 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001485 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001486 public int subWindowTypeToLayerLw(int type) {
1487 switch (type) {
1488 case TYPE_APPLICATION_PANEL:
1489 case TYPE_APPLICATION_ATTACHED_DIALOG:
1490 return APPLICATION_PANEL_SUBLAYER;
1491 case TYPE_APPLICATION_MEDIA:
1492 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001493 case TYPE_APPLICATION_MEDIA_OVERLAY:
1494 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001495 case TYPE_APPLICATION_SUB_PANEL:
1496 return APPLICATION_SUB_PANEL_SUBLAYER;
1497 }
1498 Log.e(TAG, "Unknown sub-window type: " + type);
1499 return 0;
1500 }
1501
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001502 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001503 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001504 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001505 }
1506
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001507 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001508 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001509 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001510 }
1511
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001512 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001513 if (mHasNavigationBar) {
1514 // For a basic navigation bar, when we are in landscape mode we place
1515 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001516 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1517 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001518 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001519 }
1520 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001521 }
1522
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001523 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001524 if (mHasNavigationBar) {
1525 // For a basic navigation bar, when we are in portrait mode we place
1526 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001527 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1528 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001529 }
1530 }
1531 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001532 }
1533
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001534 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1535 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001536 }
1537
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001538 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001539 // There is a separate status bar at the top of the display. We don't count that as part
1540 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001541 // we do want to exclude it since applications can't generally use that part
1542 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001543 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001544 }
1545
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001546 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001547 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) {
1548 return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD;
1549 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001550
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001551 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001552 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001553 switch (attrs.type) {
1554 case TYPE_STATUS_BAR:
1555 case TYPE_NAVIGATION_BAR:
1556 case TYPE_WALLPAPER:
1557 case TYPE_DREAM:
1558 case TYPE_UNIVERSE_BACKGROUND:
1559 case TYPE_KEYGUARD:
Jim Miller5ecd8112013-01-09 18:50:26 -08001560 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001561 return false;
1562 default:
1563 return true;
1564 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001565 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001566
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001567 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001568 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001569 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1570 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001571 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001572 if (!SHOW_STARTING_ANIMATIONS) {
1573 return null;
1574 }
1575 if (packageName == null) {
1576 return null;
1577 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001578
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001579 WindowManager wm = null;
1580 View view = null;
1581
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001582 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001583 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001584 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1585 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1586 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001587 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001588 try {
1589 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001590 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001591 } catch (PackageManager.NameNotFoundException e) {
1592 // Ignore
1593 }
1594 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001595
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001596 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001597 final TypedArray ta = win.getWindowStyle();
1598 if (ta.getBoolean(
1599 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1600 || ta.getBoolean(
1601 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001602 return null;
1603 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001604
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001605 Resources r = context.getResources();
1606 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001607
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001608 win.setType(
1609 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1610 // Force the window flags: this is a fake window, so it is not really
1611 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1612 // flag because we do know that the next window will take input
1613 // focus, so we want to get the IME window up on top of us right away.
1614 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001615 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001616 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1617 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1618 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
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);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001623
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001624 if (!compatInfo.supportsScreen()) {
1625 win.addFlags(WindowManager.LayoutParams.FLAG_COMPATIBLE_WINDOW);
1626 }
1627
Adam Powell04fe6eb2013-05-31 14:39:48 -07001628 win.setDefaultIcon(icon);
1629 win.setDefaultLogo(logo);
1630
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001631 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001632 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001633
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001634 final WindowManager.LayoutParams params = win.getAttributes();
1635 params.token = appToken;
1636 params.packageName = packageName;
1637 params.windowAnimations = win.getWindowStyle().getResourceId(
1638 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001639 params.privateFlags |=
1640 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001641 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001642 params.setTitle("Starting " + packageName);
1643
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001644 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1645 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001646
1647 if (win.isFloating()) {
1648 // Whoops, there is no way to display an animation/preview
1649 // of such a thing! After all that work... let's skip it.
1650 // (Note that we must do this here because it is in
1651 // getDecorView() where the theme is evaluated... maybe
1652 // we should peek the floating attribute from the theme
1653 // earlier.)
1654 return null;
1655 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001656
Craig Mautner6fbda632012-07-03 09:26:39 -07001657 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001658 TAG, "Adding starting window for " + packageName
1659 + " / " + appToken + ": "
1660 + (view.getParent() != null ? view : null));
1661
1662 wm.addView(view, params);
1663
1664 // Only return the view if it was successfully added to the
1665 // window manager... which we can tell by it having a parent.
1666 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001667 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001668 // ignore
1669 Log.w(TAG, appToken + " already running, starting window not displayed");
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001670 } catch (RuntimeException e) {
1671 // don't crash if something else bad happens, for example a
1672 // failure loading resources because we are loading from an app
1673 // on external storage that has been unmounted.
1674 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001675 } finally {
1676 if (view != null && view.getParent() == null) {
1677 Log.w(TAG, "view not successfully added to wm, removing view");
1678 wm.removeViewImmediate(view);
1679 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001680 }
1681
1682 return null;
1683 }
1684
1685 /** {@inheritDoc} */
1686 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001687 if (DEBUG_STARTING_WINDOW) {
1688 RuntimeException e = new RuntimeException("here");
1689 e.fillInStackTrace();
1690 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1691 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001692
1693 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001694 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001695 wm.removeView(window);
1696 }
1697 }
1698
1699 /**
1700 * Preflight adding a window to the system.
1701 *
1702 * Currently enforces that three window types are singletons:
1703 * <ul>
1704 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001705 * <li>KEYGUARD_TYPE</li>
1706 * </ul>
1707 *
1708 * @param win The window to be added
1709 * @param attrs Information about the window to be added
1710 *
Jeff Brown98365d72012-08-19 20:30:52 -07001711 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1712 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001713 */
1714 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1715 switch (attrs.type) {
1716 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001717 mContext.enforceCallingOrSelfPermission(
1718 android.Manifest.permission.STATUS_BAR_SERVICE,
1719 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001720 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001721 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001722 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001723 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001724 }
1725 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001726 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001727 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001728 case TYPE_NAVIGATION_BAR:
1729 mContext.enforceCallingOrSelfPermission(
1730 android.Manifest.permission.STATUS_BAR_SERVICE,
1731 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001732 if (mNavigationBar != null) {
1733 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001734 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001735 }
1736 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001737 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001738 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001739 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001740 break;
Jim Millere898ac52012-04-06 17:10:57 -07001741 case TYPE_NAVIGATION_BAR_PANEL:
1742 mContext.enforceCallingOrSelfPermission(
1743 android.Manifest.permission.STATUS_BAR_SERVICE,
1744 "PhoneWindowManager");
1745 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001746 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001747 mContext.enforceCallingOrSelfPermission(
1748 android.Manifest.permission.STATUS_BAR_SERVICE,
1749 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001750 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001751 case TYPE_STATUS_BAR_SUB_PANEL:
1752 mContext.enforceCallingOrSelfPermission(
1753 android.Manifest.permission.STATUS_BAR_SERVICE,
1754 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001755 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001756 case TYPE_KEYGUARD:
1757 if (mKeyguard != null) {
Jeff Brown98365d72012-08-19 20:30:52 -07001758 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001759 }
1760 mKeyguard = win;
1761 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001762 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001763 if (mKeyguardScrim != null) {
1764 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1765 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001766 mKeyguardScrim = win;
1767 break;
1768
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001769 }
Jeff Brown98365d72012-08-19 20:30:52 -07001770 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001771 }
1772
1773 /** {@inheritDoc} */
1774 public void removeWindowLw(WindowState win) {
1775 if (mStatusBar == win) {
1776 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001777 mStatusBarController.setWindow(null);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001778 } else if (mKeyguard == win) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001779 Log.v(TAG, "Removing keyguard window (Did it crash?)");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001780 mKeyguard = null;
Jim Millerc0b676d2013-03-22 16:11:08 -07001781 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001782 } else if (mKeyguardScrim == win) {
1783 Log.v(TAG, "Removing keyguard scrim");
1784 mKeyguardScrim = null;
1785 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001786 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001787 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001788 }
1789 }
1790
1791 static final boolean PRINT_ANIM = false;
1792
1793 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001794 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001795 public int selectAnimationLw(WindowState win, int transit) {
1796 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1797 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001798 if (win == mStatusBar) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001799 if (transit == TRANSIT_EXIT
1800 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001801 return R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001802 } else if (transit == TRANSIT_ENTER
1803 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001804 return R.anim.dock_top_enter;
1805 }
1806 } else if (win == mNavigationBar) {
1807 // This can be on either the bottom or the right.
1808 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001809 if (transit == TRANSIT_EXIT
1810 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001811 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001812 } else if (transit == TRANSIT_ENTER
1813 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001814 return R.anim.dock_bottom_enter;
1815 }
1816 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001817 if (transit == TRANSIT_EXIT
1818 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001819 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001820 } else if (transit == TRANSIT_ENTER
1821 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001822 return R.anim.dock_right_enter;
1823 }
1824 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001825 }
1826
1827 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001828 if (win.hasAppShownWindows()) {
1829 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1830 return com.android.internal.R.anim.app_starting_exit;
1831 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001832 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001833 && transit == TRANSIT_ENTER) {
1834 // Special case: we are animating in a dream, while the keyguard
1835 // is shown. We don't want an animation on the dream, because
1836 // we need it shown immediately with the keyguard animating away
1837 // to reveal it.
1838 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001839 }
1840
1841 return 0;
1842 }
1843
Craig Mautner3c174372013-02-21 17:54:37 -08001844 @Override
1845 public void selectRotationAnimationLw(int anim[]) {
1846 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
1847 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
1848 + (mTopFullscreenOpaqueWindowState == null ?
1849 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
1850 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
1851 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
1852 case ROTATION_ANIMATION_CROSSFADE:
1853 anim[0] = R.anim.rotation_animation_xfade_exit;
1854 anim[1] = R.anim.rotation_animation_enter;
1855 break;
1856 case ROTATION_ANIMATION_JUMPCUT:
1857 anim[0] = R.anim.rotation_animation_jump_exit;
1858 anim[1] = R.anim.rotation_animation_enter;
1859 break;
1860 case ROTATION_ANIMATION_ROTATE:
1861 default:
1862 anim[0] = anim[1] = 0;
1863 break;
1864 }
1865 } else {
1866 anim[0] = anim[1] = 0;
1867 }
1868 }
1869
1870 @Override
1871 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
1872 boolean forceDefault) {
1873 switch (exitAnimId) {
1874 case R.anim.rotation_animation_xfade_exit:
1875 case R.anim.rotation_animation_jump_exit:
1876 // These are the only cases that matter.
1877 if (forceDefault) {
1878 return false;
1879 }
1880 int anim[] = new int[2];
1881 selectRotationAnimationLw(anim);
1882 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
1883 default:
1884 return true;
1885 }
1886 }
1887
1888 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07001889 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
1890 return AnimationUtils.loadAnimation(mContext, onWallpaper
1891 ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter
1892 : com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001893 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04001894
1895 private static void awakenDreams() {
1896 IDreamManager dreamManager = getDreamManager();
1897 if (dreamManager != null) {
1898 try {
1899 dreamManager.awaken();
1900 } catch (RemoteException e) {
1901 // fine, stay asleep then
1902 }
1903 }
1904 }
1905
1906 static IDreamManager getDreamManager() {
1907 return IDreamManager.Stub.asInterface(
1908 ServiceManager.checkService(DreamService.DREAM_SERVICE));
1909 }
1910
Jeff Brown4d396052010-10-29 21:50:21 -07001911 static ITelephony getTelephonyService() {
Mike Lockwoodf5f4ec92011-11-08 14:05:31 -08001912 return ITelephony.Stub.asInterface(
Jeff Brown4d396052010-10-29 21:50:21 -07001913 ServiceManager.checkService(Context.TELEPHONY_SERVICE));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001914 }
1915
Jeff Brown4d396052010-10-29 21:50:21 -07001916 static IAudioService getAudioService() {
1917 IAudioService audioService = IAudioService.Stub.asInterface(
1918 ServiceManager.checkService(Context.AUDIO_SERVICE));
1919 if (audioService == null) {
1920 Log.w(TAG, "Unable to find IAudioService interface.");
1921 }
1922 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001923 }
1924
1925 boolean keyguardOn() {
1926 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
1927 }
1928
1929 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
1930 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
1931 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
1932 };
1933
1934 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001935 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001936 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001937 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08001938 final int keyCode = event.getKeyCode();
1939 final int repeatCount = event.getRepeatCount();
1940 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001941 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08001942 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
1943 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001944
Jeff Brown40013652012-05-16 21:22:36 -07001945 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001946 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001947 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
1948 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001949 }
1950
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001951 // If we think we might have a volume down & power key chord on the way
1952 // but we're not sure, then tell the dispatcher to wait a little while and
1953 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08001954 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001955 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
1956 final long now = SystemClock.uptimeMillis();
1957 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
1958 if (now < timeoutTime) {
1959 return timeoutTime - now;
1960 }
1961 }
1962 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
1963 && mVolumeDownKeyConsumedByScreenshotChord) {
1964 if (!down) {
1965 mVolumeDownKeyConsumedByScreenshotChord = false;
1966 }
1967 return -1;
1968 }
1969 }
1970
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001971 // First we always handle the home key here, so applications
1972 // can never break it, although if keyguard is on, we do let
1973 // it handle it, because that gives us the correct 5 second
1974 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001975 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001976
Jeff Brown49ed71d2010-12-06 17:13:33 -08001977 // If we have released the home key, and didn't do anything else
1978 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07001979 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07001980 cancelPreloadRecentApps();
1981
Jeff Brown49ed71d2010-12-06 17:13:33 -08001982 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07001983 if (mHomeConsumed) {
1984 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07001985 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08001986 }
Jeff Browncaca8812013-05-09 13:34:33 -07001987
1988 if (canceled) {
1989 Log.i(TAG, "Ignoring HOME; event canceled.");
1990 return -1;
1991 }
1992
1993 // If an incoming call is ringing, HOME is totally disabled.
1994 // (The user is already on the InCallScreen at this point,
1995 // and his ONLY options are to answer or reject the call.)
1996 try {
1997 ITelephony telephonyService = getTelephonyService();
1998 if (telephonyService != null && telephonyService.isRinging()) {
1999 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2000 return -1;
2001 }
2002 } catch (RemoteException ex) {
2003 Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
2004 }
2005
2006 // Delay handling home if a double-tap is possible.
2007 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2008 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2009 mHomeDoubleTapPending = true;
2010 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2011 ViewConfiguration.getDoubleTapTimeout());
2012 return -1;
2013 }
2014
2015 // Go home!
2016 launchHomeFromHotKey();
2017 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002018 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002019
2020 // If a system window has focus, then it doesn't make sense
2021 // right now to interact with applications.
2022 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2023 if (attrs != null) {
2024 final int type = attrs.type;
2025 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
Jim Miller5ecd8112013-01-09 18:50:26 -08002026 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002027 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
2028 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002029 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002030 }
2031 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2032 for (int i=0; i<typeCount; i++) {
2033 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2034 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002035 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002036 }
2037 }
2038 }
Jeff Browncaca8812013-05-09 13:34:33 -07002039
2040 // Remember that home is pressed and handle special actions.
2041 if (repeatCount == 0) {
2042 mHomePressed = true;
2043 if (mHomeDoubleTapPending) {
2044 mHomeDoubleTapPending = false;
2045 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2046 handleDoubleTapOnHome();
2047 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2048 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2049 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002050 }
Jeff Browncaca8812013-05-09 13:34:33 -07002051 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2052 if (!keyguardOn) {
2053 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002054 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002055 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002056 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002057 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002058 // Hijack modified menu keys for debugging features
2059 final int chordBug = KeyEvent.META_SHIFT_ON;
2060
2061 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002062 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002063 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002064 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2065 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002066 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002067 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002068 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002069 Intent service = new Intent();
2070 service.setClassName(mContext, "com.android.server.LoadAverageService");
2071 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002072 boolean shown = Settings.Global.getInt(
2073 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002074 if (!shown) {
2075 mContext.startService(service);
2076 } else {
2077 mContext.stopService(service);
2078 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002079 Settings.Global.putInt(
2080 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002081 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002082 }
2083 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002084 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002085 if (down) {
2086 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002087 mSearchKeyShortcutPending = true;
2088 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002089 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002090 } else {
2091 mSearchKeyShortcutPending = false;
2092 if (mConsumeSearchKeyUp) {
2093 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002094 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002095 }
2096 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002097 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002098 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002099 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002100 if (down && repeatCount == 0) {
2101 preloadRecentApps();
2102 } else if (!down) {
2103 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002104 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002105 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002106 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002107 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2108 if (down) {
2109 if (repeatCount == 0) {
2110 mAssistKeyLongPressed = false;
2111 } else if (repeatCount == 1) {
2112 mAssistKeyLongPressed = true;
2113 if (!keyguardOn) {
2114 launchAssistLongPressAction();
2115 }
2116 }
2117 } else {
2118 if (mAssistKeyLongPressed) {
2119 mAssistKeyLongPressed = false;
2120 } else {
2121 if (!keyguardOn) {
2122 launchAssistAction();
2123 }
2124 }
2125 }
2126 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002127 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2128 if (down && repeatCount == 0) {
2129 mHandler.post(mScreenshotRunnable);
2130 }
2131 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002132 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2133 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2134 if (down) {
2135 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2136
2137 // Disable autobrightness if it's on
2138 int auto = Settings.System.getIntForUser(
2139 mContext.getContentResolver(),
2140 Settings.System.SCREEN_BRIGHTNESS_MODE,
2141 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2142 UserHandle.USER_CURRENT_OR_SELF);
2143 if (auto != 0) {
2144 Settings.System.putIntForUser(mContext.getContentResolver(),
2145 Settings.System.SCREEN_BRIGHTNESS_MODE,
2146 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2147 UserHandle.USER_CURRENT_OR_SELF);
2148 }
2149
2150 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2151 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2152 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2153 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2154 Settings.System.SCREEN_BRIGHTNESS,
2155 mPowerManager.getDefaultScreenBrightnessSetting(),
2156 UserHandle.USER_CURRENT_OR_SELF);
2157 brightness += step;
2158 // Make sure we don't go beyond the limits.
2159 brightness = Math.min(max, brightness);
2160 brightness = Math.max(min, brightness);
2161
2162 Settings.System.putIntForUser(mContext.getContentResolver(),
2163 Settings.System.SCREEN_BRIGHTNESS, brightness,
2164 UserHandle.USER_CURRENT_OR_SELF);
2165 Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG);
2166 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF);
2167 }
2168 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002169 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002170
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002171 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002172 // Any printing key that is chorded with Search should be consumed
2173 // even if no shortcut was invoked. This prevents text from being
2174 // inadvertently inserted when using a keyboard that has built-in macro
2175 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002176 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002177 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2178 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002179 mConsumeSearchKeyUp = true;
2180 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002181 if (down && repeatCount == 0 && !keyguardOn) {
2182 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2183 if (shortcutIntent != null) {
2184 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002185 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002186 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002187 } catch (ActivityNotFoundException ex) {
2188 Slog.w(TAG, "Dropping shortcut key combination because "
2189 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002190 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002191 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002192 } else {
2193 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002194 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002195 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002196 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002197 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002198 }
2199 }
2200
Jeff Brown68b909d2011-12-07 16:36:01 -08002201 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002202 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002203 && (metaState & KeyEvent.META_META_ON) != 0) {
2204 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002205 if (kcm.isPrintingKey(keyCode)) {
2206 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2207 metaState & ~(KeyEvent.META_META_ON
2208 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2209 if (shortcutIntent != null) {
2210 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2211 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002212 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002213 } catch (ActivityNotFoundException ex) {
2214 Slog.w(TAG, "Dropping shortcut key combination because "
2215 + "the activity to which it is registered was not found: "
2216 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2217 }
2218 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002219 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002220 }
2221 }
2222
Jeff Brown6651a632011-11-28 12:59:11 -08002223 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002224 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002225 String category = sApplicationLaunchKeyCategories.get(keyCode);
2226 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002227 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002228 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2229 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002230 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002231 } catch (ActivityNotFoundException ex) {
2232 Slog.w(TAG, "Dropping application launch key because "
2233 + "the activity to which it is registered was not found: "
2234 + "keyCode=" + keyCode + ", category=" + category, ex);
2235 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002236 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002237 }
2238 }
2239
Jeff Brown68b909d2011-12-07 16:36:01 -08002240 // Display task switcher for ALT-TAB or Meta-TAB.
2241 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Jeff Brown602ab322012-05-16 13:33:47 -07002242 if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002243 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
2244 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2245 || KeyEvent.metaStateHasModifiers(
2246 shiftlessModifiers, KeyEvent.META_META_ON)) {
2247 mRecentAppsDialogHeldModifiers = shiftlessModifiers;
2248 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW);
2249 return -1;
2250 }
2251 }
2252 } else if (!down && mRecentAppsDialogHeldModifiers != 0
2253 && (metaState & mRecentAppsDialogHeldModifiers) == 0) {
2254 mRecentAppsDialogHeldModifiers = 0;
Jeff Brown602ab322012-05-16 13:33:47 -07002255 showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS :
2256 RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH);
Jeff Brown68b909d2011-12-07 16:36:01 -08002257 }
2258
Jeff Browncf39bdf2012-05-18 14:41:19 -07002259 // Handle keyboard language switching.
2260 if (down && repeatCount == 0
2261 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2262 || (keyCode == KeyEvent.KEYCODE_SPACE
2263 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2264 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2265 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2266 return -1;
2267 }
2268 if (mLanguageSwitchKeyPressed && !down
2269 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2270 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2271 mLanguageSwitchKeyPressed = false;
2272 return -1;
2273 }
2274
Justin Kohd378ad72013-04-01 12:18:26 -07002275 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2276 return -1;
2277 }
2278
Jeff Brown68b909d2011-12-07 16:36:01 -08002279 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002280 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002281 }
2282
Jeff Brown3915bb82010-11-05 15:02:16 -07002283 /** {@inheritDoc} */
2284 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002285 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002286 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002287 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002288 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2289 + ", flags=" + event.getFlags()
2290 + ", keyCode=" + event.getKeyCode()
2291 + ", scanCode=" + event.getScanCode()
2292 + ", metaState=" + event.getMetaState()
2293 + ", repeatCount=" + event.getRepeatCount()
2294 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002295 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002296
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002297 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002298 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2299 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002300 final int keyCode = event.getKeyCode();
2301 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002302 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2303 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002304
Jeff Brown54875002011-04-06 15:33:01 -07002305 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002306 final FallbackAction fallbackAction;
2307 if (initialDown) {
2308 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2309 } else {
2310 fallbackAction = mFallbackActions.get(keyCode);
2311 }
2312
2313 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002314 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002315 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2316 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002317 }
2318
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002319 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2320 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002321 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002322 event.getAction(), fallbackAction.keyCode,
2323 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002324 event.getDeviceId(), event.getScanCode(),
2325 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002326
2327 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2328 fallbackEvent.recycle();
2329 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002330 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002331
2332 if (initialDown) {
2333 mFallbackActions.put(keyCode, fallbackAction);
2334 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2335 mFallbackActions.remove(keyCode);
2336 fallbackAction.recycle();
2337 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002338 }
2339 }
2340
Jeff Brown40013652012-05-16 21:22:36 -07002341 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002342 if (fallbackEvent == null) {
2343 Slog.d(TAG, "No fallback.");
2344 } else {
2345 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2346 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002347 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002348 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002349 }
2350
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002351 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
2352 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags, true);
2353 if ((actions & ACTION_PASS_TO_USER) != 0) {
2354 long delayMillis = interceptKeyBeforeDispatching(
2355 win, fallbackEvent, policyFlags);
2356 if (delayMillis == 0) {
2357 return true;
2358 }
2359 }
2360 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002361 }
2362
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002363 private void launchAssistLongPressAction() {
2364 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2365 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2366
2367 // launch the search activity
2368 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2369 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2370 try {
Jim Miller45308b12012-06-18 19:23:39 -07002371 // TODO: This only stops the factory-installed search manager.
2372 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002373 SearchManager searchManager = getSearchManager();
2374 if (searchManager != null) {
2375 searchManager.stopSearch();
2376 }
Michael Wright43e27f72013-04-10 14:06:48 -07002377 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002378 } catch (ActivityNotFoundException e) {
2379 Slog.w(TAG, "No activity to handle assist long press action.", e);
2380 }
2381 }
2382
2383 private void launchAssistAction() {
2384 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002385 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002386 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002387 if (intent != null) {
2388 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2389 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2390 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2391 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002392 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002393 } catch (ActivityNotFoundException e) {
2394 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002395 }
2396 }
2397 }
2398
2399 private SearchManager getSearchManager() {
2400 if (mSearchManager == null) {
2401 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2402 }
2403 return mSearchManager;
2404 }
2405
Jeff Browncaca8812013-05-09 13:34:33 -07002406 private void preloadRecentApps() {
2407 mPreloadedRecentApps = true;
2408 try {
2409 IStatusBarService statusbar = getStatusBarService();
2410 if (statusbar != null) {
2411 statusbar.preloadRecentApps();
2412 }
2413 } catch (RemoteException e) {
2414 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2415 // re-acquire status bar service next time it is needed.
2416 mStatusBarService = null;
2417 }
2418 }
2419
2420 private void cancelPreloadRecentApps() {
2421 if (mPreloadedRecentApps) {
2422 mPreloadedRecentApps = false;
2423 try {
2424 IStatusBarService statusbar = getStatusBarService();
2425 if (statusbar != null) {
2426 statusbar.cancelPreloadRecentApps();
2427 }
2428 } catch (RemoteException e) {
2429 Slog.e(TAG, "RemoteException when showing recent apps", e);
2430 // re-acquire status bar service next time it is needed.
2431 mStatusBarService = null;
2432 }
2433 }
2434 }
2435
2436 private void toggleRecentApps() {
2437 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2438 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
2439 try {
2440 IStatusBarService statusbar = getStatusBarService();
2441 if (statusbar != null) {
2442 statusbar.toggleRecentApps();
2443 }
2444 } catch (RemoteException e) {
2445 Slog.e(TAG, "RemoteException when showing recent apps", e);
2446 // re-acquire status bar service next time it is needed.
2447 mStatusBarService = null;
2448 }
2449 }
2450
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002451 /**
2452 * A home key -> launch home action was detected. Take the appropriate action
2453 * given the situation with the keyguard.
2454 */
2455 void launchHomeFromHotKey() {
Jim Miller5ecd8112013-01-09 18:50:26 -08002456 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotHidden()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002457 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002458 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002459 // when in keyguard restricted mode, must first verify unlock
2460 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002461 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002462 public void onKeyguardExitResult(boolean success) {
2463 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002464 try {
2465 ActivityManagerNative.getDefault().stopAppSwitches();
2466 } catch (RemoteException e) {
2467 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002468 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002469 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002470 }
2471 }
2472 });
2473 } else {
2474 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002475 try {
2476 ActivityManagerNative.getDefault().stopAppSwitches();
2477 } catch (RemoteException e) {
2478 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002479 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002480 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002481 }
2482 }
2483
John Spurlock04db1762013-05-13 12:46:41 -04002484 private final Runnable mClearHideNavigationFlag = new Runnable() {
2485 @Override
2486 public void run() {
2487 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2488 // Clear flags.
2489 mForceClearedSystemUiFlags &=
2490 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2491 }
2492 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002493 }
2494 };
2495
2496 /**
2497 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2498 * to determine when the nav bar should be shown and prevent applications from
2499 * receiving those touches.
2500 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002501 final class HideNavInputEventReceiver extends InputEventReceiver {
2502 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2503 super(inputChannel, looper);
2504 }
2505
Dianne Hackborndf89e652011-10-06 22:35:11 -07002506 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002507 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002508 boolean handled = false;
2509 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002510 if (event instanceof MotionEvent
2511 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2512 final MotionEvent motionEvent = (MotionEvent)event;
2513 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002514 // When the user taps down, we re-show the nav bar.
2515 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002516 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002517 // Any user activity always causes us to show the
2518 // navigation controls, if they had been hidden.
2519 // We also clear the low profile and only content
2520 // flags so that tapping on the screen will atomically
2521 // restore all currently hidden screen decorations.
2522 int newVal = mResettingSystemUiFlags |
2523 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2524 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2525 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002526 if (mResettingSystemUiFlags != newVal) {
2527 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002528 changed = true;
2529 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002530 // We don't allow the system's nav bar to be hidden
2531 // again for 1 second, to prevent applications from
2532 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002533 newVal = mForceClearedSystemUiFlags |
2534 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002535 if (mForceClearedSystemUiFlags != newVal) {
2536 mForceClearedSystemUiFlags = newVal;
2537 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002538 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002539 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002540 }
2541 if (changed) {
2542 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2543 }
2544 }
2545 }
2546 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002547 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002548 }
2549 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002550 }
2551 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2552 new InputEventReceiver.Factory() {
2553 @Override
2554 public InputEventReceiver createInputEventReceiver(
2555 InputChannel inputChannel, Looper looper) {
2556 return new HideNavInputEventReceiver(inputChannel, looper);
2557 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002558 };
2559
2560 @Override
2561 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002562 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2563 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
John Spurlock27735a42013-08-14 17:57:38 -04002564
Dianne Hackborndf89e652011-10-06 22:35:11 -07002565 // Reset any bits in mForceClearingStatusBarVisibility that
2566 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002567 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002568 // Clear any bits in the new visibility that are currently being
2569 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002570 return visibility & ~mResettingSystemUiFlags
2571 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002572 }
2573
Craig Mautner69b08182012-09-05 13:07:13 -07002574 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002575 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
2576 final int fl = attrs.flags;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002577 final int systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002578
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002579 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002580 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002581 int availRight, availBottom;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002582 if (mCanHideNavigationBar &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002583 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002584 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2585 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2586 } else {
2587 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2588 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2589 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002590 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2591 if ((fl & FLAG_FULLSCREEN) != 0) {
2592 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2593 availRight - mStableFullscreenRight,
2594 availBottom - mStableFullscreenBottom);
2595 } else {
2596 contentInset.set(mStableLeft, mStableTop,
2597 availRight - mStableRight, availBottom - mStableBottom);
2598 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002599 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002600 contentInset.setEmpty();
2601 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002602 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2603 contentInset.set(mCurLeft, mCurTop,
2604 availRight - mCurRight, availBottom - mCurBottom);
2605 } else {
2606 contentInset.set(mCurLeft, mCurTop,
2607 availRight - mCurRight, availBottom - mCurBottom);
2608 }
2609 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002610 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002611 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002612 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002613
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002614 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002615 @Override
2616 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2617 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002618 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2619 if (isDefaultDisplay) {
2620 switch (displayRotation) {
2621 case Surface.ROTATION_90:
2622 overscanLeft = mOverscanTop;
2623 overscanTop = mOverscanRight;
2624 overscanRight = mOverscanBottom;
2625 overscanBottom = mOverscanLeft;
2626 break;
2627 case Surface.ROTATION_180:
2628 overscanLeft = mOverscanRight;
2629 overscanTop = mOverscanBottom;
2630 overscanRight = mOverscanLeft;
2631 overscanBottom = mOverscanTop;
2632 break;
2633 case Surface.ROTATION_270:
2634 overscanLeft = mOverscanBottom;
2635 overscanTop = mOverscanLeft;
2636 overscanRight = mOverscanTop;
2637 overscanBottom = mOverscanRight;
2638 break;
2639 default:
2640 overscanLeft = mOverscanLeft;
2641 overscanTop = mOverscanTop;
2642 overscanRight = mOverscanRight;
2643 overscanBottom = mOverscanBottom;
2644 break;
2645 }
2646 } else {
2647 overscanLeft = 0;
2648 overscanTop = 0;
2649 overscanRight = 0;
2650 overscanBottom = 0;
2651 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002652 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2653 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2654 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2655 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002656 mSystemLeft = 0;
2657 mSystemTop = 0;
2658 mSystemRight = displayWidth;
2659 mSystemBottom = displayHeight;
2660 mUnrestrictedScreenLeft = overscanLeft;
2661 mUnrestrictedScreenTop = overscanTop;
2662 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2663 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2664 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2665 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002666 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2667 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002668 mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002669 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002670 mDockTop = mContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002671 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002672 mDockRight = mContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002673 = mCurRight = displayWidth - overscanRight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002674 mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002675 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002676 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002677 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002678
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002679 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2680 final Rect pf = mTmpParentFrame;
2681 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002682 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002683 final Rect vf = mTmpVisibleFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002684 pf.left = df.left = of.left = vf.left = mDockLeft;
2685 pf.top = df.top = of.top = vf.top = mDockTop;
2686 pf.right = df.right = of.right = vf.right = mDockRight;
2687 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002688
Craig Mautner69b08182012-09-05 13:07:13 -07002689 if (isDefaultDisplay) {
2690 // For purposes of putting out fake window up to steal focus, we will
2691 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002692 final int sysui = mLastSystemUiFlags;
2693 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
2694 boolean navTransparent = (sysui & View.SYSTEM_UI_FLAG_TRANSPARENT_NAVIGATION) != 0;
2695 boolean transientAllowed = (sysui & View.SYSTEM_UI_FLAG_ALLOW_TRANSIENT) != 0;
2696 navTransparent &= !transientAllowed; // transient trumps transparent
Dianne Hackborne26ab702011-10-16 13:21:33 -07002697
Craig Mautner69b08182012-09-05 13:07:13 -07002698 // When the navigation bar isn't visible, we put up a fake
2699 // input window to catch all touch events. This way we can
2700 // detect when the user presses anywhere to bring back the nav
2701 // bar and ensure the application doesn't see the event.
John Spurlocke1f366f2013-08-05 12:22:40 -04002702 if (navVisible || transientAllowed) {
Craig Mautner69b08182012-09-05 13:07:13 -07002703 if (mHideNavFakeWindow != null) {
2704 mHideNavFakeWindow.dismiss();
2705 mHideNavFakeWindow = null;
2706 }
2707 } else if (mHideNavFakeWindow == null) {
2708 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2709 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
2710 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER,
2711 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002712 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002713
Craig Mautner69b08182012-09-05 13:07:13 -07002714 // For purposes of positioning and showing the nav bar, if we have
2715 // decided that it can't be hidden (because of the screen aspect ratio),
2716 // then take that into account.
2717 navVisible |= !mCanHideNavigationBar;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002718
John Spurlockad3e6cb2013-04-30 08:47:43 -04002719 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07002720 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04002721 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07002722 // Force the navigation bar to its appropriate place and
2723 // size. We need to do this directly, instead of relying on
2724 // it to bubble up from the nav bar, because this needs to
2725 // change atomically with screen rotations.
2726 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2727 if (mNavigationBarOnBottom) {
2728 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002729 int top = displayHeight - overscanBottom
2730 - mNavigationBarHeightForRotation[displayRotation];
2731 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07002732 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlocke1f366f2013-08-05 12:22:40 -04002733 if (transientNavBarShowing || navTransparent) {
John Spurlock27735a42013-08-14 17:57:38 -04002734 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002735 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002736 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002737 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08002738 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
2739 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002740 } else {
2741 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002742 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002743 }
John Spurlockb77edbf2013-08-21 21:04:12 -04002744 if (navVisible && !navTransparent && !mNavigationBar.isAnimatingLw()
2745 && !mNavigationBarController.wasRecentlyTransparent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002746 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002747 // and not in the process of animating on or off, then
2748 // we can tell the app that it is covered by it.
2749 mSystemBottom = mTmpNavigationFrame.top;
2750 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002751 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002752 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002753 int left = displayWidth - overscanRight
2754 - mNavigationBarWidthForRotation[displayRotation];
2755 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07002756 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlocke1f366f2013-08-05 12:22:40 -04002757 if (transientNavBarShowing || navTransparent) {
John Spurlock27735a42013-08-14 17:57:38 -04002758 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002759 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002760 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002761 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08002762 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
2763 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07002764 } else {
2765 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002766 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002767 }
John Spurlockb77edbf2013-08-21 21:04:12 -04002768 if (navVisible && !navTransparent && !mNavigationBar.isAnimatingLw()
2769 && !mNavigationBarController.wasRecentlyTransparent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07002770 // If the nav bar is currently requested to be visible,
2771 // and not in the process of animating on or off, then
2772 // we can tell the app that it is covered by it.
2773 mSystemRight = mTmpNavigationFrame.left;
2774 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002775 }
Craig Mautner69b08182012-09-05 13:07:13 -07002776 // Make sure the content and current rectangles are updated to
2777 // account for the restrictions from the navigation bar.
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002778 mContentTop = mCurTop = mDockTop;
2779 mContentBottom = mCurBottom = mDockBottom;
2780 mContentLeft = mCurLeft = mDockLeft;
2781 mContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002782 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2783 // And compute the final frame.
2784 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002785 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame);
Craig Mautnereda67292013-04-28 13:50:14 -07002786 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04002787 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002788 updateSysUiVisibility = true;
2789 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002790 }
Craig Mautnereda67292013-04-28 13:50:14 -07002791 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07002792 mDockLeft, mDockTop, mDockRight, mDockBottom));
2793
2794 // decide where the status bar goes ahead of time
2795 if (mStatusBar != null) {
2796 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002797 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
2798 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2799 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
2800 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
2801 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002802 vf.left = mStableLeft;
2803 vf.top = mStableTop;
2804 vf.right = mStableRight;
2805 vf.bottom = mStableBottom;
2806
2807 mStatusBarLayer = mStatusBar.getSurfaceLayer();
2808
2809 // Let the status bar determine its size.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002810 mStatusBar.computeFrameLw(pf, df, vf, vf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002811
2812 // For layout, the status bar is always at the top with our fixed height.
2813 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
2814
John Spurlocke1f366f2013-08-05 12:22:40 -04002815 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
2816 boolean statusBarTransparent = (sysui & View.SYSTEM_UI_FLAG_TRANSPARENT_STATUS) != 0;
John Spurlock32beb2c2013-03-11 10:16:47 -04002817
Craig Mautner69b08182012-09-05 13:07:13 -07002818 // If the status bar is hidden, we don't want to cause
2819 // windows behind it to scroll.
John Spurlocke1f366f2013-08-05 12:22:40 -04002820 if (mStatusBar.isVisibleLw() && !statusBarTransient && !statusBarTransparent) {
Craig Mautner69b08182012-09-05 13:07:13 -07002821 // Status bar may go away, so the screen area it occupies
2822 // is available to apps but just covering them when the
2823 // status bar is visible.
2824 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
2825
2826 mContentTop = mCurTop = mDockTop;
2827 mContentBottom = mCurBottom = mDockBottom;
2828 mContentLeft = mCurLeft = mDockLeft;
2829 mContentRight = mCurRight = mDockRight;
2830
Craig Mautnereda67292013-04-28 13:50:14 -07002831 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07002832 String.format(
2833 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
2834 mDockLeft, mDockTop, mDockRight, mDockBottom,
2835 mContentLeft, mContentTop, mContentRight, mContentBottom,
2836 mCurLeft, mCurTop, mCurRight, mCurBottom));
2837 }
John Spurlocke1f366f2013-08-05 12:22:40 -04002838 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockb77edbf2013-08-21 21:04:12 -04002839 && !statusBarTransient && !statusBarTransparent
2840 && !mStatusBarController.wasRecentlyTransparent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002841 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002842 // and not in the process of animating on or off, then
2843 // we can tell the app that it is covered by it.
2844 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
2845 }
John Spurlock27735a42013-08-14 17:57:38 -04002846 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002847 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04002848 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002849 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04002850 if (updateSysUiVisibility) {
2851 updateSystemUiVisibilityLw();
2852 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002853 }
2854 }
2855
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002856 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002857 @Override
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002858 public int getSystemDecorRectLw(Rect systemRect) {
2859 systemRect.left = mSystemLeft;
2860 systemRect.top = mSystemTop;
2861 systemRect.right = mSystemRight;
2862 systemRect.bottom = mSystemBottom;
2863 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
2864 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
2865 return 0;
2866 }
2867
Craig Mautner967212c2013-04-13 21:10:58 -07002868 @Override
2869 public void getContentRectLw(Rect r) {
2870 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
2871 }
2872
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002873 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
2874 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002875 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
2876 // Here's a special case: if this attached window is a panel that is
2877 // above the dock window, and the window it is attached to is below
2878 // the dock window, then the frames we computed for the window it is
2879 // attached to can not be used because the dock is effectively part
2880 // of the underlying window and the attached window is floating on top
2881 // of the whole thing. So, we ignore the attached window and explicitly
2882 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002883 df.left = of.left = cf.left = vf.left = mDockLeft;
2884 df.top = of.top = cf.top = vf.top = mDockTop;
2885 df.right = of.right = cf.right = vf.right = mDockRight;
2886 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002887 } else {
2888 // The effective display frame of the attached window depends on
2889 // whether it is taking care of insetting its content. If not,
2890 // we need to use the parent's content frame so that the entire
2891 // window is positioned within that content. Otherwise we can use
2892 // the display frame and let the attached window take care of
2893 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002894 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002895 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002896 } else {
2897 // If the window is resizing, then we want to base the content
2898 // frame on our attached content frame to resize... however,
2899 // things can be tricky if the attached window is NOT in resize
2900 // mode, in which case its content frame will be larger.
2901 // Ungh. So to deal with that, make sure the content frame
2902 // we end up using is not covering the IM dock.
2903 cf.set(attached.getContentFrameLw());
2904 if (attached.getSurfaceLayer() < mDockLayer) {
2905 if (cf.left < mContentLeft) cf.left = mContentLeft;
2906 if (cf.top < mContentTop) cf.top = mContentTop;
2907 if (cf.right > mContentRight) cf.right = mContentRight;
2908 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
2909 }
2910 }
2911 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002912 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002913 vf.set(attached.getVisibleFrameLw());
2914 }
2915 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
2916 // window should be positioned relative to its parent or the entire
2917 // screen.
2918 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
2919 ? attached.getFrameLw() : df);
2920 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002921
2922 private void applyStableConstraints(int sysui, int fl, Rect r) {
2923 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2924 // If app is requesting a stable layout, don't let the
2925 // content insets go below the stable values.
2926 if ((fl & FLAG_FULLSCREEN) != 0) {
2927 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
2928 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
2929 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
2930 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
2931 } else {
2932 if (r.left < mStableLeft) r.left = mStableLeft;
2933 if (r.top < mStableTop) r.top = mStableTop;
2934 if (r.right > mStableRight) r.right = mStableRight;
2935 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
2936 }
2937 }
2938 }
2939
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002940 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002941 @Override
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07002942 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
2943 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002944 // we've already done the status bar
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002945 if (win == mStatusBar || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002946 return;
2947 }
Craig Mautner69b08182012-09-05 13:07:13 -07002948 final boolean isDefaultDisplay = win.isDefaultDisplay();
2949 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09002950 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
2951 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07002952 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09002953 offsetInputMethodWindowLw(mLastInputMethodWindow);
2954 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002955
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002956 final int fl = attrs.flags;
2957 final int sim = attrs.softInputMode;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002958 final int sysUiFl = win.getSystemUiVisibility();
2959
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002960 final Rect pf = mTmpParentFrame;
2961 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002962 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002963 final Rect cf = mTmpContentFrame;
2964 final Rect vf = mTmpVisibleFrame;
Craig Mautner69b08182012-09-05 13:07:13 -07002965
2966 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04002967 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002968
Craig Mautnerf683b562012-10-02 11:10:57 -07002969 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
2970
Craig Mautner69b08182012-09-05 13:07:13 -07002971 if (!isDefaultDisplay) {
2972 if (attached != null) {
2973 // If this window is attached to another, our display
2974 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002975 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002976 } else {
2977 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002978 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
2979 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
2980 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08002981 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002982 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002983 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07002984 }
2985 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002986 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
2987 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
2988 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
2989 pf.bottom = df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002990 // IM dock windows always go to the bottom of the screen.
2991 attrs.gravity = Gravity.BOTTOM;
2992 mDockLayer = win.getSurfaceLayer();
2993 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002994 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
2995 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Craig Mautnereda67292013-04-28 13:50:14 -07002996 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002997 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002998 // This is the case for a normal activity window: we want it
2999 // to cover all of the screen space, and it can take care of
3000 // moving its contents to account for screen decorations that
3001 // intrude into that space.
3002 if (attached != null) {
3003 // If this window is attached to another, our display
3004 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003005 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003006 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003007 if (attrs.type == TYPE_STATUS_BAR_PANEL
3008 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003009 // Status bar panels are the only windows who can go on top of
3010 // the status bar. They are protected by the STATUS_BAR_SERVICE
3011 // permission, so they have the same privileges as the status
3012 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003013 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003014 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003015
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003016 pf.left = df.left = of.left = hasNavBar
3017 ? mDockLeft : mUnrestrictedScreenLeft;
3018 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3019 pf.right = df.right = of.right = hasNavBar
3020 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3021 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3022 pf.bottom = df.bottom = of.bottom = hasNavBar
3023 ? mRestrictedScreenTop+mRestrictedScreenHeight
3024 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003025
Craig Mautnereda67292013-04-28 13:50:14 -07003026 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003027 "Laying out status bar window: (%d,%d - %d,%d)",
3028 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackbornc652de82013-02-15 16:32:56 -08003029 } else if ((attrs.flags&FLAG_LAYOUT_IN_OVERSCAN) != 0
3030 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3031 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3032 // Asking to layout into the overscan region, so give it that pure
3033 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003034 pf.left = df.left = of.left = mOverscanScreenLeft;
3035 pf.top = df.top = of.top = mOverscanScreenTop;
3036 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3037 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3038 + mOverscanScreenHeight;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003039 } else if (mCanHideNavigationBar
3040 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003041 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3042 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3043 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003044 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003045 // only do this for application windows to ensure no window that
3046 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003047 pf.left = df.left = mOverscanScreenLeft;
3048 pf.top = df.top = mOverscanScreenTop;
3049 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3050 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003051 // We need to tell the app about where the frame inside the overscan
3052 // is, so it can inset its content by that amount -- it didn't ask
3053 // to actually extend itself into the overscan region.
3054 of.left = mUnrestrictedScreenLeft;
3055 of.top = mUnrestrictedScreenTop;
3056 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3057 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003058 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003059 pf.left = df.left = mRestrictedOverscanScreenLeft;
3060 pf.top = df.top = mRestrictedOverscanScreenTop;
3061 pf.right = df.right = mRestrictedOverscanScreenLeft
3062 + mRestrictedOverscanScreenWidth;
3063 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3064 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003065 // We need to tell the app about where the frame inside the overscan
3066 // is, so it can inset its content by that amount -- it didn't ask
3067 // to actually extend itself into the overscan region.
3068 of.left = mUnrestrictedScreenLeft;
3069 of.top = mUnrestrictedScreenTop;
3070 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3071 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003072 }
Craig Mautner69b08182012-09-05 13:07:13 -07003073
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003074 if ((attrs.flags&FLAG_FULLSCREEN) == 0) {
3075 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3076 cf.left = mDockLeft;
3077 cf.top = mDockTop;
3078 cf.right = mDockRight;
3079 cf.bottom = mDockBottom;
3080 } else {
3081 cf.left = mContentLeft;
3082 cf.top = mContentTop;
3083 cf.right = mContentRight;
3084 cf.bottom = mContentBottom;
3085 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003086 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003087 // Full screen windows are always given a layout that is as if the
3088 // status bar and other transient decors are gone. This is to avoid
3089 // bad states when moving from a window that is not hding the
3090 // status bar to one that is.
3091 cf.left = mRestrictedScreenLeft;
3092 cf.top = mRestrictedScreenTop;
3093 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3094 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003095 }
Craig Mautner69b08182012-09-05 13:07:13 -07003096
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003097 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003098 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3099 vf.left = mCurLeft;
3100 vf.top = mCurTop;
3101 vf.right = mCurRight;
3102 vf.bottom = mCurBottom;
3103 } else {
3104 vf.set(cf);
3105 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003106 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003107 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3108 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3109 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003110 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3111 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003112 // A window that has requested to fill the entire screen just
3113 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003114 if (attrs.type == TYPE_STATUS_BAR_PANEL
3115 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003116 pf.left = df.left = of.left = cf.left = hasNavBar
3117 ? mDockLeft : mUnrestrictedScreenLeft;
3118 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3119 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003120 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003121 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003122 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003123 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003124 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003125 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003126 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3127 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003128 } else if (attrs.type == TYPE_NAVIGATION_BAR
3129 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003130 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003131 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3132 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3133 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3134 + mUnrestrictedScreenWidth;
3135 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3136 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003137 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003138 "Laying out navigation bar window: (%d,%d - %d,%d)",
3139 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003140 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3141 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003142 && ((fl & FLAG_FULLSCREEN) != 0)) {
3143 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003144 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3145 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3146 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3147 + mOverscanScreenWidth;
3148 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3149 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003150 } else if (attrs.type == TYPE_BOOT_PROGRESS
3151 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003152 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003153 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3154 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3155 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3156 + mOverscanScreenWidth;
3157 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3158 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003159 } else if (attrs.type == TYPE_WALLPAPER) {
3160 // The wallpaper also has Real Ultimate Power.
3161 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3162 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003163 pf.right = df.right = of.right = cf.right
John Spurlockef4adae2013-08-26 17:58:58 -04003164 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003165 pf.bottom = df.bottom = of.bottom = cf.bottom
John Spurlockef4adae2013-08-26 17:58:58 -04003166 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003167 } else if ((attrs.flags & FLAG_LAYOUT_IN_OVERSCAN) != 0
3168 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3169 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3170 // Asking to layout into the overscan region, so give it that pure
3171 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003172 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3173 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3174 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003175 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003176 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003177 = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003178 } else if (mCanHideNavigationBar
3179 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
John Spurlock34e13d92013-08-10 06:52:28 -04003180 && (attrs.type == TYPE_TOAST
3181 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3182 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003183 // Asking for layout as if the nav bar is hidden, lets the
3184 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003185 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003186 // can be above the nav bar can do this.
3187 // XXX This assumes that an app asking for this will also
3188 // ask for layout in only content. We can't currently figure out
3189 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003190 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3191 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3192 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3193 + mUnrestrictedScreenWidth;
3194 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3195 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003196 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003197 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3198 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3199 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3200 + mRestrictedScreenWidth;
3201 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3202 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003203 }
Craig Mautner69b08182012-09-05 13:07:13 -07003204
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003205 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003206
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003207 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3208 vf.left = mCurLeft;
3209 vf.top = mCurTop;
3210 vf.right = mCurRight;
3211 vf.bottom = mCurBottom;
3212 } else {
3213 vf.set(cf);
3214 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003215 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003216 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3217 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003218 // A child window should be placed inside of the same visible
3219 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003220 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003221 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003222 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3223 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003224 // Otherwise, a normal window must be placed inside the content
3225 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003226 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3227 // Status bar panels are the only windows who can go on top of
3228 // the status bar. They are protected by the STATUS_BAR_SERVICE
3229 // permission, so they have the same privileges as the status
3230 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003231 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3232 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3233 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3234 + mRestrictedScreenWidth;
3235 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3236 + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003237 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003238 pf.left = mContentLeft;
3239 pf.top = mContentTop;
3240 pf.right = mContentRight;
3241 pf.bottom = mContentBottom;
3242 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003243 df.left = of.left = cf.left = mDockLeft;
3244 df.top = of.top = cf.top = mDockTop;
3245 df.right = of.right = cf.right = mDockRight;
3246 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003247 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003248 df.left = of.left = cf.left = mContentLeft;
3249 df.top = of.top = cf.top = mContentTop;
3250 df.right = of.right = cf.right = mContentRight;
3251 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003252 }
3253 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3254 vf.left = mCurLeft;
3255 vf.top = mCurTop;
3256 vf.right = mCurRight;
3257 vf.bottom = mCurBottom;
3258 } else {
3259 vf.set(cf);
3260 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003261 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003262 }
3263 }
Craig Mautner69b08182012-09-05 13:07:13 -07003264
Craig Mautnerb816bed2013-07-23 10:26:17 -07003265 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3266 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003267 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3268 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3269 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003270 }
3271
Craig Mautnereda67292013-04-28 13:50:14 -07003272 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003273 + ": sim=#" + Integer.toHexString(sim)
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003274 + " attach=" + attached + " type=" + attrs.type
3275 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003276 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003277 + " of=" + of.toShortString()
The Android Open Source Project11267662009-03-18 17:39:47 -07003278 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003279
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003280 win.computeFrameLw(pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003281
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003282 // Dock windows carve out the bottom of the screen, so normal windows
3283 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003284 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3285 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003286 setLastInputMethodWindowLw(null, null);
3287 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003288 }
3289 }
3290
satok1bc0a492012-04-25 22:47:12 +09003291 private void offsetInputMethodWindowLw(WindowState win) {
3292 int top = win.getContentFrameLw().top;
3293 top += win.getGivenContentInsetsLw().top;
3294 if (mContentBottom > top) {
3295 mContentBottom = top;
3296 }
3297 top = win.getVisibleFrameLw().top;
3298 top += win.getGivenVisibleInsetsLw().top;
3299 if (mCurBottom > top) {
3300 mCurBottom = top;
3301 }
Craig Mautnereda67292013-04-28 13:50:14 -07003302 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003303 + mDockBottom + " mContentBottom="
3304 + mContentBottom + " mCurBottom=" + mCurBottom);
3305 }
3306
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003307 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003308 @Override
3309 public void finishLayoutLw() {
3310 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003311 }
3312
3313 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003314 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003315 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003316 mTopFullscreenOpaqueWindowState = null;
3317 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003318 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003319 mForcingShowNavBar = false;
3320 mForcingShowNavBarLayer = -1;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003321
3322 mHideLockScreen = false;
3323 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003324 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003325 mShowingLockscreen = false;
3326 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003327 }
3328
3329 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003330 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003331 public void applyPostLayoutPolicyLw(WindowState win,
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003332 WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003333 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3334 + win.isVisibleOrBehindKeyguardLw());
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003335 if (mTopFullscreenOpaqueWindowState == null && (win.getAttrs().privateFlags
3336 &WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_SHOW_NAV_BAR) != 0) {
3337 if (mForcingShowNavBarLayer < 0) {
3338 mForcingShowNavBar = true;
3339 mForcingShowNavBarLayer = win.getSurfaceLayer();
3340 }
3341 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003342 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003343 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003344 if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003345 if (attrs.type == TYPE_KEYGUARD) {
3346 mForceStatusBarFromKeyguard = true;
3347 } else {
3348 mForceStatusBar = true;
3349 }
3350 }
3351 if (attrs.type == TYPE_KEYGUARD) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003352 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003353 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003354 boolean applyWindow = attrs.type >= FIRST_APPLICATION_WINDOW
3355 && attrs.type <= LAST_APPLICATION_WINDOW;
3356 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003357 // If the lockscreen was showing when the dream started then wait
3358 // for the dream to draw before hiding the lockscreen.
3359 if (!mDreamingLockscreen
3360 || (win.isVisibleLw() && win.hasDrawnLw())) {
3361 mShowingDream = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003362 applyWindow = true;
3363 }
3364 }
3365 if (applyWindow
Dianne Hackborn6493e642010-10-01 13:06:30 -07003366 && attrs.x == 0 && attrs.y == 0
3367 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3368 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
Craig Mautnereda67292013-04-28 13:50:14 -07003369 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003370 mTopFullscreenOpaqueWindowState = win;
3371 if ((attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003372 if (DEBUG_LAYOUT) Slog.v(TAG, "Setting mHideLockScreen to true by win " + win);
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003373 mHideLockScreen = true;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003374 mForceStatusBarFromKeyguard = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003375 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003376 if ((attrs.flags & FLAG_DISMISS_KEYGUARD) != 0
3377 && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautnereda67292013-04-28 13:50:14 -07003378 if (DEBUG_LAYOUT) Slog.v(TAG, "Setting mDismissKeyguard true by win " + win);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003379 mDismissKeyguard = mWinDismissingKeyguard == win ?
3380 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3381 mWinDismissingKeyguard = win;
Craig Mautnereda67292013-04-28 13:50:14 -07003382 mForceStatusBarFromKeyguard = mShowingLockscreen && isKeyguardSecure();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003383 }
3384 if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
3385 mAllowLockscreenWhenOn = true;
3386 }
3387 }
3388 }
3389 }
3390
3391 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003392 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003393 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003394 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003395 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003396
3397 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3398 ? mTopFullscreenOpaqueWindowState.getAttrs()
3399 : null;
3400
Jeff Brownc8018eb2012-10-29 21:33:27 -07003401 // If we are not currently showing a dream then remember the current
3402 // lockscreen state. We will use this to determine whether the dream
3403 // started while the lockscreen was showing and remember this state
3404 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003405 if (!mShowingDream) {
3406 mDreamingLockscreen = mShowingLockscreen;
3407 }
3408
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003409 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003410 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003411 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003412 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003413 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003414 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003415 if (mStatusBarController.setBarShowingLw(true)) {
3416 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3417 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003418 } else if (mTopFullscreenOpaqueWindowState != null) {
Joe Onorato93056472010-09-10 10:30:46 -04003419 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003420 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003421 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003422 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
Joe Onorato93056472010-09-10 10:30:46 -04003423 + " lp.flags=0x" + Integer.toHexString(lp.flags));
3424 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003425 topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
3426 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003427 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3428 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3429 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3430 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003431 if (mStatusBarController.isTransientShowing()) {
3432 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003433 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3434 }
3435 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003436 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003437 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003438 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003439 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003440 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003441 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003442 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003443 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003444 if (mStatusBarController.setBarShowingLw(true)) {
3445 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3446 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003447 }
3448 }
3449 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003450
Joe Onorato644f9c32011-01-25 12:06:23 -08003451 mTopIsFullscreen = topIsFullscreen;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003452
Craig Mautner39834192012-09-02 07:47:24 -07003453 // Hide the key guard if a visible window explicitly specifies that it wants to be
3454 // displayed when the screen is locked.
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003455 if (mKeyguard != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003456 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
Craig Mautner39834192012-09-02 07:47:24 -07003457 + mHideLockScreen);
Jim Miller5ecd8112013-01-09 18:50:26 -08003458 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardDelegate.isSecure()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003459 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003460 changes |= FINISH_LAYOUT_REDO_LAYOUT
3461 | FINISH_LAYOUT_REDO_CONFIG
3462 | FINISH_LAYOUT_REDO_WALLPAPER;
3463 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003464 if (mKeyguardDelegate.isShowing()) {
Dianne Hackbornb446e972009-09-20 15:23:25 -07003465 mHandler.post(new Runnable() {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003466 @Override
Dianne Hackbornb446e972009-09-20 15:23:25 -07003467 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08003468 mKeyguardDelegate.keyguardDone(false, false);
Dianne Hackbornb446e972009-09-20 15:23:25 -07003469 }
3470 });
3471 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003472 } else if (mHideLockScreen) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003473 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003474 changes |= FINISH_LAYOUT_REDO_LAYOUT
3475 | FINISH_LAYOUT_REDO_CONFIG
3476 | FINISH_LAYOUT_REDO_WALLPAPER;
3477 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003478 mKeyguardDelegate.setHidden(true);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003479 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3480 // This is the case of keyguard isSecure() and not mHideLockScreen.
3481 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3482 // Only launch the next keyguard unlock window once per window.
3483 if (mKeyguard.showLw(true)) {
3484 changes |= FINISH_LAYOUT_REDO_LAYOUT
3485 | FINISH_LAYOUT_REDO_CONFIG
3486 | FINISH_LAYOUT_REDO_WALLPAPER;
3487 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003488 mKeyguardDelegate.setHidden(false);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003489 mHandler.post(new Runnable() {
3490 @Override
3491 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08003492 mKeyguardDelegate.dismiss();
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003493 }
3494 });
3495 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003496 } else {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003497 mWinDismissingKeyguard = null;
Dianne Hackborn08743722009-12-21 12:16:51 -08003498 if (mKeyguard.showLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003499 changes |= FINISH_LAYOUT_REDO_LAYOUT
3500 | FINISH_LAYOUT_REDO_CONFIG
3501 | FINISH_LAYOUT_REDO_WALLPAPER;
3502 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003503 mKeyguardDelegate.setHidden(false);
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003504 }
3505 }
Joe Onorato664644d2011-01-23 17:53:23 -08003506
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003507 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003508 // If the navigation bar has been hidden or shown, we need to do another
3509 // layout pass to update that window.
3510 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3511 }
Joe Onorato664644d2011-01-23 17:53:23 -08003512
Mike Lockwood28569302010-01-28 11:54:40 -05003513 // update since mAllowLockscreenWhenOn might have changed
3514 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003515 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003516 }
3517
Dianne Hackborn08743722009-12-21 12:16:51 -08003518 public boolean allowAppAnimationsLw() {
Craig Mautnerf03e4c52012-06-14 14:11:27 -07003519 if (mKeyguard != null && mKeyguard.isVisibleLw() && !mKeyguard.isAnimatingLw()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003520 // If keyguard is currently visible, no reason to animate
3521 // behind it.
3522 return false;
3523 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003524 return true;
3525 }
3526
Dianne Hackborndf89e652011-10-06 22:35:11 -07003527 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003528 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003529 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003530 // If the navigation bar has been hidden or shown, we need to do another
3531 // layout pass to update that window.
3532 return FINISH_LAYOUT_REDO_LAYOUT;
3533 }
3534 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003535 }
3536
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003537 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07003538 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003539 // do nothing if headless
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003540 if (mHeadless) return;
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003541
Jeff Brown46b9ac02010-04-22 18:58:52 -07003542 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003543 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3544 if (newLidState == mLidState) {
3545 return;
3546 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003547
Jeff Brownc458ce92012-04-30 14:58:40 -07003548 mLidState = newLidState;
3549 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003550 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003551
3552 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07003553 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07003554 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003555 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003556 }
3557 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003558
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003559 void setHdmiPlugged(boolean plugged) {
3560 if (mHdmiPlugged != plugged) {
3561 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003562 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003563 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003564 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003565 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003566 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003567 }
3568 }
3569
Joe Onoratoea495d42011-04-06 11:41:11 -07003570 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003571 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003572 // watch for HDMI plug messages if the hdmi switch exists
3573 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3574 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3575
Joe Onoratoea495d42011-04-06 11:41:11 -07003576 final String filename = "/sys/class/switch/hdmi/state";
3577 FileReader reader = null;
3578 try {
3579 reader = new FileReader(filename);
3580 char[] buf = new char[15];
3581 int n = reader.read(buf);
3582 if (n > 1) {
3583 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3584 }
3585 } catch (IOException ex) {
3586 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3587 } catch (NumberFormatException ex) {
3588 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3589 } finally {
3590 if (reader != null) {
3591 try {
3592 reader.close();
3593 } catch (IOException ex) {
3594 }
Joe Onoratodc100302011-01-11 17:07:41 -08003595 }
3596 }
3597 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07003598 // This dance forces the code in setHdmiPlugged to run.
3599 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
3600 mHdmiPlugged = !plugged;
3601 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08003602 }
3603
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003604 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003605 * @return Whether music is being played right now.
3606 */
3607 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07003608 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
3609 if (am == null) {
3610 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003611 return false;
3612 }
Eric Laurent413cb9d2009-07-17 11:52:43 -07003613 return am.isMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003614 }
3615
3616 /**
3617 * Tell the audio service to adjust the volume appropriate to the event.
3618 * @param keycode
3619 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04003620 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07003621 IAudioService audioService = getAudioService();
3622 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003623 return;
3624 }
3625 try {
3626 // since audio is playing, we shouldn't have to hold a wake lock
3627 // during the call, but we do it as a precaution for the rare possibility
3628 // that the music stops right before we call this
Jeff Brownb0418da2010-11-01 15:24:01 -07003629 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003630 mBroadcastWakeLock.acquire();
Jeff Brown4d396052010-10-29 21:50:21 -07003631 audioService.adjustStreamVolume(stream,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003632 keycode == KeyEvent.KEYCODE_VOLUME_UP
3633 ? AudioManager.ADJUST_RAISE
3634 : AudioManager.ADJUST_LOWER,
Dianne Hackbornba50b97c2013-04-30 15:04:46 -07003635 0,
3636 mContext.getBasePackageName());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003637 } catch (RemoteException e) {
3638 Log.w(TAG, "IAudioService.adjustStreamVolume() threw RemoteException " + e);
3639 } finally {
3640 mBroadcastWakeLock.release();
3641 }
3642 }
Jeff Brown4d396052010-10-29 21:50:21 -07003643
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07003644 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003645 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003646
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003647 final Runnable mScreenshotTimeout = new Runnable() {
3648 @Override public void run() {
3649 synchronized (mScreenshotLock) {
3650 if (mScreenshotConnection != null) {
3651 mContext.unbindService(mScreenshotConnection);
3652 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003653 }
Winson Chung9112ec32011-06-27 13:15:32 -07003654 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003655 }
3656 };
3657
3658 // Assume this is called from the Handler thread.
3659 private void takeScreenshot() {
3660 synchronized (mScreenshotLock) {
3661 if (mScreenshotConnection != null) {
3662 return;
3663 }
3664 ComponentName cn = new ComponentName("com.android.systemui",
3665 "com.android.systemui.screenshot.TakeScreenshotService");
3666 Intent intent = new Intent();
3667 intent.setComponent(cn);
3668 ServiceConnection conn = new ServiceConnection() {
3669 @Override
3670 public void onServiceConnected(ComponentName name, IBinder service) {
3671 synchronized (mScreenshotLock) {
3672 if (mScreenshotConnection != this) {
3673 return;
3674 }
3675 Messenger messenger = new Messenger(service);
3676 Message msg = Message.obtain(null, 1);
3677 final ServiceConnection myConn = this;
3678 Handler h = new Handler(mHandler.getLooper()) {
3679 @Override
3680 public void handleMessage(Message msg) {
3681 synchronized (mScreenshotLock) {
3682 if (mScreenshotConnection == myConn) {
3683 mContext.unbindService(mScreenshotConnection);
3684 mScreenshotConnection = null;
3685 mHandler.removeCallbacks(mScreenshotTimeout);
3686 }
3687 }
3688 }
3689 };
3690 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07003691 msg.arg1 = msg.arg2 = 0;
3692 if (mStatusBar != null && mStatusBar.isVisibleLw())
3693 msg.arg1 = 1;
3694 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
3695 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003696 try {
3697 messenger.send(msg);
3698 } catch (RemoteException e) {
3699 }
3700 }
3701 }
3702 @Override
3703 public void onServiceDisconnected(ComponentName name) {}
3704 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08003705 if (mContext.bindServiceAsUser(
3706 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003707 mScreenshotConnection = conn;
3708 mHandler.postDelayed(mScreenshotTimeout, 10000);
3709 }
3710 }
Winson Chung9112ec32011-06-27 13:15:32 -07003711 }
3712
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003713 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003714 @Override
Jeff Brown1f245102010-11-18 20:53:46 -08003715 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags, boolean isScreenOn) {
Jeff Brown96307042012-07-27 15:51:34 -07003716 if (!mSystemBooted) {
3717 // If we have not yet booted, don't let key events do anything.
3718 return 0;
3719 }
3720
Jeff Brown1f245102010-11-18 20:53:46 -08003721 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3722 final boolean canceled = event.isCanceled();
3723 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07003724
Jeff Brown3122e442010-10-11 23:32:49 -07003725 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07003726
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05003727 // If screen is off then we treat the case where the keyguard is open but hidden
3728 // the same as if it were open and in front.
3729 // This will prevent any keys other than the power button from waking the screen
3730 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08003731 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Mike Lockwood3a74bd32011-08-12 13:55:22 -07003732 (isScreenOn ?
Jim Miller5ecd8112013-01-09 18:50:26 -08003733 mKeyguardDelegate.isShowingAndNotHidden() :
3734 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003735
Jeff Brown96307042012-07-27 15:51:34 -07003736 if (keyCode == KeyEvent.KEYCODE_POWER) {
3737 policyFlags |= WindowManagerPolicy.FLAG_WAKE;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003738 }
Jeff Brown96307042012-07-27 15:51:34 -07003739 final boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE
3740 | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003741
Jeff Brown40013652012-05-16 21:22:36 -07003742 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003743 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown96307042012-07-27 15:51:34 -07003744 + " screenIsOn=" + isScreenOn + " keyguardActive=" + keyguardActive
3745 + " policyFlags=" + Integer.toHexString(policyFlags)
3746 + " isWakeKey=" + isWakeKey);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003747 }
3748
Jeff Brown98392ef2011-09-12 18:24:59 -07003749 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
3750 && event.getRepeatCount() == 0) {
Jeff Brown4d396052010-10-29 21:50:21 -07003751 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
3752 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003753
Jeff Brown4d396052010-10-29 21:50:21 -07003754 // Basic policy based on screen state and keyguard.
3755 // FIXME: This policy isn't quite correct. We shouldn't care whether the screen
3756 // is on or off, really. We should care about whether the device is in an
3757 // interactive state or is in suspend pretending to be "off".
3758 // The primary screen might be turned off due to proximity sensor or
3759 // because we are presenting media on an auxiliary screen or remotely controlling
3760 // the device some other way (which is why we have an exemption here for injected
3761 // events).
3762 int result;
Mike Lockwoodd747dc82011-09-13 16:28:22 -04003763 if ((isScreenOn && !mHeadless) || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003764 // When the screen is on or if the key is injected pass the key to the application.
3765 result = ACTION_PASS_TO_USER;
3766 } else {
3767 // When the screen is off and the key is not injected, determine whether
3768 // to wake the device but don't pass the key to the application.
3769 result = 0;
Jeff Brown1c2e4942012-11-06 16:32:01 -08003770 if (down && isWakeKey && isWakeKeyWhenScreenOff(keyCode)) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07003771 result |= ACTION_WAKE_UP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003772 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003773 }
3774
Justin Kohd378ad72013-04-01 12:18:26 -07003775 // If the key would be handled globally, just return the result, don't worry about special
3776 // key processing.
3777 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
3778 return result;
3779 }
3780
Jeff Brown4d396052010-10-29 21:50:21 -07003781 // Handle special keys.
3782 switch (keyCode) {
3783 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07003784 case KeyEvent.KEYCODE_VOLUME_UP:
3785 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003786 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
3787 if (down) {
3788 if (isScreenOn && !mVolumeDownKeyTriggered
3789 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3790 mVolumeDownKeyTriggered = true;
3791 mVolumeDownKeyTime = event.getDownTime();
3792 mVolumeDownKeyConsumedByScreenshotChord = false;
3793 cancelPendingPowerKeyAction();
3794 interceptScreenshotChord();
3795 }
3796 } else {
3797 mVolumeDownKeyTriggered = false;
3798 cancelPendingScreenshotChordAction();
3799 }
3800 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
3801 if (down) {
3802 if (isScreenOn && !mVolumeUpKeyTriggered
3803 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3804 mVolumeUpKeyTriggered = true;
3805 cancelPendingPowerKeyAction();
3806 cancelPendingScreenshotChordAction();
3807 }
3808 } else {
3809 mVolumeUpKeyTriggered = false;
3810 cancelPendingScreenshotChordAction();
3811 }
3812 }
Jeff Brown4d396052010-10-29 21:50:21 -07003813 if (down) {
3814 ITelephony telephonyService = getTelephonyService();
3815 if (telephonyService != null) {
3816 try {
3817 if (telephonyService.isRinging()) {
3818 // If an incoming call is ringing, either VOLUME key means
3819 // "silence ringer". We handle these keys here, rather than
3820 // in the InCallScreen, to make sure we'll respond to them
3821 // even if the InCallScreen hasn't come to the foreground yet.
3822 // Look for the DOWN event here, to agree with the "fallback"
3823 // behavior in the InCallScreen.
3824 Log.i(TAG, "interceptKeyBeforeQueueing:"
3825 + " VOLUME key-down while ringing: Silence ringer!");
3826
3827 // Silence the ringer. (It's safe to call this
3828 // even if the ringer has already been silenced.)
3829 telephonyService.silenceRinger();
3830
3831 // And *don't* pass this key thru to the current activity
3832 // (which is probably the InCallScreen.)
3833 result &= ~ACTION_PASS_TO_USER;
3834 break;
3835 }
3836 if (telephonyService.isOffhook()
3837 && (result & ACTION_PASS_TO_USER) == 0) {
3838 // If we are in call but we decided not to pass the key to
3839 // the application, handle the volume change here.
3840 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
3841 break;
3842 }
3843 } catch (RemoteException ex) {
3844 Log.w(TAG, "ITelephony threw RemoteException", ex);
3845 }
3846 }
3847
3848 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
3849 // If music is playing but we decided not to pass the key to the
3850 // application, handle the volume change here.
3851 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
3852 break;
3853 }
3854 }
3855 break;
3856 }
3857
3858 case KeyEvent.KEYCODE_ENDCALL: {
3859 result &= ~ACTION_PASS_TO_USER;
3860 if (down) {
3861 ITelephony telephonyService = getTelephonyService();
3862 boolean hungUp = false;
3863 if (telephonyService != null) {
3864 try {
3865 hungUp = telephonyService.endCall();
3866 } catch (RemoteException ex) {
3867 Log.w(TAG, "ITelephony threw RemoteException", ex);
3868 }
3869 }
3870 interceptPowerKeyDown(!isScreenOn || hungUp);
3871 } else {
3872 if (interceptPowerKeyUp(canceled)) {
3873 if ((mEndcallBehavior
3874 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
3875 if (goHome()) {
3876 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07003877 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003878 }
Jeff Brown4d396052010-10-29 21:50:21 -07003879 if ((mEndcallBehavior
3880 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown96307042012-07-27 15:51:34 -07003881 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
Jeff Brown4d396052010-10-29 21:50:21 -07003882 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003883 }
Jeff Brown4d396052010-10-29 21:50:21 -07003884 }
3885 break;
3886 }
3887
3888 case KeyEvent.KEYCODE_POWER: {
3889 result &= ~ACTION_PASS_TO_USER;
3890 if (down) {
John Spurlock27735a42013-08-14 17:57:38 -04003891 if (isScreenOn && isTransientNavigationAllowed(mLastSystemUiFlags)) {
John Spurlock34e13d92013-08-10 06:52:28 -04003892 mTransientNavigationConfirmation.unconfirmLastPackage();
3893 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003894 if (isScreenOn && !mPowerKeyTriggered
3895 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3896 mPowerKeyTriggered = true;
3897 mPowerKeyTime = event.getDownTime();
3898 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07003899 }
Winson Chung9112ec32011-06-27 13:15:32 -07003900
Jeff Brown4d396052010-10-29 21:50:21 -07003901 ITelephony telephonyService = getTelephonyService();
3902 boolean hungUp = false;
3903 if (telephonyService != null) {
3904 try {
3905 if (telephonyService.isRinging()) {
3906 // Pressing Power while there's a ringing incoming
3907 // call should silence the ringer.
3908 telephonyService.silenceRinger();
3909 } else if ((mIncallPowerBehavior
3910 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
3911 && telephonyService.isOffhook()) {
3912 // Otherwise, if "Power button ends call" is enabled,
3913 // the Power button will hang up any current active call.
3914 hungUp = telephonyService.endCall();
3915 }
3916 } catch (RemoteException ex) {
3917 Log.w(TAG, "ITelephony threw RemoteException", ex);
3918 }
3919 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003920 interceptPowerKeyDown(!isScreenOn || hungUp
3921 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003922 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003923 mPowerKeyTriggered = false;
3924 cancelPendingScreenshotChordAction();
3925 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown96307042012-07-27 15:51:34 -07003926 result = (result & ~ACTION_WAKE_UP) | ACTION_GO_TO_SLEEP;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003927 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003928 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07003929 }
3930 break;
3931 }
3932
3933 case KeyEvent.KEYCODE_MEDIA_PLAY:
3934 case KeyEvent.KEYCODE_MEDIA_PAUSE:
3935 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
3936 if (down) {
3937 ITelephony telephonyService = getTelephonyService();
3938 if (telephonyService != null) {
3939 try {
3940 if (!telephonyService.isIdle()) {
3941 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
3942 // to avoid music playback.
3943 break;
3944 }
3945 } catch (RemoteException ex) {
3946 Log.w(TAG, "ITelephony threw RemoteException", ex);
Jeff Brown3122e442010-10-11 23:32:49 -07003947 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003948 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003949 }
Jeff Brown4d396052010-10-29 21:50:21 -07003950 case KeyEvent.KEYCODE_HEADSETHOOK:
3951 case KeyEvent.KEYCODE_MUTE:
3952 case KeyEvent.KEYCODE_MEDIA_STOP:
3953 case KeyEvent.KEYCODE_MEDIA_NEXT:
3954 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
3955 case KeyEvent.KEYCODE_MEDIA_REWIND:
3956 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09003957 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
3958 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07003959 if ((result & ACTION_PASS_TO_USER) == 0) {
3960 // Only do this if we would otherwise not pass it to the user. In that
3961 // case, the PhoneWindow class will do the same thing, except it will
3962 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07003963 // Note that we need to make a copy of the key event here because the
3964 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07003965 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07003966 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
3967 new KeyEvent(event));
3968 msg.setAsynchronous(true);
3969 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07003970 }
3971 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003972 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003973
Jeff Brown4d396052010-10-29 21:50:21 -07003974 case KeyEvent.KEYCODE_CALL: {
3975 if (down) {
3976 ITelephony telephonyService = getTelephonyService();
3977 if (telephonyService != null) {
3978 try {
3979 if (telephonyService.isRinging()) {
3980 Log.i(TAG, "interceptKeyBeforeQueueing:"
3981 + " CALL key-down while ringing: Answer the call!");
3982 telephonyService.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003983
Jeff Brown4d396052010-10-29 21:50:21 -07003984 // And *don't* pass this key thru to the current activity
3985 // (which is presumably the InCallScreen.)
3986 result &= ~ACTION_PASS_TO_USER;
3987 }
3988 } catch (RemoteException ex) {
3989 Log.w(TAG, "ITelephony threw RemoteException", ex);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003990 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003991 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003992 }
Jeff Brown4d396052010-10-29 21:50:21 -07003993 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003994 }
3995 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003996 return result;
3997 }
3998
Jeff Brown1c2e4942012-11-06 16:32:01 -08003999 /**
4000 * When the screen is off we ignore some keys that might otherwise typically
4001 * be considered wake keys. We filter them out here.
4002 *
4003 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4004 * is always considered a wake key.
4005 */
4006 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4007 switch (keyCode) {
4008 // ignore volume keys unless docked
4009 case KeyEvent.KEYCODE_VOLUME_UP:
4010 case KeyEvent.KEYCODE_VOLUME_DOWN:
4011 case KeyEvent.KEYCODE_VOLUME_MUTE:
4012 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4013
4014 // ignore media and camera keys
4015 case KeyEvent.KEYCODE_MUTE:
4016 case KeyEvent.KEYCODE_HEADSETHOOK:
4017 case KeyEvent.KEYCODE_MEDIA_PLAY:
4018 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4019 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4020 case KeyEvent.KEYCODE_MEDIA_STOP:
4021 case KeyEvent.KEYCODE_MEDIA_NEXT:
4022 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4023 case KeyEvent.KEYCODE_MEDIA_REWIND:
4024 case KeyEvent.KEYCODE_MEDIA_RECORD:
4025 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004026 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004027 case KeyEvent.KEYCODE_CAMERA:
4028 return false;
4029 }
4030 return true;
4031 }
4032
4033
Jeff Brown56194eb2011-03-02 19:23:13 -08004034 /** {@inheritDoc} */
4035 @Override
4036 public int interceptMotionBeforeQueueingWhenScreenOff(int policyFlags) {
4037 int result = 0;
4038
4039 final boolean isWakeMotion = (policyFlags
4040 & (WindowManagerPolicy.FLAG_WAKE | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
4041 if (isWakeMotion) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07004042 result |= ACTION_WAKE_UP;
Jeff Brown56194eb2011-03-02 19:23:13 -08004043 }
4044 return result;
4045 }
4046
Jeff Brown40013652012-05-16 21:22:36 -07004047 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4048 if (DEBUG_INPUT) {
4049 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004050 }
4051
Jeff Brown40013652012-05-16 21:22:36 -07004052 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4053 if (DEBUG_INPUT) {
4054 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4055 }
4056
4057 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4058 mHavePendingMediaKeyRepeatWithWakeLock = false;
4059 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4060 }
4061
4062 dispatchMediaKeyWithWakeLockToAudioService(event);
4063
4064 if (event.getAction() == KeyEvent.ACTION_DOWN
4065 && event.getRepeatCount() == 0) {
4066 mHavePendingMediaKeyRepeatWithWakeLock = true;
4067
4068 Message msg = mHandler.obtainMessage(
4069 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4070 msg.setAsynchronous(true);
4071 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4072 } else {
4073 mBroadcastWakeLock.release();
4074 }
4075 }
4076
4077 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4078 mHavePendingMediaKeyRepeatWithWakeLock = false;
4079
4080 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4081 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4082 if (DEBUG_INPUT) {
4083 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4084 }
4085
4086 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4087 mBroadcastWakeLock.release();
4088 }
4089
4090 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4091 if (ActivityManagerNative.isSystemReady()) {
4092 IAudioService audioService = getAudioService();
4093 if (audioService != null) {
4094 try {
4095 audioService.dispatchMediaKeyEventUnderWakelock(event);
4096 } catch (RemoteException e) {
4097 Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
Jean-Michel Trivic6802222012-04-30 11:15:03 -07004098 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004099 }
4100 }
4101 }
4102
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004103 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004104 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004105 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004106 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4107 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4108 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004109 } else {
4110 try {
4111 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4112 ServiceManager.getService(Context.UI_MODE_SERVICE));
4113 mUiMode = uiModeService.getCurrentModeType();
4114 } catch (RemoteException e) {
4115 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004116 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004117 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004118 synchronized (mLock) {
4119 updateOrientationListenerLp();
4120 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004121 }
4122 };
4123
Jeff Brown6aaf2952012-10-05 16:01:08 -07004124 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4125 @Override
4126 public void onReceive(Context context, Intent intent) {
4127 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004128 if (mKeyguardDelegate != null) {
4129 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004130 }
4131 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004132 if (mKeyguardDelegate != null) {
4133 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004134 }
4135 }
4136 }
4137 };
4138
Christopher Tate5e08af02012-09-21 17:17:22 -07004139 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4140 @Override
4141 public void onReceive(Context context, Intent intent) {
4142 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4143 // tickle the settings observer: this first ensures that we're
4144 // observing the relevant settings for the newly-active user,
4145 // and then updates our own bookkeeping based on the now-
4146 // current user.
4147 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004148
4149 // force a re-application of focused window sysui visibility.
4150 // the window may never have been shown for this user
4151 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004152 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004153 mLastSystemUiFlags = 0;
4154 updateSystemUiVisibilityLw();
4155 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004156 }
4157 }
4158 };
4159
John Spurlocke1f366f2013-08-05 12:22:40 -04004160 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004161 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlock27735a42013-08-14 17:57:38 -04004162 boolean sb = mStatusBarController.checkShowTransientBarLw();
4163 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004164 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004165 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4166 if (sb ^ nb && barTarget != swipeTarget) {
4167 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004168 return;
4169 }
John Spurlock27735a42013-08-14 17:57:38 -04004170 if (sb) mStatusBarController.showTransient();
4171 if (nb) mNavigationBarController.showTransient();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004172 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004173 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004174 }
4175 }
4176
Jeff Brownc38c9be2012-10-04 13:16:19 -07004177 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004178 public void screenTurnedOff(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004179 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004180 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004181 mScreenOnEarly = false;
4182 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004183 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004184 if (mKeyguardDelegate != null) {
4185 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004186 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004187 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07004188 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004189 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004190 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004191 }
4192
Jeff Brownc38c9be2012-10-04 13:16:19 -07004193 @Override
Dianne Hackborn38e29a62011-09-18 14:43:08 -07004194 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004195 EventLog.writeEvent(70000, 1);
Dianne Hackborn40011092011-09-22 13:37:48 -07004196 if (false) {
4197 RuntimeException here = new RuntimeException("here");
4198 here.fillInStackTrace();
4199 Slog.i(TAG, "Screen turning on...", here);
4200 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004201
The Android Open Source Project0727d222009-03-11 12:11:58 -07004202 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004203 mScreenOnEarly = true;
The Android Open Source Project0727d222009-03-11 12:11:58 -07004204 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004205 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004206 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004207
Jeff Brownc38c9be2012-10-04 13:16:19 -07004208 waitForKeyguard(screenOnListener);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004209 }
4210
Jeff Brownc38c9be2012-10-04 13:16:19 -07004211 private void waitForKeyguard(final ScreenOnListener screenOnListener) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004212 if (mKeyguardDelegate != null) {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004213 if (screenOnListener != null) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004214 mKeyguardDelegate.onScreenTurnedOn(new KeyguardServiceDelegate.ShowListener() {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004215 @Override
4216 public void onShown(IBinder windowToken) {
4217 waitForKeyguardWindowDrawn(windowToken, screenOnListener);
4218 }
4219 });
4220 return;
4221 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -08004222 mKeyguardDelegate.onScreenTurnedOn(null);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004223 }
4224 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -08004225 Slog.i(TAG, "No keyguard interface!");
Jeff Brownc38c9be2012-10-04 13:16:19 -07004226 }
4227 finishScreenTurningOn(screenOnListener);
4228 }
4229
4230 private void waitForKeyguardWindowDrawn(IBinder windowToken,
4231 final ScreenOnListener screenOnListener) {
4232 if (windowToken != null) {
4233 try {
4234 if (mWindowManager.waitForWindowDrawn(
4235 windowToken, new IRemoteCallback.Stub() {
4236 @Override
4237 public void sendResult(Bundle data) {
4238 Slog.i(TAG, "Lock screen displayed!");
4239 finishScreenTurningOn(screenOnListener);
4240 }
4241 })) {
4242 return;
4243 }
4244 } catch (RemoteException ex) {
4245 // Can't happen in system process.
4246 }
4247 }
4248
4249 Slog.i(TAG, "No lock screen!");
4250 finishScreenTurningOn(screenOnListener);
4251 }
4252
4253 private void finishScreenTurningOn(ScreenOnListener screenOnListener) {
4254 synchronized (mLock) {
4255 mScreenOnFully = true;
4256 }
4257
Jeff Brown4fc45272012-10-10 18:28:14 -07004258 try {
4259 mWindowManager.setEventDispatching(true);
4260 } catch (RemoteException unhandled) {
4261 }
4262
Jeff Brownc38c9be2012-10-04 13:16:19 -07004263 if (screenOnListener != null) {
4264 screenOnListener.onScreenOn();
4265 }
4266 }
4267
4268 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004269 public boolean isScreenOnEarly() {
4270 return mScreenOnEarly;
4271 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004272
4273 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004274 public boolean isScreenOnFully() {
4275 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004276 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004277
Dianne Hackborn08743722009-12-21 12:16:51 -08004278 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004279 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004280 if (mKeyguardDelegate != null) {
4281 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004282 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004283 }
4284
4285 /** {@inheritDoc} */
4286 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004287 if (mKeyguardDelegate != null) {
4288 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004289 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004290 }
4291
Mike Lockwoodf7913302009-11-28 22:27:10 -05004292 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004293 if (mKeyguardDelegate == null) return false;
4294 return mKeyguardDelegate.isShowingAndNotHidden();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004295 }
4296
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004297
4298 /** {@inheritDoc} */
4299 public boolean isKeyguardLocked() {
4300 return keyguardOn();
4301 }
4302
4303 /** {@inheritDoc} */
4304 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004305 if (mKeyguardDelegate == null) return false;
4306 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004307 }
4308
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004309 /** {@inheritDoc} */
4310 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004311 if (mKeyguardDelegate == null) return false;
4312 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004313 }
4314
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004315 public void dismissKeyguardLw() {
Jim Miller195b5512013-02-28 03:35:57 -08004316 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004317 mHandler.post(new Runnable() {
4318 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004319 if (mKeyguardDelegate.isDismissable()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004320 // Can we just finish the keyguard straight away?
Jim Miller5ecd8112013-01-09 18:50:26 -08004321 mKeyguardDelegate.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004322 } else {
4323 // ask the keyguard to prompt the user to authenticate if necessary
Jim Miller5ecd8112013-01-09 18:50:26 -08004324 mKeyguardDelegate.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004325 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004326 }
4327 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004328 }
4329 }
4330
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004331 void sendCloseSystemWindows() {
4332 sendCloseSystemWindows(mContext, null);
4333 }
4334
4335 void sendCloseSystemWindows(String reason) {
4336 sendCloseSystemWindows(mContext, reason);
4337 }
4338
4339 static void sendCloseSystemWindows(Context context, String reason) {
4340 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004341 try {
4342 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4343 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004344 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004345 }
4346 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004347
Jeff Brown01a98dd2011-09-20 15:08:29 -07004348 @Override
4349 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004350 if (false) {
4351 Slog.v(TAG, "rotationForOrientationLw(orient="
4352 + orientation + ", last=" + lastRotation
4353 + "); user=" + mUserRotation + " "
4354 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4355 ? "USER_ROTATION_LOCKED" : "")
4356 );
4357 }
4358
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004359 if (mForceDefaultOrientation) {
4360 return Surface.ROTATION_0;
4361 }
4362
The Android Open Source Project0727d222009-03-11 12:11:58 -07004363 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004364 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4365 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004366 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004367 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004368
Jeff Browndec6cf42011-11-15 14:08:20 -08004369 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004370 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004371 // Ignore sensor when lid switch is open and rotation is forced.
4372 preferredRotation = mLidOpenRotation;
4373 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004374 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004375 // Ignore sensor when in car dock unless explicitly enabled.
4376 // This case can override the behavior of NOSENSOR, and can also
4377 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004378 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004379 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004380 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4381 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4382 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004383 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004384 // Ignore sensor when in desk dock unless explicitly enabled.
4385 // This case can override the behavior of NOSENSOR, and can also
4386 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004387 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004388 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004389 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4390 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004391 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004392 preferredRotation = mDemoHdmiRotation;
4393 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4394 && mUndockedHdmiRotation >= 0) {
4395 // Ignore sensor when plugged into HDMI and an undocked orientation has
4396 // been specified in the configuration (only for legacy devices without
4397 // full multi-display support).
4398 // Note that the dock orientation overrides the HDMI orientation.
4399 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004400 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4401 // Application just wants to remain locked in the last rotation.
4402 preferredRotation = lastRotation;
Jeff Brown207673cd2012-06-05 17:47:11 -07004403 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004404 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004405 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4406 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4407 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4408 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004409 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4410 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4411 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4412 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4413 // Otherwise, use sensor only if requested by the application or enabled
4414 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004415 if (mAllowAllRotations < 0) {
4416 // Can't read this during init() because the context doesn't
4417 // have display metrics at that time so we cannot determine
4418 // tablet vs. phone then.
4419 mAllowAllRotations = mContext.getResources().getBoolean(
4420 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4421 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004422 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004423 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004424 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4425 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004426 preferredRotation = sensorRotation;
4427 } else {
4428 preferredRotation = lastRotation;
4429 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004430 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4431 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4432 // Apply rotation lock. Does not apply to NOSENSOR.
4433 // The idea is that the user rotation expresses a weak preference for the direction
4434 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4435 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004436 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004437 } else {
4438 // No overriding preference.
4439 // We will do exactly what the application asked us to do.
4440 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004441 }
4442
Dianne Hackborne5439f22010-10-02 16:53:50 -07004443 switch (orientation) {
4444 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004445 // Return portrait unless overridden.
4446 if (isAnyPortrait(preferredRotation)) {
4447 return preferredRotation;
4448 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004449 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004450
Jeff Brown01a98dd2011-09-20 15:08:29 -07004451 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004452 // Return landscape unless overridden.
4453 if (isLandscapeOrSeascape(preferredRotation)) {
4454 return preferredRotation;
4455 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004456 return mLandscapeRotation;
4457
4458 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004459 // Return reverse portrait unless overridden.
4460 if (isAnyPortrait(preferredRotation)) {
4461 return preferredRotation;
4462 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004463 return mUpsideDownRotation;
4464
4465 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004466 // Return seascape unless overridden.
4467 if (isLandscapeOrSeascape(preferredRotation)) {
4468 return preferredRotation;
4469 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004470 return mSeascapeRotation;
4471
4472 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004473 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004474 // Return either landscape rotation.
4475 if (isLandscapeOrSeascape(preferredRotation)) {
4476 return preferredRotation;
4477 }
4478 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004479 return lastRotation;
4480 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004481 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004482
Jeff Brown01a98dd2011-09-20 15:08:29 -07004483 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004484 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004485 // Return either portrait rotation.
4486 if (isAnyPortrait(preferredRotation)) {
4487 return preferredRotation;
4488 }
4489 if (isAnyPortrait(lastRotation)) {
4490 return lastRotation;
4491 }
4492 return mPortraitRotation;
4493
4494 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004495 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4496 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004497 if (preferredRotation >= 0) {
4498 return preferredRotation;
4499 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004500 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004501 }
4502 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004503 }
4504
Jeff Brown01a98dd2011-09-20 15:08:29 -07004505 @Override
4506 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4507 switch (orientation) {
4508 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4509 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4510 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4511 return isAnyPortrait(rotation);
4512
4513 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4514 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4515 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4516 return isLandscapeOrSeascape(rotation);
4517
4518 default:
4519 return true;
4520 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004521 }
4522
Jeff Brownc0347aa2011-09-23 17:26:09 -07004523 @Override
4524 public void setRotationLw(int rotation) {
4525 mOrientationListener.setCurrentRotation(rotation);
4526 }
4527
Jeff Brown01a98dd2011-09-20 15:08:29 -07004528 private boolean isLandscapeOrSeascape(int rotation) {
4529 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004530 }
4531
Jeff Brown01a98dd2011-09-20 15:08:29 -07004532 private boolean isAnyPortrait(int rotation) {
4533 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004534 }
4535
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004536 public int getUserRotationMode() {
4537 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07004538 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
4539 WindowManagerPolicy.USER_ROTATION_FREE :
4540 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004541 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004542
4543 // User rotation: to be used when all else fails in assigning an orientation to the device
4544 public void setUserRotationMode(int mode, int rot) {
4545 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004546
4547 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004548 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004549 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004550 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004551 rot,
4552 UserHandle.USER_CURRENT);
4553 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004554 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004555 0,
4556 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004557 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004558 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004559 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004560 1,
4561 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004562 }
4563 }
4564
Jeff Brownac143512012-04-05 18:57:33 -07004565 public void setSafeMode(boolean safeMode) {
4566 mSafeMode = safeMode;
4567 performHapticFeedbackLw(null, safeMode
4568 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4569 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004570 }
Craig Mautnereda67292013-04-28 13:50:14 -07004571
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004572 static long[] getLongIntArray(Resources r, int resid) {
4573 int[] ar = r.getIntArray(resid);
4574 if (ar == null) {
4575 return null;
4576 }
4577 long[] out = new long[ar.length];
4578 for (int i=0; i<ar.length; i++) {
4579 out[i] = ar[i];
4580 }
4581 return out;
4582 }
Craig Mautnereda67292013-04-28 13:50:14 -07004583
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004584 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004585 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004586 public void systemReady() {
Jim Miller195b5512013-02-28 03:35:57 -08004587 if (!mHeadless) {
4588 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
Jim Miller5ecd8112013-01-09 18:50:26 -08004589 mKeyguardDelegate.onSystemReady();
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004590 }
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004591 synchronized (mLock) {
4592 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08004593 mSystemReady = true;
4594 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07004595 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08004596 public void run() {
4597 updateSettings();
4598 }
4599 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004600 }
4601 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07004602
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004603 /** {@inheritDoc} */
4604 public void systemBooted() {
4605 synchronized (mLock) {
4606 mSystemBooted = true;
4607 }
4608 }
4609
Dianne Hackborn661cd522011-08-22 00:26:20 -07004610 ProgressDialog mBootMsgDialog = null;
4611
4612 /** {@inheritDoc} */
4613 public void showBootMessage(final CharSequence msg, final boolean always) {
Mike Lockwoodaa5bf142011-09-21 13:03:40 -04004614 if (mHeadless) return;
Dianne Hackborn661cd522011-08-22 00:26:20 -07004615 mHandler.post(new Runnable() {
4616 @Override public void run() {
4617 if (mBootMsgDialog == null) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07004618 mBootMsgDialog = new ProgressDialog(mContext) {
4619 // This dialog will consume all events coming in to
4620 // it, to avoid it trying to do things too early in boot.
4621 @Override public boolean dispatchKeyEvent(KeyEvent event) {
4622 return true;
4623 }
4624 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
4625 return true;
4626 }
4627 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
4628 return true;
4629 }
4630 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
4631 return true;
4632 }
4633 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
4634 return true;
4635 }
4636 @Override public boolean dispatchPopulateAccessibilityEvent(
4637 AccessibilityEvent event) {
4638 return true;
4639 }
4640 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07004641 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
4642 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
4643 mBootMsgDialog.setIndeterminate(true);
4644 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004645 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004646 mBootMsgDialog.getWindow().addFlags(
4647 WindowManager.LayoutParams.FLAG_DIM_BEHIND
4648 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
4649 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08004650 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
4651 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
4652 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004653 mBootMsgDialog.setCancelable(false);
4654 mBootMsgDialog.show();
4655 }
4656 mBootMsgDialog.setMessage(msg);
4657 }
4658 });
4659 }
4660
4661 /** {@inheritDoc} */
4662 public void hideBootMessages() {
4663 mHandler.post(new Runnable() {
4664 @Override public void run() {
4665 if (mBootMsgDialog != null) {
4666 mBootMsgDialog.dismiss();
4667 mBootMsgDialog = null;
4668 }
4669 }
4670 });
4671 }
4672
Mike Lockwood28569302010-01-28 11:54:40 -05004673 /** {@inheritDoc} */
4674 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004675 // ***************************************
4676 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
4677 // ***************************************
4678 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
4679 // WITH ITS LOCKS HELD.
4680 //
4681 // This code must be VERY careful about the locks
4682 // it acquires.
4683 // In fact, the current code acquires way too many,
4684 // and probably has lurking deadlocks.
4685
Mike Lockwood28569302010-01-28 11:54:40 -05004686 synchronized (mScreenLockTimeout) {
4687 if (mLockScreenTimerActive) {
4688 // reset the timer
4689 mHandler.removeCallbacks(mScreenLockTimeout);
4690 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4691 }
4692 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04004693 }
4694
Adam Cohenf7522022012-10-03 20:03:18 -07004695 class ScreenLockTimeout implements Runnable {
4696 Bundle options;
4697
4698 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05004699 public void run() {
4700 synchronized (this) {
4701 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08004702 if (mKeyguardDelegate != null) {
4703 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004704 }
Mike Lockwood28569302010-01-28 11:54:40 -05004705 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07004706 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05004707 }
4708 }
Mike Lockwood28569302010-01-28 11:54:40 -05004709
Adam Cohenf7522022012-10-03 20:03:18 -07004710 public void setLockOptions(Bundle options) {
4711 this.options = options;
4712 }
4713 }
4714
4715 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
4716
4717 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08004718 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
4719 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07004720 if (options != null) {
4721 // In case multiple calls are made to lockNow, we don't wipe out the options
4722 // until the runnable actually executes.
4723 mScreenLockTimeout.setLockOptions(options);
4724 }
Jim Miller93c518e2012-01-17 15:55:31 -08004725 mHandler.post(mScreenLockTimeout);
4726 }
4727
Mike Lockwood28569302010-01-28 11:54:40 -05004728 private void updateLockScreenTimeout() {
4729 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004730 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08004731 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05004732 if (mLockScreenTimerActive != enable) {
4733 if (enable) {
4734 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
4735 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4736 } else {
4737 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
4738 mHandler.removeCallbacks(mScreenLockTimeout);
4739 }
4740 mLockScreenTimerActive = enable;
4741 }
4742 }
4743 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004744
4745 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004746 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004747 public void enableScreenAfterBoot() {
4748 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07004749 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004750 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004751 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07004752
Jeff Brownc458ce92012-04-30 14:58:40 -07004753 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07004754 if (mLidState == LID_CLOSED && mLidControlsSleep) {
4755 mPowerManager.goToSleep(SystemClock.uptimeMillis());
4756 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004757 }
4758
4759 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004760 try {
4761 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004762 mWindowManager.updateRotation(alwaysSendConfiguration, false);
4763 } catch (RemoteException e) {
4764 // Ignore
4765 }
4766 }
4767
4768 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
4769 try {
4770 //set orientation on WindowManager
4771 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004772 } catch (RemoteException e) {
4773 // Ignore
4774 }
4775 }
4776
Daniel Sandler6396c722013-04-16 20:19:09 -04004777 /**
4778 * Return an Intent to launch the currently active dock app as home. Returns
4779 * null if the standard home should be launched, which is the case if any of the following is
4780 * true:
4781 * <ul>
4782 * <li>The device is not in either car mode or desk mode
4783 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
4784 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
4785 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
4786 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
4787 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07004788 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04004789 */
4790 Intent createHomeDockIntent() {
4791 Intent intent = null;
4792
4793 // What home does is based on the mode, not the dock state. That
4794 // is, when in car mode you should be taken to car home regardless
4795 // of whether we are actually in a car dock.
4796 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
4797 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
4798 intent = mCarDockIntent;
4799 }
4800 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
4801 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
4802 intent = mDeskDockIntent;
4803 }
4804 }
4805
4806 if (intent == null) {
4807 return null;
4808 }
4809
4810 ActivityInfo ai = null;
4811 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
4812 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04004813 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
4814 getCurrentUserId());
Daniel Sandler6396c722013-04-16 20:19:09 -04004815 if (info != null) {
4816 ai = info.activityInfo;
4817 }
4818 if (ai != null
4819 && ai.metaData != null
4820 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
4821 intent = new Intent(intent);
4822 intent.setClassName(ai.packageName, ai.name);
4823 return intent;
4824 }
4825
4826 return null;
4827 }
4828
John Spurlockf56bef12013-07-09 09:51:46 -04004829 private int getCurrentUserId() {
4830 try {
4831 UserInfo user = ActivityManagerNative.getDefault().getCurrentUser();
4832 return user != null ? user.id : UserHandle.USER_NULL;
4833 } catch (RemoteException e) {
4834 // noop
4835 }
4836 return UserHandle.USER_NULL;
4837 }
4838
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004839 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04004840 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04004841
4842 Intent dock = createHomeDockIntent();
4843 if (dock != null) {
4844 try {
4845 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
4846 return;
4847 } catch (ActivityNotFoundException e) {
4848 }
4849 }
4850
Dianne Hackbornd8883992012-09-07 15:58:52 -07004851 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004852 }
Craig Mautnereda67292013-04-28 13:50:14 -07004853
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004854 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004855 * goes to the home screen
4856 * @return whether it did anything
4857 */
4858 boolean goHome() {
4859 if (false) {
4860 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07004861 try {
4862 ActivityManagerNative.getDefault().stopAppSwitches();
4863 } catch (RemoteException e) {
4864 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004865 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004866 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004867 } else {
4868 // This code brings home to the front or, if it is already
4869 // at the front, puts the device to sleep.
4870 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08004871 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
4872 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
4873 Log.d(TAG, "UTS-TEST-MODE");
4874 } else {
4875 ActivityManagerNative.getDefault().stopAppSwitches();
4876 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04004877 Intent dock = createHomeDockIntent();
4878 if (dock != null) {
4879 int result = ActivityManagerNative.getDefault()
4880 .startActivityAsUser(null, null, dock,
4881 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
4882 null, null, 0,
4883 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
4884 null, null, null, UserHandle.USER_CURRENT);
4885 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
4886 return false;
4887 }
4888 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004889 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004890 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004891 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004892 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07004893 null, null, 0,
4894 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004895 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07004896 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004897 return false;
4898 }
4899 } catch (RemoteException ex) {
4900 // bummer, the activity manager, which is in this process, is dead
4901 }
4902 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004903 return true;
4904 }
Craig Mautnereda67292013-04-28 13:50:14 -07004905
4906 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07004907 public void setCurrentOrientationLw(int newOrientation) {
4908 synchronized (mLock) {
4909 if (newOrientation != mCurrentAppOrientation) {
4910 mCurrentAppOrientation = newOrientation;
4911 updateOrientationListenerLp();
4912 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004913 }
4914 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004915
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07004916 private void performAuditoryFeedbackForAccessibilityIfNeed() {
4917 if (!isGlobalAccessibilityGestureEnabled()) {
4918 return;
4919 }
4920 AudioManager audioManager = (AudioManager) mContext.getSystemService(
4921 Context.AUDIO_SERVICE);
4922 if (audioManager.isSilentMode()) {
4923 return;
4924 }
4925 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
4926 Settings.System.DEFAULT_NOTIFICATION_URI);
4927 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
4928 ringTone.play();
4929 }
Craig Mautnereda67292013-04-28 13:50:14 -07004930
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07004931 private boolean isGlobalAccessibilityGestureEnabled() {
4932 return Settings.Global.getInt(mContext.getContentResolver(),
4933 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
4934 }
4935
Craig Mautnereda67292013-04-28 13:50:14 -07004936 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07004937 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07004938 if (!mVibrator.hasVibrator()) {
4939 return false;
4940 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004941 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
4942 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jim Miller5ecd8112013-01-09 18:50:26 -08004943 if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotHidden())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004944 return false;
4945 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004946 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004947 switch (effectId) {
4948 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004949 pattern = mLongPressVibePattern;
4950 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004951 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004952 pattern = mVirtualKeyVibePattern;
4953 break;
4954 case HapticFeedbackConstants.KEYBOARD_TAP:
4955 pattern = mKeyboardTapVibePattern;
4956 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004957 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004958 pattern = mSafeModeDisabledVibePattern;
4959 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004960 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08004961 pattern = mSafeModeEnabledVibePattern;
4962 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08004963 default:
4964 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004965 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004966 int owningUid;
4967 String owningPackage;
4968 if (win != null) {
4969 owningUid = win.getOwningUid();
4970 owningPackage = win.getOwningPackage();
4971 } else {
4972 owningUid = android.os.Process.myUid();
4973 owningPackage = mContext.getBasePackageName();
4974 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08004975 if (pattern.length == 1) {
4976 // One-shot vibration
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004977 mVibrator.vibrate(owningUid, owningPackage, pattern[0]);
Amith Yamasanic33cb712010-02-10 15:21:49 -08004978 } else {
4979 // Pattern vibration
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004980 mVibrator.vibrate(owningUid, owningPackage, pattern, -1);
Amith Yamasanic33cb712010-02-10 15:21:49 -08004981 }
4982 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004983 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004984
4985 @Override
4986 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04004987 }
4988
Jeff Brownc38c9be2012-10-04 13:16:19 -07004989 @Override
4990 public void keepScreenOnStoppedLw() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004991 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotHidden()) {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004992 long curTime = SystemClock.uptimeMillis();
Jim Miller25190572013-02-28 17:36:24 -08004993 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004994 }
4995 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04004996
Dianne Hackborndf89e652011-10-06 22:35:11 -07004997 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08004998 // If there is no window focused, there will be nobody to handle the events
4999 // anyway, so just hang on in whatever state we're in until things settle down.
Dianne Hackborndf89e652011-10-06 22:35:11 -07005000 if (mFocusedWindow == null) {
5001 return 0;
5002 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005003 if (mFocusedWindow.getAttrs().type == TYPE_KEYGUARD && mHideLockScreen == true) {
5004 // 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
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005013 int tmpVisibility = mFocusedWindow.getSystemUiVisibility()
Dianne Hackborne26ab702011-10-16 13:21:33 -07005014 & ~mResettingSystemUiFlags
5015 & ~mForceClearedSystemUiFlags;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005016 if (mForcingShowNavBar && mFocusedWindow.getSurfaceLayer() < mForcingShowNavBarLayer) {
5017 tmpVisibility &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
5018 }
John Spurlockb77edbf2013-08-21 21:04:12 -04005019 final int visibility = updateSystemBarsLw(mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005020 final int diff = visibility ^ mLastSystemUiFlags;
Dianne Hackborn73ab6a42011-12-13 11:16:23 -08005021 final boolean needsMenu = mFocusedWindow.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005022 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
5023 && mFocusedApp == mFocusedWindow.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;
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005028 mFocusedApp = mFocusedWindow.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 Spurlockb77edbf2013-08-21 21:04:12 -04005047 private int updateSystemBarsLw(int oldVis, int vis) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005048 if (ImmersiveModeTesting.enabled) {
5049 vis = ImmersiveModeTesting.applyForced(mFocusedWindow, vis);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005050 }
John Spurlock27735a42013-08-14 17:57:38 -04005051
5052 // prevent status bar interaction from clearing certain flags
John Spurlocke1f366f2013-08-05 12:22:40 -04005053 boolean statusBarHasFocus = mFocusedWindow.getAttrs().type == TYPE_STATUS_BAR;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005054 if (statusBarHasFocus) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005055 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5056 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlocke1f366f2013-08-05 12:22:40 -04005057 | View.SYSTEM_UI_FLAG_ALLOW_TRANSIENT;
5058 vis = (vis & ~flags) | (mLastSystemUiFlags & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005059 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005060
John Spurlock27735a42013-08-14 17:57:38 -04005061 // update status bar
5062 boolean transientAllowed =
5063 (vis & View.SYSTEM_UI_FLAG_ALLOW_TRANSIENT) != 0;
5064 boolean hideStatusBarWM =
5065 (mFocusedWindow.getAttrs().flags
5066 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5067 boolean hideStatusBarSysui =
5068 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005069
John Spurlock27735a42013-08-14 17:57:38 -04005070 boolean transientStatusBarAllowed =
5071 mStatusBar != null && (
5072 hideStatusBarWM
5073 || (hideStatusBarSysui && transientAllowed)
5074 || statusBarHasFocus);
5075
5076 if (mStatusBarController.isTransientShowing()
5077 && !transientStatusBarAllowed && hideStatusBarSysui) {
5078 // clear the clearable flags instead
5079 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5080 if (newVal != mResettingSystemUiFlags) {
5081 mResettingSystemUiFlags = newVal;
5082 mWindowManagerFuncs.reevaluateStatusBarVisibility();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005083 }
5084 }
John Spurlock27735a42013-08-14 17:57:38 -04005085
5086 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5087
5088 // update navigation bar
5089 boolean oldTransientNav = isTransientNavigationAllowed(oldVis);
5090 boolean isTransientNav = isTransientNavigationAllowed(vis);
John Spurlock34e13d92013-08-10 06:52:28 -04005091 if (mFocusedWindow != null && oldTransientNav != isTransientNav) {
5092 final int uid = getCurrentUserId();
5093 final String pkg = mFocusedWindow.getOwningPackage();
5094 mTransientNavigationConfirmation.transientNavigationChanged(uid, pkg, isTransientNav);
5095 }
John Spurlock27735a42013-08-14 17:57:38 -04005096 vis = mNavigationBarController.updateVisibilityLw(isTransientNav, oldVis, vis);
5097
John Spurlock5b9145b2013-08-20 15:13:47 -04005098 // don't send low profile updates if the system bars are hidden
5099 if (mStatusBarController.isHidden() && mNavigationBarController.isHidden()) {
5100 vis &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
5101 }
John Spurlocke1f366f2013-08-05 12:22:40 -04005102 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005103 }
5104
John Spurlock27735a42013-08-14 17:57:38 -04005105 private boolean isTransientNavigationAllowed(int vis) {
John Spurlock34e13d92013-08-10 06:52:28 -04005106 return mNavigationBar != null
5107 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
5108 && (vis & View.SYSTEM_UI_FLAG_ALLOW_TRANSIENT) != 0;
5109 }
5110
John Spurlocke1f366f2013-08-05 12:22:40 -04005111 // Temporary helper that allows testing immersive mode on existing apps
5112 // TODO remove
5113 private static final class ImmersiveModeTesting {
5114 static String ENABLED_SETTING = "immersive_mode_testing_enabled";
John Spurlock245fd012013-05-31 10:31:04 -04005115 static boolean enabled = false;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005116 private static final HashSet<String> sForced = new HashSet<String>();
5117
5118 private static String parseActivity(WindowState win) {
5119 if (win != null && win.getAppToken() != null) {
5120 String str = win.getAppToken().toString();
5121 int end = str.lastIndexOf(' ');
5122 if (end > 0) {
5123 int start = str.lastIndexOf(' ', end - 1);
5124 if (start > -1) {
5125 return str.substring(start + 1, end);
5126 }
5127 }
5128 }
5129 return null;
5130 }
5131
5132 public static int applyForced(WindowState focused, int vis) {
5133 if (sForced.contains(parseActivity(focused))) {
5134 vis |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
5135 View.SYSTEM_UI_FLAG_FULLSCREEN |
John Spurlocke1f366f2013-08-05 12:22:40 -04005136 View.SYSTEM_UI_FLAG_ALLOW_TRANSIENT;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005137 }
5138 return vis;
5139 }
5140
John Spurlocke1f366f2013-08-05 12:22:40 -04005141 public static void toggleForceImmersiveMode(WindowState focused, Context context) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005142 String activity = parseActivity(focused);
5143 if (activity != null) {
5144 String action;
5145 if (sForced.contains(activity)) {
5146 sForced.remove(activity);
John Spurlocke1f366f2013-08-05 12:22:40 -04005147 action = "Force immersive mode disabled";
John Spurlockad3e6cb2013-04-30 08:47:43 -04005148 } else {
5149 sForced.add(activity);
John Spurlocke1f366f2013-08-05 12:22:40 -04005150 action = "Force immersive mode enabled";
John Spurlockad3e6cb2013-04-30 08:47:43 -04005151 }
5152 android.widget.Toast.makeText(context,
5153 action + " for " + activity, android.widget.Toast.LENGTH_SHORT).show();
5154 }
5155 }
5156 }
5157
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005158 // Use this instead of checking config_showNavigationBar so that it can be consistently
5159 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005160 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005161 public boolean hasNavigationBar() {
5162 return mHasNavigationBar;
5163 }
5164
satok1bc0a492012-04-25 22:47:12 +09005165 @Override
5166 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5167 mLastInputMethodWindow = ime;
5168 mLastInputMethodTargetWindow = target;
5169 }
5170
Craig Mautnerf1b67412012-09-19 13:18:29 -07005171 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005172 public void setCurrentUserLw(int newUserId) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005173 if (mKeyguardDelegate != null) {
5174 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005175 }
John Spurlock13451a22012-09-28 14:40:41 -04005176 if (mStatusBarService != null) {
5177 try {
5178 mStatusBarService.setCurrentUser(newUserId);
5179 } catch (RemoteException e) {
5180 // oh well
5181 }
5182 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005183 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005184 }
5185
5186 @Override
Jim Miller4eeb4f62012-11-08 00:04:29 -08005187 public void showAssistant() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005188 mKeyguardDelegate.showAssistant();
Jim Miller4eeb4f62012-11-08 00:04:29 -08005189 }
5190
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005191 @Override
5192 public boolean canMagnifyWindow(int windowType) {
5193 switch (windowType) {
5194 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5195 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5196 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5197 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5198 return false;
5199 }
5200 }
5201 return true;
5202 }
5203
5204 @Override
5205 public boolean isTopLevelWindow(int windowType) {
5206 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5207 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5208 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5209 }
5210 return true;
5211 }
5212
Jim Miller4eeb4f62012-11-08 00:04:29 -08005213 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005214 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005215 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005216 pw.print(" mSystemReady="); pw.print(mSystemReady);
5217 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005218 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005219 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5220 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005221 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5222 || mForceClearedSystemUiFlags != 0) {
5223 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5224 pw.print(Integer.toHexString(mLastSystemUiFlags));
5225 pw.print(" mResettingSystemUiFlags=0x");
5226 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5227 pw.print(" mForceClearedSystemUiFlags=0x");
5228 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005229 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005230 if (mLastFocusNeedsMenu) {
5231 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5232 pw.println(mLastFocusNeedsMenu);
5233 }
Daniel Sandler6396c722013-04-16 20:19:09 -04005234 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5235 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005236 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5237 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5238 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5239 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005240 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005241 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005242 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5243 pw.print(mCarDockEnablesAccelerometer);
5244 pw.print(" mDeskDockEnablesAccelerometer=");
5245 pw.println(mDeskDockEnablesAccelerometer);
5246 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5247 pw.print(mLidKeyboardAccessibility);
5248 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005249 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
5250 pw.print(prefix); pw.print("mLongPressOnPowerBehavior=");
5251 pw.print(mLongPressOnPowerBehavior);
5252 pw.print(" mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005253 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5254 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005255 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005256 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5257 pw.print(","); pw.print(mOverscanScreenTop);
5258 pw.print(") "); pw.print(mOverscanScreenWidth);
5259 pw.print("x"); pw.println(mOverscanScreenHeight);
5260 if (mOverscanLeft != 0 || mOverscanTop != 0
5261 || mOverscanRight != 0 || mOverscanBottom != 0) {
5262 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5263 pw.print(" top="); pw.print(mOverscanTop);
5264 pw.print(" right="); pw.print(mOverscanRight);
5265 pw.print(" bottom="); pw.println(mOverscanBottom);
5266 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005267 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5268 pw.print(mRestrictedOverscanScreenLeft);
5269 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5270 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5271 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005272 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5273 pw.print(","); pw.print(mUnrestrictedScreenTop);
5274 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5275 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5276 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5277 pw.print(","); pw.print(mRestrictedScreenTop);
5278 pw.print(") "); pw.print(mRestrictedScreenWidth);
5279 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005280 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5281 pw.print(","); pw.print(mStableFullscreenTop);
5282 pw.print(")-("); pw.print(mStableFullscreenRight);
5283 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005284 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5285 pw.print(","); pw.print(mStableTop);
5286 pw.print(")-("); pw.print(mStableRight);
5287 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005288 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5289 pw.print(","); pw.print(mSystemTop);
5290 pw.print(")-("); pw.print(mSystemRight);
5291 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005292 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5293 pw.print(","); pw.print(mCurTop);
5294 pw.print(")-("); pw.print(mCurRight);
5295 pw.print(","); pw.print(mCurBottom); pw.println(")");
5296 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5297 pw.print(","); pw.print(mContentTop);
5298 pw.print(")-("); pw.print(mContentRight);
5299 pw.print(","); pw.print(mContentBottom); pw.println(")");
5300 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5301 pw.print(","); pw.print(mDockTop);
5302 pw.print(")-("); pw.print(mDockRight);
5303 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005304 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5305 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005306 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5307 pw.print(" mShowingDream="); pw.print(mShowingDream);
5308 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005309 if (mLastInputMethodWindow != null) {
5310 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5311 pw.println(mLastInputMethodWindow);
5312 }
5313 if (mLastInputMethodTargetWindow != null) {
5314 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5315 pw.println(mLastInputMethodTargetWindow);
5316 }
5317 if (mStatusBar != null) {
5318 pw.print(prefix); pw.print("mStatusBar=");
5319 pw.println(mStatusBar);
5320 }
5321 if (mNavigationBar != null) {
5322 pw.print(prefix); pw.print("mNavigationBar=");
5323 pw.println(mNavigationBar);
5324 }
5325 if (mKeyguard != null) {
5326 pw.print(prefix); pw.print("mKeyguard=");
5327 pw.println(mKeyguard);
5328 }
5329 if (mFocusedWindow != null) {
5330 pw.print(prefix); pw.print("mFocusedWindow=");
5331 pw.println(mFocusedWindow);
5332 }
5333 if (mFocusedApp != null) {
5334 pw.print(prefix); pw.print("mFocusedApp=");
5335 pw.println(mFocusedApp);
5336 }
5337 if (mWinDismissingKeyguard != null) {
5338 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5339 pw.println(mWinDismissingKeyguard);
5340 }
5341 if (mTopFullscreenOpaqueWindowState != null) {
5342 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5343 pw.println(mTopFullscreenOpaqueWindowState);
5344 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005345 if (mForcingShowNavBar) {
5346 pw.print(prefix); pw.print("mForcingShowNavBar=");
5347 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5348 pw.println(mForcingShowNavBarLayer);
5349 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005350 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005351 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005352 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5353 pw.print(" mForceStatusBarFromKeyguard=");
5354 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005355 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005356 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005357 pw.print(" mHomePressed="); pw.println(mHomePressed);
5358 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5359 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5360 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5361 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5362 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5363 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5364 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5365 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5366 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5367 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005368 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5369 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5370 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
John Spurlock27735a42013-08-14 17:57:38 -04005371 mStatusBarController.dump(pw, prefix);
5372 mNavigationBarController.dump(pw, prefix);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005373 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005374}