blob: 7128cfa55b33437c5a8976aa59f9d134f6f5ff3c [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16package com.android.internal.policy.impl;
17
Dianne Hackborna4972e92012-03-14 10:38:05 -070018import android.app.ActivityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080019import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080020import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040021import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070022import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070023import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040024import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080025import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070026import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080027import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040028import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080029import android.content.ContentResolver;
30import android.content.Context;
31import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070032import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070033import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080034import android.content.pm.ActivityInfo;
35import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040036import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070037import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080038import android.content.res.Configuration;
39import android.content.res.Resources;
Craig Mautner8e4df6c2012-05-23 16:57:23 -070040import android.content.res.TypedArray;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080042import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080043import android.graphics.Rect;
Michael Jurka7a348952012-02-27 13:07:58 -080044import android.media.AudioManager;
Jean-Michel Trivifca1e602013-10-10 18:12:59 -070045import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080046import 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;
Craig Mautner03924422014-03-19 19:48:38 -0700108import 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
John Spurlock7f4820a2013-10-08 12:54:35 -0400168 | View.SYSTEM_UI_FLAG_FULLSCREEN
169 | View.STATUS_BAR_TRANSLUCENT
170 | View.NAVIGATION_BAR_TRANSLUCENT;
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
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800235 boolean mSafeMode;
236 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700237 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400238 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400239 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700240 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400241 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
242 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
243 int[] mNavigationBarHeightForRotation = new int[4];
244 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400245
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800246 WindowState mKeyguard = null;
Jim Miller5ecd8112013-01-09 18:50:26 -0800247 KeyguardServiceDelegate mKeyguardDelegate;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800248 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700249 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
250 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800251 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900252 WindowState mLastInputMethodWindow = null;
253 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800254
Jeff Brown68b909d2011-12-07 16:36:01 -0800255 static final int RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS = 0;
256 static final int RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW = 1;
Jeff Brown602ab322012-05-16 13:33:47 -0700257 static final int RECENT_APPS_BEHAVIOR_DISMISS = 2;
258 static final int RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH = 3;
Jeff Brown68b909d2011-12-07 16:36:01 -0800259
260 RecentApplicationsDialog mRecentAppsDialog;
261 int mRecentAppsDialogHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700262 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800263
Jeff Brown2e7760e2012-04-11 15:14:55 -0700264 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700265 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800266
Dianne Hackbornc777e072010-02-12 13:07:59 -0800267 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700268 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800269 boolean mHdmiPlugged;
Daniel Sandler6396c722013-04-16 20:19:09 -0400270 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700271 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700272 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400273 int mCarDockRotation;
274 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700275 int mUndockedHdmiRotation;
276 int mDemoHdmiRotation;
277 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400278
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700279 // Default display does not rotate, apps that require non-default orientation will have to
280 // have the orientation emulated.
281 private boolean mForceDefaultOrientation = false;
282
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400283 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
284 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700285 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400286
Jeff Brownbcdfc622014-03-06 19:13:04 -0800287 boolean mSupportAutoRotation;
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;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -0700300 boolean mTouchExplorationEnabled = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400301 boolean mTranslucentDecorEnabled = true;
Craig Mautner967212c2013-04-13 21:10:58 -0700302
Jeff Brown70825162012-03-28 17:27:48 -0700303 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800304
305 // The last window we were told about in focusChanged.
306 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800307 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800308
Craig Mautner037aa8d2013-06-07 10:35:44 -0700309 private final class PointerLocationPointerEventListener implements PointerEventListener {
Jeff Browna41ca772010-08-11 14:46:32 -0700310 @Override
Craig Mautner037aa8d2013-06-07 10:35:44 -0700311 public void onPointerEvent(MotionEvent motionEvent) {
312 if (mPointerLocationView != null) {
313 mPointerLocationView.addPointerEvent(motionEvent);
Jeff Browna41ca772010-08-11 14:46:32 -0700314 }
315 }
Jeff Brown32cbc38552011-12-01 14:01:49 -0800316 }
Jeff Brown70825162012-03-28 17:27:48 -0700317
318 // Pointer location view state, only modified on the mHandler Looper.
Craig Mautner037aa8d2013-06-07 10:35:44 -0700319 PointerLocationPointerEventListener mPointerLocationPointerEventListener;
Jeff Brown70825162012-03-28 17:27:48 -0700320 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800321
Dianne Hackbornc652de82013-02-15 16:32:56 -0800322 // The current size of the screen; really; extends into the overscan area of
323 // the screen and doesn't account for any system elements like the status bar.
324 int mOverscanScreenLeft, mOverscanScreenTop;
325 int mOverscanScreenWidth, mOverscanScreenHeight;
326 // The current visible size of the screen; really; (ir)regardless of whether the status
327 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800328 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
329 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800330 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
331 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
332 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700333 // The current size of the screen; these may be different than (0,0)-(dw,dh)
334 // if the status bar can't be hidden; in that case it effectively carves out
335 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800336 int mRestrictedScreenLeft, mRestrictedScreenTop;
337 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700338 // During layout, the current screen borders accounting for any currently
339 // visible system UI elements.
340 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700341 // For applications requesting stable content insets, these are them.
342 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700343 // For applications requesting stable content insets but have also set the
344 // fullscreen window flag, these are the stable dimensions without the status bar.
345 int mStableFullscreenLeft, mStableFullscreenTop;
346 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800347 // During layout, the current screen borders with all outer decoration
348 // (status bar, input method dock) accounted for.
349 int mCurLeft, mCurTop, mCurRight, mCurBottom;
350 // During layout, the frame in which content should be displayed
351 // to the user, accounting for all screen decoration except for any
352 // space they deem as available for other content. This is usually
353 // the same as mCur*, but may be larger if the screen decor has supplied
354 // content insets.
355 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800356 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800357 // windows are placed.
358 int mDockLeft, mDockTop, mDockRight, mDockBottom;
359 // During layout, the layer at which the doc window is placed.
360 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700361 // During layout, this is the layer of the status bar.
362 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700363 int mLastSystemUiFlags;
364 // Bits that we are in the process of clearing, so we want to prevent
365 // them from being set by applications until everything has been updated
366 // to have them clear.
367 int mResettingSystemUiFlags = 0;
368 // Bits that we are currently always keeping cleared.
369 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800370 // What we last reported to system UI about whether the compatibility
371 // menu needs to be displayed.
372 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700373
374 FakeWindow mHideNavFakeWindow = null;
375
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800376 static final Rect mTmpParentFrame = new Rect();
377 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800378 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800379 static final Rect mTmpContentFrame = new Rect();
380 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400381 static final Rect mTmpDecorFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700382 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700383
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800384 WindowState mTopFullscreenOpaqueWindowState;
Craig Mautner03924422014-03-19 19:48:38 -0700385 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400386 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800387 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700388 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700389 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800390 boolean mForcingShowNavBar;
391 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700392
393 // States of keyguard dismiss.
394 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
395 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
396 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
397 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
398
399 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
400 * be done once per window. */
401 private WindowState mWinDismissingKeyguard;
402
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700403 boolean mShowingLockscreen;
404 boolean mShowingDream;
405 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800406 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700407 boolean mHomeConsumed;
408 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800409 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700410 Intent mCarDockIntent;
411 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700412 boolean mSearchKeyShortcutPending;
413 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700414 boolean mAssistKeyLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800415
Mike Lockwood28569302010-01-28 11:54:40 -0500416 // support for activating the lock screen while the screen is on
417 boolean mAllowLockscreenWhenOn;
418 int mLockScreenTimeout;
419 boolean mLockScreenTimerActive;
420
David Brownbaf8d092010-03-08 21:52:59 -0800421 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800422 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800423
424 // Behavior of POWER button while in-call and screen on.
425 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
426 int mIncallPowerBehavior;
427
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700428 Display mDisplay;
429
Dianne Hackborn9d132642011-04-21 17:26:39 -0700430 int mLandscapeRotation = 0; // default landscape rotation
431 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
432 int mPortraitRotation = 0; // default portrait rotation
433 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700434
Dianne Hackbornc652de82013-02-15 16:32:56 -0800435 int mOverscanLeft = 0;
436 int mOverscanTop = 0;
437 int mOverscanRight = 0;
438 int mOverscanBottom = 0;
439
Joe Onorato46b0d682010-11-22 17:37:27 -0800440 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700441 private int mLongPressOnHomeBehavior;
442
443 // What we do when the user double-taps on home
444 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800445
Winson Chung9112ec32011-06-27 13:15:32 -0700446 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700447 // Time to volume and power must be pressed within this interval of each other.
448 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700449 // Increase the chord delay when taking a screenshot from the keyguard
450 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800451 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700452 private boolean mVolumeDownKeyTriggered;
453 private long mVolumeDownKeyTime;
454 private boolean mVolumeDownKeyConsumedByScreenshotChord;
455 private boolean mVolumeUpKeyTriggered;
456 private boolean mPowerKeyTriggered;
457 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700458
Michael Wrightb854e242013-02-05 17:54:02 -0800459 /* The number of steps between min and max brightness */
460 private static final int BRIGHTNESS_STEPS = 10;
461
Christopher Tate5e08af02012-09-21 17:17:22 -0700462 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800463 ShortcutManager mShortcutManager;
464 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700465 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800466
Craig Mautnerd625ab22013-09-06 13:40:31 -0700467 private int mCurrentUserId;
468
Justin Kohd378ad72013-04-01 12:18:26 -0700469 // Maps global key codes to the components that will handle them.
470 private GlobalKeyManager mGlobalKeyManager;
471
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700472 // Fallback actions by key code.
473 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
474 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800475
Jeff Brown70825162012-03-28 17:27:48 -0700476 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
477 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700478 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
479 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Jeff Brown70825162012-03-28 17:27:48 -0700480
481 private class PolicyHandler extends Handler {
482 @Override
483 public void handleMessage(Message msg) {
484 switch (msg.what) {
485 case MSG_ENABLE_POINTER_LOCATION:
486 enablePointerLocation();
487 break;
488 case MSG_DISABLE_POINTER_LOCATION:
489 disablePointerLocation();
490 break;
Jeff Brown40013652012-05-16 21:22:36 -0700491 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
492 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
493 break;
494 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
495 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
496 break;
Jeff Brown70825162012-03-28 17:27:48 -0700497 }
498 }
499 }
500
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800501 private UEventObserver mHDMIObserver = new UEventObserver() {
502 @Override
503 public void onUEvent(UEventObserver.UEvent event) {
504 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
505 }
506 };
507
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800508 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800509 SettingsObserver(Handler handler) {
510 super(handler);
511 }
David Brownbaf8d092010-03-08 21:52:59 -0800512
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800513 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700514 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800515 ContentResolver resolver = mContext.getContentResolver();
516 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700517 Settings.System.END_BUTTON_BEHAVIOR), false, this,
518 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800519 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700520 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
521 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800522 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700523 Settings.System.ACCELEROMETER_ROTATION), false, this,
524 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500525 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700526 Settings.System.USER_ROTATION), false, this,
527 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400528 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700529 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
530 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800531 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700532 Settings.System.POINTER_LOCATION), false, this,
533 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800534 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700535 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
536 UserHandle.USER_ALL);
Dianne Hackborn03759ed2009-03-27 16:04:08 -0700537 resolver.registerContentObserver(Settings.System.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400538 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700539 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800540 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800541 }
542
543 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800544 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700545 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800546 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800547 }
Craig Mautner967212c2013-04-13 21:10:58 -0700548
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800549 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800550 MyOrientationListener(Context context, Handler handler) {
551 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800552 }
Craig Mautner967212c2013-04-13 21:10:58 -0700553
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800554 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700555 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700556 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700557 updateRotation(false);
558 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800559 }
560 MyOrientationListener mOrientationListener;
561
John Spurlock27735a42013-08-14 17:57:38 -0400562 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400563 View.STATUS_BAR_TRANSIENT,
564 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400565 View.STATUS_BAR_TRANSLUCENT,
566 StatusBarManager.WINDOW_STATUS_BAR,
567 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400568
John Spurlock27735a42013-08-14 17:57:38 -0400569 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400570 View.NAVIGATION_BAR_TRANSIENT,
571 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400572 View.NAVIGATION_BAR_TRANSLUCENT,
573 StatusBarManager.WINDOW_NAVIGATION_BAR,
574 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400575
John Spurlockf1a36642013-10-12 17:50:42 -0400576 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400577
Craig Mautner037aa8d2013-06-07 10:35:44 -0700578 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400579
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700580 IStatusBarService getStatusBarService() {
581 synchronized (mServiceAquireLock) {
582 if (mStatusBarService == null) {
583 mStatusBarService = IStatusBarService.Stub.asInterface(
584 ServiceManager.getService("statusbar"));
585 }
586 return mStatusBarService;
587 }
588 }
589
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700590 /*
591 * We always let the sensor be switched on by default except when
592 * the user has explicitly disabled sensor based rotation or when the
593 * screen is switched off.
594 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700595 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800596 if (mSupportAutoRotation) {
597 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
598 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
599 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
600 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
601 // If the application has explicitly requested to follow the
602 // orientation, then we need to turn the sensor on.
603 return true;
604 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800605 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700606 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800607 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
608 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
609 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400610 // enable accelerometer if we are docked in a dock that enables accelerometer
611 // orientation management,
612 return true;
613 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700614 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800615 // If the setting for using the sensor by default is enabled, then
616 // we will always leave it on. Note that the user could go to
617 // a window that forces an orientation that does not use the
618 // sensor and in theory we could turn it off... however, when next
619 // turning it on we won't have a good value for the current
620 // orientation for a little bit, which can cause orientation
621 // changes to lag, so we'd like to keep it always on. (It will
622 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700623 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800624 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800625 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800626 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700627
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800628 /*
629 * Various use cases for invoking this function
630 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700631 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800632 * if not already enabled
633 * screen turned on and current app does not have sensor orientation, disable listeners if
634 * already enabled
635 * screen turning on and current app has sensor based orientation, enable listeners if needed
636 * screen turning on and current app has nosensor based orientation, do nothing
637 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700638 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800639 if (!mOrientationListener.canDetectOrientation()) {
640 // If sensor is turned off or nonexistent for some reason
641 return;
642 }
643 //Could have been invoked due to screen turning on or off or
644 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700645 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800646 ", current orientation="+mCurrentAppOrientation+
647 ", SensorEnabled="+mOrientationSensorEnabled);
648 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700649 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700650 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800651 disable = false;
652 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700653 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800654 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700655 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800656 mOrientationSensorEnabled = true;
657 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700658 }
659 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800660 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700661 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800662 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700663 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800664 mOrientationSensorEnabled = false;
665 }
666 }
667
Jeff Brown4d396052010-10-29 21:50:21 -0700668 private void interceptPowerKeyDown(boolean handled) {
669 mPowerKeyHandled = handled;
670 if (!handled) {
671 mHandler.postDelayed(mPowerLongPress, ViewConfiguration.getGlobalActionKeyTimeout());
672 }
673 }
674
675 private boolean interceptPowerKeyUp(boolean canceled) {
676 if (!mPowerKeyHandled) {
677 mHandler.removeCallbacks(mPowerLongPress);
678 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700679 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700680 return false;
681 }
682
683 private void cancelPendingPowerKeyAction() {
684 if (!mPowerKeyHandled) {
685 mHandler.removeCallbacks(mPowerLongPress);
686 }
Jeff Brownff204712011-10-25 21:27:54 -0700687 if (mPowerKeyTriggered) {
688 mPendingPowerKeyUpCanceled = true;
689 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700690 }
691
692 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800693 if (mScreenshotChordEnabled
694 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700695 final long now = SystemClock.uptimeMillis();
696 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
697 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
698 mVolumeDownKeyConsumedByScreenshotChord = true;
699 cancelPendingPowerKeyAction();
700
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800701 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700702 }
703 }
704 }
705
Winson Chung1cea2f32012-10-08 20:42:01 -0700706 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800707 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700708 // Double the time it takes to take a screenshot from the keyguard
709 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
710 ViewConfiguration.getGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700711 }
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800712 return ViewConfiguration.getGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700713 }
714
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700715 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800716 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700717 }
718
719 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700720 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800721 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700722 // The context isn't read
723 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700724 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
725 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400726 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700727 int resolvedBehavior = mLongPressOnPowerBehavior;
728 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
729 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
730 }
731
732 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700733 case LONG_PRESS_POWER_NOTHING:
734 break;
735 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
736 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700737 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
738 performAuditoryFeedbackForAccessibilityIfNeed();
739 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700740 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
741 showGlobalActionsDialog();
742 break;
743 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700744 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700745 mPowerKeyHandled = true;
746 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
747 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700748 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700749 break;
750 }
751 }
752 };
753
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800754 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800755 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700756 public void run() {
757 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800758 }
759 };
760
761 void showGlobalActionsDialog() {
762 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700763 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800764 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700765 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800766 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
767 if (keyguardShowing) {
768 // since it took two seconds of long press to bring this up,
769 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800770 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800771 }
772 }
773
774 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700775 return Settings.Global.getInt(
776 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800777 }
778
Patrick Dubroyece94522011-02-23 18:35:01 -0800779 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800780 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700781 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800782 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800783
Jeff Browncaca8812013-05-09 13:34:33 -0700784 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
785 toggleRecentApps();
786 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
787 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700788 }
789 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800790 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800791
Jeff Browncaca8812013-05-09 13:34:33 -0700792 private void handleDoubleTapOnHome() {
793 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
794 mHomeConsumed = true;
795 toggleRecentApps();
796 }
797 }
798
799 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
800 @Override
801 public void run() {
802 if (mHomeDoubleTapPending) {
803 mHomeDoubleTapPending = false;
804 launchHomeFromHotKey();
805 }
806 }
807 };
808
Patrick Dubroyece94522011-02-23 18:35:01 -0800809 /**
Jeff Brown68b909d2011-12-07 16:36:01 -0800810 * Create (if necessary) and show or dismiss the recent apps dialog according
811 * according to the requested behavior.
Patrick Dubroyece94522011-02-23 18:35:01 -0800812 */
Jeff Brown68b909d2011-12-07 16:36:01 -0800813 void showOrHideRecentAppsDialog(final int behavior) {
Jeff Brownda3d5a92011-03-29 15:11:34 -0700814 mHandler.post(new Runnable() {
815 @Override
816 public void run() {
817 if (mRecentAppsDialog == null) {
Jeff Brown54875002011-04-06 15:33:01 -0700818 mRecentAppsDialog = new RecentApplicationsDialog(mContext);
Jeff Brownda3d5a92011-03-29 15:11:34 -0700819 }
Jeff Brown54875002011-04-06 15:33:01 -0700820 if (mRecentAppsDialog.isShowing()) {
Jeff Brown68b909d2011-12-07 16:36:01 -0800821 switch (behavior) {
822 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
Jeff Brown602ab322012-05-16 13:33:47 -0700823 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800824 mRecentAppsDialog.dismiss();
825 break;
826 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
827 mRecentAppsDialog.dismissAndSwitch();
828 break;
829 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
830 default:
831 break;
Jeff Brown54875002011-04-06 15:33:01 -0700832 }
833 } else {
Jeff Brown68b909d2011-12-07 16:36:01 -0800834 switch (behavior) {
835 case RECENT_APPS_BEHAVIOR_SHOW_OR_DISMISS:
836 mRecentAppsDialog.show();
837 break;
838 case RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW:
839 try {
840 mWindowManager.setInTouchMode(false);
841 } catch (RemoteException e) {
842 }
843 mRecentAppsDialog.show();
844 break;
Jeff Brown602ab322012-05-16 13:33:47 -0700845 case RECENT_APPS_BEHAVIOR_DISMISS:
Jeff Brown68b909d2011-12-07 16:36:01 -0800846 case RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH:
847 default:
848 break;
849 }
Jeff Brown54875002011-04-06 15:33:01 -0700850 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700851 }
852 });
Patrick Dubroyece94522011-02-23 18:35:01 -0800853 }
Jeff Brownda3d5a92011-03-29 15:11:34 -0700854
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800855 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800856 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800857 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700858 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800859 mContext = context;
860 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700861 mWindowManagerFuncs = windowManagerFuncs;
Jeff Brown70825162012-03-28 17:27:48 -0700862 mHandler = new PolicyHandler();
Craig Mautnereee29c42013-01-17 14:44:34 -0800863 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700864 try {
865 mOrientationListener.setCurrentRotation(windowManager.getRotation());
866 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700867 mSettingsObserver = new SettingsObserver(mHandler);
868 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800869 mShortcutManager = new ShortcutManager(context, mHandler);
870 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400871 mUiMode = context.getResources().getInteger(
872 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800873 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
874 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
875 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
876 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700877 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
878 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
879 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
880 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
881 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
882 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
883 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
884 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700885
Jeff Brown96307042012-07-27 15:51:34 -0700886 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
887 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800888 "PhoneWindowManager.mBroadcastWakeLock");
889 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -0800890 mSupportAutoRotation = mContext.getResources().getBoolean(
891 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700892 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400893 com.android.internal.R.integer.config_lidOpenRotation);
894 mCarDockRotation = readRotation(
895 com.android.internal.R.integer.config_carDockRotation);
896 mDeskDockRotation = readRotation(
897 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700898 mUndockedHdmiRotation = readRotation(
899 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400900 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
901 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
902 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
903 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700904 mLidKeyboardAccessibility = mContext.getResources().getInteger(
905 com.android.internal.R.integer.config_lidKeyboardAccessibility);
906 mLidNavigationAccessibility = mContext.getResources().getInteger(
907 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -0700908 mLidControlsSleep = mContext.getResources().getBoolean(
909 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400910 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
911 com.android.internal.R.bool.config_enableTranslucentDecor);
Jeff Brownf71343d2013-05-31 17:59:11 -0700912 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -0700913
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700914 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800915 IntentFilter filter = new IntentFilter();
916 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
917 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
918 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
919 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700920 filter.addAction(Intent.ACTION_DOCK_EVENT);
921 Intent intent = context.registerReceiver(mDockReceiver, filter);
922 if (intent != null) {
923 // Retrieve current sticky dock event broadcast.
924 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
925 Intent.EXTRA_DOCK_STATE_UNDOCKED);
926 }
Daniel Sandler7e37df52011-11-16 22:08:23 -0800927
Jeff Brown6aaf2952012-10-05 16:01:08 -0700928 // register for dream-related broadcasts
929 filter = new IntentFilter();
930 filter.addAction(Intent.ACTION_DREAMING_STARTED);
931 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
932 context.registerReceiver(mDreamReceiver, filter);
933
Christopher Tate5e08af02012-09-21 17:17:22 -0700934 // register for multiuser-relevant broadcasts
935 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
936 context.registerReceiver(mMultiuserReceiver, filter);
937
John Spurlock57306e62013-04-22 09:48:49 -0400938 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -0700939 mSystemGestures = new SystemGesturesPointerEventListener(context,
940 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -0400941 @Override
942 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -0400943 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400944 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -0400945 }
John Spurlockad3e6cb2013-04-30 08:47:43 -0400946 }
947 @Override
948 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -0400949 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400950 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400951 }
952 }
953 @Override
954 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -0400955 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400956 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400957 }
958 }
959 @Override
960 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -0400961 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -0400962 }
963 });
John Spurlockf1a36642013-10-12 17:50:42 -0400964 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -0700965 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -0400966
Jeff Brownc2346132012-04-13 01:55:38 -0700967 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700968 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
969 com.android.internal.R.array.config_longPressVibePattern);
970 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
971 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -0800972 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
973 com.android.internal.R.array.config_keyboardTapVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700974 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
975 com.android.internal.R.array.config_safeModeDisabledVibePattern);
976 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
977 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -0400978
Christopher Tatee90585f2012-03-05 18:56:25 -0800979 mScreenshotChordEnabled = mContext.getResources().getBoolean(
980 com.android.internal.R.bool.config_enableScreenshotChord);
981
Justin Kohd378ad72013-04-01 12:18:26 -0700982 mGlobalKeyManager = new GlobalKeyManager(mContext);
983
Joe Onoratoea495d42011-04-06 11:41:11 -0700984 // Controls rotation and the like.
985 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -0700986
987 // Match current screen state.
988 if (mPowerManager.isScreenOn()) {
989 screenTurningOn(null);
990 } else {
991 screenTurnedOff(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
992 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700993 }
994
Jeff Brownf71343d2013-05-31 17:59:11 -0700995 /**
996 * Read values from config.xml that may be overridden depending on
997 * the configuration of the device.
998 * eg. Disable long press on home goes to recents on sw600dp.
999 */
1000 private void readConfigurationDependentBehaviors() {
1001 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1002 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1003 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1004 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1005 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1006 }
1007
1008 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1009 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1010 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1011 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1012 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1013 }
1014 }
1015
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001016 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001017 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001018 // This method might be called before the policy has been fully initialized
1019 // or for other displays we don't care about.
1020 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1021 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001022 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001023 mDisplay = display;
1024
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001025 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001026 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001027 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001028 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001029 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001030 mLandscapeRotation = Surface.ROTATION_0;
1031 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001032 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001033 mPortraitRotation = Surface.ROTATION_90;
1034 mUpsideDownRotation = Surface.ROTATION_270;
1035 } else {
1036 mPortraitRotation = Surface.ROTATION_270;
1037 mUpsideDownRotation = Surface.ROTATION_90;
1038 }
1039 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001040 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001041 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001042 mPortraitRotation = Surface.ROTATION_0;
1043 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001044 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001045 mLandscapeRotation = Surface.ROTATION_270;
1046 mSeascapeRotation = Surface.ROTATION_90;
1047 } else {
1048 mLandscapeRotation = Surface.ROTATION_90;
1049 mSeascapeRotation = Surface.ROTATION_270;
1050 }
1051 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001052
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001053 mStatusBarHeight =
1054 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001055
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001056 // Height of the navigation bar when presented horizontally at bottom
1057 mNavigationBarHeightForRotation[mPortraitRotation] =
1058 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001059 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001060 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001061 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1062 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001063
1064 // Width of the navigation bar when presented vertically along one side
1065 mNavigationBarWidthForRotation[mPortraitRotation] =
1066 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1067 mNavigationBarWidthForRotation[mLandscapeRotation] =
1068 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001069 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001070
1071 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001072 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001073 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001074
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001075 // Allow the navigation bar to move on small devices (phones).
1076 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001077
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001078 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001079 // Allow a system property to override this. Used by the emulator.
1080 // See also hasNavigationBar().
1081 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1082 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001083 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001084 } else if ("0".equals(navBarOverride)) {
1085 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001086 }
1087
Jeff Brown27f1d672012-10-17 18:32:34 -07001088 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1089 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001090 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001091 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001092 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001093 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001094 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001095 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001096
1097 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1098 // http://developer.android.com/guide/practices/screens_support.html#range
1099 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1100 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1101 // For debug purposes the next line turns this feature off with:
1102 // $ adb shell setprop config.override_forced_orient true
1103 // $ adb shell wm size reset
1104 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1105 }
1106
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001107 /**
1108 * @return whether the navigation bar can be hidden, e.g. the device has a
1109 * navigation bar and touch exploration is not enabled
1110 */
1111 private boolean canHideNavigationBar() {
1112 return mHasNavigationBar && !mTouchExplorationEnabled;
1113 }
1114
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001115 @Override
1116 public boolean isDefaultOrientationForced() {
1117 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001118 }
1119
Dianne Hackbornc652de82013-02-15 16:32:56 -08001120 @Override
1121 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1122 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1123 mOverscanLeft = left;
1124 mOverscanTop = top;
1125 mOverscanRight = right;
1126 mOverscanBottom = bottom;
1127 }
1128 }
1129
Dianne Hackbornc777e072010-02-12 13:07:59 -08001130 public void updateSettings() {
1131 ContentResolver resolver = mContext.getContentResolver();
1132 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001133 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001134 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001135 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001136 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1137 UserHandle.USER_CURRENT);
1138 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001139 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001140 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1141 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001142
Jeff Brown207673cd2012-06-05 17:47:11 -07001143 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001144 int userRotation = Settings.System.getIntForUser(resolver,
1145 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1146 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001147 if (mUserRotation != userRotation) {
1148 mUserRotation = userRotation;
1149 updateRotation = true;
1150 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001151 int userRotationMode = Settings.System.getIntForUser(resolver,
1152 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001153 WindowManagerPolicy.USER_ROTATION_FREE :
1154 WindowManagerPolicy.USER_ROTATION_LOCKED;
1155 if (mUserRotationMode != userRotationMode) {
1156 mUserRotationMode = userRotationMode;
1157 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001158 updateOrientationListenerLp();
1159 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001160
Dianne Hackbornc777e072010-02-12 13:07:59 -08001161 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001162 int pointerLocation = Settings.System.getIntForUser(resolver,
1163 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001164 if (mPointerLocationMode != pointerLocation) {
1165 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001166 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1167 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001168 }
1169 }
1170 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001171 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1172 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1173 String imId = Settings.Secure.getStringForUser(resolver,
1174 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001175 boolean hasSoftInput = imId != null && imId.length() > 0;
1176 if (mHasSoftInput != hasSoftInput) {
1177 mHasSoftInput = hasSoftInput;
1178 updateRotation = true;
1179 }
John Spurlockf1a36642013-10-12 17:50:42 -04001180 if (mImmersiveModeConfirmation != null) {
1181 mImmersiveModeConfirmation.loadSetting();
John Spurlockd67ec252013-09-05 11:31:54 -04001182 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001183 }
1184 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001185 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001186 }
Jeff Brown70825162012-03-28 17:27:48 -07001187 }
1188
1189 private void enablePointerLocation() {
1190 if (mPointerLocationView == null) {
1191 mPointerLocationView = new PointerLocationView(mContext);
1192 mPointerLocationView.setPrintCoords(false);
1193
Dianne Hackbornc777e072010-02-12 13:07:59 -08001194 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1195 WindowManager.LayoutParams.MATCH_PARENT,
1196 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001197 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001198 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1199 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1200 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1201 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001202 if (ActivityManager.isHighEndGfx()) {
1203 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1204 lp.privateFlags |=
1205 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1206 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001207 lp.format = PixelFormat.TRANSLUCENT;
1208 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001209 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001210 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001211 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001212 wm.addView(mPointerLocationView, lp);
1213
Craig Mautner037aa8d2013-06-07 10:35:44 -07001214 mPointerLocationPointerEventListener = new PointerLocationPointerEventListener();
1215 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationPointerEventListener);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001216 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001217 }
Jeff Brown70825162012-03-28 17:27:48 -07001218
1219 private void disablePointerLocation() {
Craig Mautner037aa8d2013-06-07 10:35:44 -07001220 if (mPointerLocationPointerEventListener != null) {
1221 mWindowManagerFuncs.unregisterPointerEventListener(
1222 mPointerLocationPointerEventListener);
1223 mPointerLocationPointerEventListener = null;
Jeff Brown70825162012-03-28 17:27:48 -07001224 }
1225
1226 if (mPointerLocationView != null) {
1227 WindowManager wm = (WindowManager)
1228 mContext.getSystemService(Context.WINDOW_SERVICE);
1229 wm.removeView(mPointerLocationView);
1230 mPointerLocationView = null;
1231 }
1232 }
1233
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001234 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001235 try {
1236 int rotation = mContext.getResources().getInteger(resID);
1237 switch (rotation) {
1238 case 0:
1239 return Surface.ROTATION_0;
1240 case 90:
1241 return Surface.ROTATION_90;
1242 case 180:
1243 return Surface.ROTATION_180;
1244 case 270:
1245 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001246 }
1247 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001248 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001249 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001250 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001251 }
1252
1253 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001254 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001255 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001256 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001257
1258 outAppOp[0] = AppOpsManager.OP_NONE;
1259
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001260 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1261 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001262 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001263 }
1264 String permission = null;
1265 switch (type) {
1266 case TYPE_TOAST:
1267 // XXX right now the app process has complete control over
1268 // this... should introduce a token to let the system
1269 // monitor/control what they are doing.
1270 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001271 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001272 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001273 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001274 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001275 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001276 break;
1277 case TYPE_PHONE:
1278 case TYPE_PRIORITY_PHONE:
1279 case TYPE_SYSTEM_ALERT:
1280 case TYPE_SYSTEM_ERROR:
1281 case TYPE_SYSTEM_OVERLAY:
1282 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001283 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001284 break;
1285 default:
1286 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1287 }
1288 if (permission != null) {
1289 if (mContext.checkCallingOrSelfPermission(permission)
1290 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001291 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001292 }
1293 }
Jeff Brown98365d72012-08-19 20:30:52 -07001294 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001295 }
Craig Mautner88400d32012-09-30 12:35:45 -07001296
1297 @Override
1298 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1299
1300 // If this switch statement is modified, modify the comment in the declarations of
1301 // the type in {@link WindowManager.LayoutParams} as well.
1302 switch (attrs.type) {
1303 default:
1304 // These are the windows that by default are shown only to the user that created
1305 // them. If this needs to be overridden, set
1306 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1307 // {@link WindowManager.LayoutParams}. Note that permission
1308 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1309 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1310 return true;
1311 }
1312 break;
1313
1314 // These are the windows that by default are shown to all users. However, to
1315 // protect against spoofing, check permissions below.
1316 case TYPE_APPLICATION_STARTING:
1317 case TYPE_BOOT_PROGRESS:
1318 case TYPE_DISPLAY_OVERLAY:
1319 case TYPE_HIDDEN_NAV_CONSUMER:
1320 case TYPE_KEYGUARD:
Jim Miller5ecd8112013-01-09 18:50:26 -08001321 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001322 case TYPE_KEYGUARD_DIALOG:
1323 case TYPE_MAGNIFICATION_OVERLAY:
1324 case TYPE_NAVIGATION_BAR:
1325 case TYPE_NAVIGATION_BAR_PANEL:
1326 case TYPE_PHONE:
1327 case TYPE_POINTER:
1328 case TYPE_PRIORITY_PHONE:
1329 case TYPE_RECENTS_OVERLAY:
1330 case TYPE_SEARCH_BAR:
1331 case TYPE_STATUS_BAR:
1332 case TYPE_STATUS_BAR_PANEL:
1333 case TYPE_STATUS_BAR_SUB_PANEL:
1334 case TYPE_SYSTEM_DIALOG:
1335 case TYPE_UNIVERSE_BACKGROUND:
1336 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001337 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001338 break;
1339 }
1340
1341 // Check if third party app has set window to system window type.
1342 return mContext.checkCallingOrSelfPermission(
1343 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1344 != PackageManager.PERMISSION_GRANTED;
1345 }
1346
Craig Mautner967212c2013-04-13 21:10:58 -07001347 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001348 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1349 switch (attrs.type) {
1350 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001351 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001352 // These types of windows can't receive input events.
1353 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1354 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001355 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001356 break;
1357 }
1358 }
1359
1360 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001361 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001362 }
1363
Jeff Browndaa37532012-05-01 15:54:03 -07001364 private boolean isHidden(int accessibilityMode) {
1365 switch (accessibilityMode) {
1366 case 1:
1367 return mLidState == LID_CLOSED;
1368 case 2:
1369 return mLidState == LID_OPEN;
1370 default:
1371 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001372 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001373 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001374
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001375 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001376 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001377 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1378 int navigationPresence) {
1379 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1380
Jeff Brownf71343d2013-05-31 17:59:11 -07001381 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001382 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001383 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001384
Jeff Browndaa37532012-05-01 15:54:03 -07001385 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1386 || (keyboardPresence == PRESENCE_INTERNAL
1387 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001388 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001389 if (!mHasSoftInput) {
1390 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1391 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001392 }
1393
Jeff Browndaa37532012-05-01 15:54:03 -07001394 if (config.navigation == Configuration.NAVIGATION_NONAV
1395 || (navigationPresence == PRESENCE_INTERNAL
1396 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001397 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001398 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001399 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001400
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001401 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001402 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001403 public int windowTypeToLayerLw(int type) {
1404 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001405 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001406 }
1407 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001408 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001409 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001410 case TYPE_PRIVATE_PRESENTATION:
1411 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001412 case TYPE_WALLPAPER:
1413 // wallpaper is at the bottom, though the window manager may move it.
1414 return 2;
1415 case TYPE_PHONE:
1416 return 3;
1417 case TYPE_SEARCH_BAR:
1418 return 4;
Craig Mautner88400d32012-09-30 12:35:45 -07001419 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001420 case TYPE_SYSTEM_DIALOG:
1421 return 5;
1422 case TYPE_TOAST:
1423 // toasts and the plugged-in battery thing
1424 return 6;
1425 case TYPE_PRIORITY_PHONE:
1426 // SIM errors and unlock. Not sure if this really should be in a high layer.
1427 return 7;
1428 case TYPE_DREAM:
1429 // used for Dreams (screensavers with TYPE_DREAM windows)
1430 return 8;
1431 case TYPE_SYSTEM_ALERT:
1432 // like the ANR / app crashed dialogs
1433 return 9;
1434 case TYPE_INPUT_METHOD:
1435 // on-screen keyboards and other such input method user interfaces go here.
1436 return 10;
1437 case TYPE_INPUT_METHOD_DIALOG:
1438 // on-screen keyboards and other such input method user interfaces go here.
1439 return 11;
Jim Miller5ecd8112013-01-09 18:50:26 -08001440 case TYPE_KEYGUARD_SCRIM:
1441 // the safety window that shows behind keyguard while keyguard is starting
1442 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001443 case TYPE_KEYGUARD:
1444 // the keyguard; nothing on top of these can take focus, since they are
1445 // responsible for power management when displayed.
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001446 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08001447 case TYPE_KEYGUARD_DIALOG:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001448 return 14;
Jim Miller5ecd8112013-01-09 18:50:26 -08001449 case TYPE_STATUS_BAR_SUB_PANEL:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001450 return 15;
Jim Miller5ecd8112013-01-09 18:50:26 -08001451 case TYPE_STATUS_BAR:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001452 return 16;
Jim Miller5ecd8112013-01-09 18:50:26 -08001453 case TYPE_STATUS_BAR_PANEL:
1454 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001455 case TYPE_VOLUME_OVERLAY:
1456 // the on-screen volume indicator and controller shown when the user
1457 // changes the device volume
Jim Miller5ecd8112013-01-09 18:50:26 -08001458 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001459 case TYPE_SYSTEM_OVERLAY:
1460 // the on-screen volume indicator and controller shown when the user
1461 // changes the device volume
Jim Miller5ecd8112013-01-09 18:50:26 -08001462 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001463 case TYPE_NAVIGATION_BAR:
1464 // the navigation bar, if available, shows atop most things
Jim Miller5ecd8112013-01-09 18:50:26 -08001465 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001466 case TYPE_NAVIGATION_BAR_PANEL:
1467 // some panels (e.g. search) need to show on top of the navigation bar
Jim Miller5ecd8112013-01-09 18:50:26 -08001468 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001469 case TYPE_SYSTEM_ERROR:
1470 // system-level error dialogs
Jim Miller5ecd8112013-01-09 18:50:26 -08001471 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001472 case TYPE_MAGNIFICATION_OVERLAY:
1473 // used to highlight the magnified portion of a display
Jim Miller5ecd8112013-01-09 18:50:26 -08001474 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001475 case TYPE_DISPLAY_OVERLAY:
1476 // used to simulate secondary display devices
Jim Miller5ecd8112013-01-09 18:50:26 -08001477 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001478 case TYPE_DRAG:
1479 // the drag layer: input for drag-and-drop is associated with this window,
1480 // which sits above all other focusable windows
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001481 return 25;
Jim Miller5ecd8112013-01-09 18:50:26 -08001482 case TYPE_SECURE_SYSTEM_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001483 return 26;
Jim Miller5ecd8112013-01-09 18:50:26 -08001484 case TYPE_BOOT_PROGRESS:
1485 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001486 case TYPE_POINTER:
1487 // the (mouse) pointer layer
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001488 return 28;
Jim Miller5ecd8112013-01-09 18:50:26 -08001489 case TYPE_HIDDEN_NAV_CONSUMER:
1490 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001491 }
1492 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001493 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001494 }
1495
1496 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001497 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001498 public int subWindowTypeToLayerLw(int type) {
1499 switch (type) {
1500 case TYPE_APPLICATION_PANEL:
1501 case TYPE_APPLICATION_ATTACHED_DIALOG:
1502 return APPLICATION_PANEL_SUBLAYER;
1503 case TYPE_APPLICATION_MEDIA:
1504 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001505 case TYPE_APPLICATION_MEDIA_OVERLAY:
1506 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001507 case TYPE_APPLICATION_SUB_PANEL:
1508 return APPLICATION_SUB_PANEL_SUBLAYER;
1509 }
1510 Log.e(TAG, "Unknown sub-window type: " + type);
1511 return 0;
1512 }
1513
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001514 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001515 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001516 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001517 }
1518
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001519 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001520 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001521 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001522 }
1523
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001524 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001525 if (mHasNavigationBar) {
1526 // For a basic navigation bar, when we are in landscape mode we place
1527 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001528 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1529 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001530 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001531 }
1532 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001533 }
1534
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001535 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001536 if (mHasNavigationBar) {
1537 // For a basic navigation bar, when we are in portrait mode we place
1538 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001539 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1540 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001541 }
1542 }
1543 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001544 }
1545
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001546 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1547 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001548 }
1549
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001550 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001551 // There is a separate status bar at the top of the display. We don't count that as part
1552 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001553 // we do want to exclude it since applications can't generally use that part
1554 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001555 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001556 }
1557
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001558 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001559 public boolean doesForceHide(WindowState win, WindowManager.LayoutParams attrs) {
1560 return attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD;
1561 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001562
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001563 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001564 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001565 switch (attrs.type) {
1566 case TYPE_STATUS_BAR:
1567 case TYPE_NAVIGATION_BAR:
1568 case TYPE_WALLPAPER:
1569 case TYPE_DREAM:
1570 case TYPE_UNIVERSE_BACKGROUND:
1571 case TYPE_KEYGUARD:
Jim Miller5ecd8112013-01-09 18:50:26 -08001572 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001573 return false;
1574 default:
1575 return true;
1576 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001577 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001578
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001579 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001580 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001581 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1582 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001583 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001584 if (!SHOW_STARTING_ANIMATIONS) {
1585 return null;
1586 }
1587 if (packageName == null) {
1588 return null;
1589 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001590
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001591 WindowManager wm = null;
1592 View view = null;
1593
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001594 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001595 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001596 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1597 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1598 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001599 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001600 try {
1601 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001602 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001603 } catch (PackageManager.NameNotFoundException e) {
1604 // Ignore
1605 }
1606 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001607
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001608 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001609 final TypedArray ta = win.getWindowStyle();
1610 if (ta.getBoolean(
1611 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1612 || ta.getBoolean(
1613 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001614 return null;
1615 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001616
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001617 Resources r = context.getResources();
1618 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001619
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001620 win.setType(
1621 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1622 // Force the window flags: this is a fake window, so it is not really
1623 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1624 // flag because we do know that the next window will take input
1625 // focus, so we want to get the IME window up on top of us right away.
1626 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001627 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001628 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1629 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1630 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001631 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001632 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1633 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1634 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001635
Adam Powell04fe6eb2013-05-31 14:39:48 -07001636 win.setDefaultIcon(icon);
1637 win.setDefaultLogo(logo);
1638
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001639 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001640 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001641
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001642 final WindowManager.LayoutParams params = win.getAttributes();
1643 params.token = appToken;
1644 params.packageName = packageName;
1645 params.windowAnimations = win.getWindowStyle().getResourceId(
1646 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001647 params.privateFlags |=
1648 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001649 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07001650
1651 if (!compatInfo.supportsScreen()) {
1652 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
1653 }
1654
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001655 params.setTitle("Starting " + packageName);
1656
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001657 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1658 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001659
1660 if (win.isFloating()) {
1661 // Whoops, there is no way to display an animation/preview
1662 // of such a thing! After all that work... let's skip it.
1663 // (Note that we must do this here because it is in
1664 // getDecorView() where the theme is evaluated... maybe
1665 // we should peek the floating attribute from the theme
1666 // earlier.)
1667 return null;
1668 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001669
Craig Mautner6fbda632012-07-03 09:26:39 -07001670 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001671 TAG, "Adding starting window for " + packageName
1672 + " / " + appToken + ": "
1673 + (view.getParent() != null ? view : null));
1674
1675 wm.addView(view, params);
1676
1677 // Only return the view if it was successfully added to the
1678 // window manager... which we can tell by it having a parent.
1679 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001680 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001681 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08001682 Log.w(TAG, appToken + " already running, starting window not displayed. " +
1683 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001684 } catch (RuntimeException e) {
1685 // don't crash if something else bad happens, for example a
1686 // failure loading resources because we are loading from an app
1687 // on external storage that has been unmounted.
1688 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001689 } finally {
1690 if (view != null && view.getParent() == null) {
1691 Log.w(TAG, "view not successfully added to wm, removing view");
1692 wm.removeViewImmediate(view);
1693 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001694 }
1695
1696 return null;
1697 }
1698
1699 /** {@inheritDoc} */
1700 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001701 if (DEBUG_STARTING_WINDOW) {
1702 RuntimeException e = new RuntimeException("here");
1703 e.fillInStackTrace();
1704 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1705 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001706
1707 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001708 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001709 wm.removeView(window);
1710 }
1711 }
1712
1713 /**
1714 * Preflight adding a window to the system.
1715 *
1716 * Currently enforces that three window types are singletons:
1717 * <ul>
1718 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001719 * <li>KEYGUARD_TYPE</li>
1720 * </ul>
1721 *
1722 * @param win The window to be added
1723 * @param attrs Information about the window to be added
1724 *
Jeff Brown98365d72012-08-19 20:30:52 -07001725 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1726 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001727 */
1728 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1729 switch (attrs.type) {
1730 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001731 mContext.enforceCallingOrSelfPermission(
1732 android.Manifest.permission.STATUS_BAR_SERVICE,
1733 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001734 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001735 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001736 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001737 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001738 }
1739 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001740 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001741 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001742 case TYPE_NAVIGATION_BAR:
1743 mContext.enforceCallingOrSelfPermission(
1744 android.Manifest.permission.STATUS_BAR_SERVICE,
1745 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001746 if (mNavigationBar != null) {
1747 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001748 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001749 }
1750 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001751 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001752 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001753 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001754 break;
Jim Millere898ac52012-04-06 17:10:57 -07001755 case TYPE_NAVIGATION_BAR_PANEL:
1756 mContext.enforceCallingOrSelfPermission(
1757 android.Manifest.permission.STATUS_BAR_SERVICE,
1758 "PhoneWindowManager");
1759 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001760 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001761 mContext.enforceCallingOrSelfPermission(
1762 android.Manifest.permission.STATUS_BAR_SERVICE,
1763 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001764 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001765 case TYPE_STATUS_BAR_SUB_PANEL:
1766 mContext.enforceCallingOrSelfPermission(
1767 android.Manifest.permission.STATUS_BAR_SERVICE,
1768 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001769 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001770 case TYPE_KEYGUARD:
1771 if (mKeyguard != null) {
Jeff Brown98365d72012-08-19 20:30:52 -07001772 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001773 }
1774 mKeyguard = win;
1775 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001776 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001777 if (mKeyguardScrim != null) {
1778 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1779 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001780 mKeyguardScrim = win;
1781 break;
1782
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001783 }
Jeff Brown98365d72012-08-19 20:30:52 -07001784 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001785 }
1786
1787 /** {@inheritDoc} */
1788 public void removeWindowLw(WindowState win) {
1789 if (mStatusBar == win) {
1790 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001791 mStatusBarController.setWindow(null);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001792 } else if (mKeyguard == win) {
Jim Miller5ecd8112013-01-09 18:50:26 -08001793 Log.v(TAG, "Removing keyguard window (Did it crash?)");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001794 mKeyguard = null;
Jim Millerc0b676d2013-03-22 16:11:08 -07001795 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001796 } else if (mKeyguardScrim == win) {
1797 Log.v(TAG, "Removing keyguard scrim");
1798 mKeyguardScrim = null;
1799 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001800 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001801 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001802 }
1803 }
1804
1805 static final boolean PRINT_ANIM = false;
1806
1807 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001808 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001809 public int selectAnimationLw(WindowState win, int transit) {
1810 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1811 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001812 if (win == mStatusBar) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001813 if (transit == TRANSIT_EXIT
1814 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001815 return R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001816 } else if (transit == TRANSIT_ENTER
1817 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001818 return R.anim.dock_top_enter;
1819 }
1820 } else if (win == mNavigationBar) {
1821 // This can be on either the bottom or the right.
1822 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001823 if (transit == TRANSIT_EXIT
1824 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001825 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001826 } else if (transit == TRANSIT_ENTER
1827 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001828 return R.anim.dock_bottom_enter;
1829 }
1830 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001831 if (transit == TRANSIT_EXIT
1832 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001833 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001834 } else if (transit == TRANSIT_ENTER
1835 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001836 return R.anim.dock_right_enter;
1837 }
1838 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001839 }
1840
1841 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001842 if (win.hasAppShownWindows()) {
1843 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1844 return com.android.internal.R.anim.app_starting_exit;
1845 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001846 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001847 && transit == TRANSIT_ENTER) {
1848 // Special case: we are animating in a dream, while the keyguard
1849 // is shown. We don't want an animation on the dream, because
1850 // we need it shown immediately with the keyguard animating away
1851 // to reveal it.
1852 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001853 }
1854
1855 return 0;
1856 }
1857
Craig Mautner3c174372013-02-21 17:54:37 -08001858 @Override
1859 public void selectRotationAnimationLw(int anim[]) {
1860 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
1861 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
1862 + (mTopFullscreenOpaqueWindowState == null ?
1863 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
1864 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
1865 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
1866 case ROTATION_ANIMATION_CROSSFADE:
1867 anim[0] = R.anim.rotation_animation_xfade_exit;
1868 anim[1] = R.anim.rotation_animation_enter;
1869 break;
1870 case ROTATION_ANIMATION_JUMPCUT:
1871 anim[0] = R.anim.rotation_animation_jump_exit;
1872 anim[1] = R.anim.rotation_animation_enter;
1873 break;
1874 case ROTATION_ANIMATION_ROTATE:
1875 default:
1876 anim[0] = anim[1] = 0;
1877 break;
1878 }
1879 } else {
1880 anim[0] = anim[1] = 0;
1881 }
1882 }
1883
1884 @Override
1885 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
1886 boolean forceDefault) {
1887 switch (exitAnimId) {
1888 case R.anim.rotation_animation_xfade_exit:
1889 case R.anim.rotation_animation_jump_exit:
1890 // These are the only cases that matter.
1891 if (forceDefault) {
1892 return false;
1893 }
1894 int anim[] = new int[2];
1895 selectRotationAnimationLw(anim);
1896 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
1897 default:
1898 return true;
1899 }
1900 }
1901
1902 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07001903 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
1904 return AnimationUtils.loadAnimation(mContext, onWallpaper
1905 ? com.android.internal.R.anim.lock_screen_wallpaper_behind_enter
1906 : com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001907 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04001908
1909 private static void awakenDreams() {
1910 IDreamManager dreamManager = getDreamManager();
1911 if (dreamManager != null) {
1912 try {
1913 dreamManager.awaken();
1914 } catch (RemoteException e) {
1915 // fine, stay asleep then
1916 }
1917 }
1918 }
1919
1920 static IDreamManager getDreamManager() {
1921 return IDreamManager.Stub.asInterface(
1922 ServiceManager.checkService(DreamService.DREAM_SERVICE));
1923 }
1924
Jeff Brown4d396052010-10-29 21:50:21 -07001925 static ITelephony getTelephonyService() {
Mike Lockwoodf5f4ec92011-11-08 14:05:31 -08001926 return ITelephony.Stub.asInterface(
Jeff Brown4d396052010-10-29 21:50:21 -07001927 ServiceManager.checkService(Context.TELEPHONY_SERVICE));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001928 }
1929
Jeff Brown4d396052010-10-29 21:50:21 -07001930 static IAudioService getAudioService() {
1931 IAudioService audioService = IAudioService.Stub.asInterface(
1932 ServiceManager.checkService(Context.AUDIO_SERVICE));
1933 if (audioService == null) {
1934 Log.w(TAG, "Unable to find IAudioService interface.");
1935 }
1936 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001937 }
1938
1939 boolean keyguardOn() {
1940 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
1941 }
1942
1943 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
1944 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
1945 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
1946 };
1947
1948 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001949 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001950 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001951 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08001952 final int keyCode = event.getKeyCode();
1953 final int repeatCount = event.getRepeatCount();
1954 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001955 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08001956 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
1957 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001958
Jeff Brown40013652012-05-16 21:22:36 -07001959 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001960 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001961 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
1962 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001963 }
1964
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001965 // If we think we might have a volume down & power key chord on the way
1966 // but we're not sure, then tell the dispatcher to wait a little while and
1967 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08001968 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001969 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
1970 final long now = SystemClock.uptimeMillis();
1971 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
1972 if (now < timeoutTime) {
1973 return timeoutTime - now;
1974 }
1975 }
1976 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
1977 && mVolumeDownKeyConsumedByScreenshotChord) {
1978 if (!down) {
1979 mVolumeDownKeyConsumedByScreenshotChord = false;
1980 }
1981 return -1;
1982 }
1983 }
1984
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001985 // First we always handle the home key here, so applications
1986 // can never break it, although if keyguard is on, we do let
1987 // it handle it, because that gives us the correct 5 second
1988 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001989 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07001990
Jeff Brown49ed71d2010-12-06 17:13:33 -08001991 // If we have released the home key, and didn't do anything else
1992 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07001993 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07001994 cancelPreloadRecentApps();
1995
Jeff Brown49ed71d2010-12-06 17:13:33 -08001996 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07001997 if (mHomeConsumed) {
1998 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07001999 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002000 }
Jeff Browncaca8812013-05-09 13:34:33 -07002001
2002 if (canceled) {
2003 Log.i(TAG, "Ignoring HOME; event canceled.");
2004 return -1;
2005 }
2006
2007 // If an incoming call is ringing, HOME is totally disabled.
2008 // (The user is already on the InCallScreen at this point,
2009 // and his ONLY options are to answer or reject the call.)
2010 try {
2011 ITelephony telephonyService = getTelephonyService();
2012 if (telephonyService != null && telephonyService.isRinging()) {
2013 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2014 return -1;
2015 }
2016 } catch (RemoteException ex) {
2017 Log.w(TAG, "RemoteException from getPhoneInterface()", ex);
2018 }
2019
2020 // Delay handling home if a double-tap is possible.
2021 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2022 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2023 mHomeDoubleTapPending = true;
2024 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2025 ViewConfiguration.getDoubleTapTimeout());
2026 return -1;
2027 }
2028
2029 // Go home!
2030 launchHomeFromHotKey();
2031 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002032 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002033
2034 // If a system window has focus, then it doesn't make sense
2035 // right now to interact with applications.
2036 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2037 if (attrs != null) {
2038 final int type = attrs.type;
2039 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD
Jim Miller5ecd8112013-01-09 18:50:26 -08002040 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002041 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG) {
2042 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002043 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002044 }
2045 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2046 for (int i=0; i<typeCount; i++) {
2047 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2048 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002049 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002050 }
2051 }
2052 }
Jeff Browncaca8812013-05-09 13:34:33 -07002053
2054 // Remember that home is pressed and handle special actions.
2055 if (repeatCount == 0) {
2056 mHomePressed = true;
2057 if (mHomeDoubleTapPending) {
2058 mHomeDoubleTapPending = false;
2059 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2060 handleDoubleTapOnHome();
2061 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2062 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2063 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002064 }
Jeff Browncaca8812013-05-09 13:34:33 -07002065 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2066 if (!keyguardOn) {
2067 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002068 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002069 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002070 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002071 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002072 // Hijack modified menu keys for debugging features
2073 final int chordBug = KeyEvent.META_SHIFT_ON;
2074
2075 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002076 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002077 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002078 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2079 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002080 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002081 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002082 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002083 Intent service = new Intent();
2084 service.setClassName(mContext, "com.android.server.LoadAverageService");
2085 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002086 boolean shown = Settings.Global.getInt(
2087 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002088 if (!shown) {
2089 mContext.startService(service);
2090 } else {
2091 mContext.stopService(service);
2092 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002093 Settings.Global.putInt(
2094 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002095 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002096 }
2097 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002098 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002099 if (down) {
2100 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002101 mSearchKeyShortcutPending = true;
2102 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002103 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002104 } else {
2105 mSearchKeyShortcutPending = false;
2106 if (mConsumeSearchKeyUp) {
2107 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002108 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002109 }
2110 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002111 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002112 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002113 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002114 if (down && repeatCount == 0) {
2115 preloadRecentApps();
2116 } else if (!down) {
2117 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002118 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002119 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002120 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002121 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2122 if (down) {
2123 if (repeatCount == 0) {
2124 mAssistKeyLongPressed = false;
2125 } else if (repeatCount == 1) {
2126 mAssistKeyLongPressed = true;
2127 if (!keyguardOn) {
2128 launchAssistLongPressAction();
2129 }
2130 }
2131 } else {
2132 if (mAssistKeyLongPressed) {
2133 mAssistKeyLongPressed = false;
2134 } else {
2135 if (!keyguardOn) {
2136 launchAssistAction();
2137 }
2138 }
2139 }
2140 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002141 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2142 if (down && repeatCount == 0) {
2143 mHandler.post(mScreenshotRunnable);
2144 }
2145 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002146 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2147 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2148 if (down) {
2149 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2150
2151 // Disable autobrightness if it's on
2152 int auto = Settings.System.getIntForUser(
2153 mContext.getContentResolver(),
2154 Settings.System.SCREEN_BRIGHTNESS_MODE,
2155 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2156 UserHandle.USER_CURRENT_OR_SELF);
2157 if (auto != 0) {
2158 Settings.System.putIntForUser(mContext.getContentResolver(),
2159 Settings.System.SCREEN_BRIGHTNESS_MODE,
2160 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2161 UserHandle.USER_CURRENT_OR_SELF);
2162 }
2163
2164 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2165 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2166 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2167 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2168 Settings.System.SCREEN_BRIGHTNESS,
2169 mPowerManager.getDefaultScreenBrightnessSetting(),
2170 UserHandle.USER_CURRENT_OR_SELF);
2171 brightness += step;
2172 // Make sure we don't go beyond the limits.
2173 brightness = Math.min(max, brightness);
2174 brightness = Math.max(min, brightness);
2175
2176 Settings.System.putIntForUser(mContext.getContentResolver(),
2177 Settings.System.SCREEN_BRIGHTNESS, brightness,
2178 UserHandle.USER_CURRENT_OR_SELF);
2179 Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG);
2180 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF);
2181 }
2182 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002183 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002184
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002185 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002186 // Any printing key that is chorded with Search should be consumed
2187 // even if no shortcut was invoked. This prevents text from being
2188 // inadvertently inserted when using a keyboard that has built-in macro
2189 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002190 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002191 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2192 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002193 mConsumeSearchKeyUp = true;
2194 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002195 if (down && repeatCount == 0 && !keyguardOn) {
2196 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2197 if (shortcutIntent != null) {
2198 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002199 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002200 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002201 } catch (ActivityNotFoundException ex) {
2202 Slog.w(TAG, "Dropping shortcut key combination because "
2203 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002204 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002205 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002206 } else {
2207 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002208 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002209 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002210 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002211 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002212 }
2213 }
2214
Jeff Brown68b909d2011-12-07 16:36:01 -08002215 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002216 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002217 && (metaState & KeyEvent.META_META_ON) != 0) {
2218 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002219 if (kcm.isPrintingKey(keyCode)) {
2220 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2221 metaState & ~(KeyEvent.META_META_ON
2222 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2223 if (shortcutIntent != null) {
2224 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2225 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002226 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002227 } catch (ActivityNotFoundException ex) {
2228 Slog.w(TAG, "Dropping shortcut key combination because "
2229 + "the activity to which it is registered was not found: "
2230 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2231 }
2232 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002233 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002234 }
2235 }
2236
Jeff Brown6651a632011-11-28 12:59:11 -08002237 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002238 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002239 String category = sApplicationLaunchKeyCategories.get(keyCode);
2240 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002241 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002242 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2243 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002244 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002245 } catch (ActivityNotFoundException ex) {
2246 Slog.w(TAG, "Dropping application launch key because "
2247 + "the activity to which it is registered was not found: "
2248 + "keyCode=" + keyCode + ", category=" + category, ex);
2249 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002250 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002251 }
2252 }
2253
Jeff Brown68b909d2011-12-07 16:36:01 -08002254 // Display task switcher for ALT-TAB or Meta-TAB.
2255 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Jeff Brown602ab322012-05-16 13:33:47 -07002256 if (mRecentAppsDialogHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002257 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
2258 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2259 || KeyEvent.metaStateHasModifiers(
2260 shiftlessModifiers, KeyEvent.META_META_ON)) {
2261 mRecentAppsDialogHeldModifiers = shiftlessModifiers;
2262 showOrHideRecentAppsDialog(RECENT_APPS_BEHAVIOR_EXIT_TOUCH_MODE_AND_SHOW);
2263 return -1;
2264 }
2265 }
2266 } else if (!down && mRecentAppsDialogHeldModifiers != 0
2267 && (metaState & mRecentAppsDialogHeldModifiers) == 0) {
2268 mRecentAppsDialogHeldModifiers = 0;
Jeff Brown602ab322012-05-16 13:33:47 -07002269 showOrHideRecentAppsDialog(keyguardOn ? RECENT_APPS_BEHAVIOR_DISMISS :
2270 RECENT_APPS_BEHAVIOR_DISMISS_AND_SWITCH);
Jeff Brown68b909d2011-12-07 16:36:01 -08002271 }
2272
Jeff Browncf39bdf2012-05-18 14:41:19 -07002273 // Handle keyboard language switching.
2274 if (down && repeatCount == 0
2275 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2276 || (keyCode == KeyEvent.KEYCODE_SPACE
2277 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2278 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2279 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2280 return -1;
2281 }
2282 if (mLanguageSwitchKeyPressed && !down
2283 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2284 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2285 mLanguageSwitchKeyPressed = false;
2286 return -1;
2287 }
2288
Justin Kohd378ad72013-04-01 12:18:26 -07002289 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2290 return -1;
2291 }
2292
Jeff Brown68b909d2011-12-07 16:36:01 -08002293 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002294 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002295 }
2296
Jeff Brown3915bb82010-11-05 15:02:16 -07002297 /** {@inheritDoc} */
2298 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002299 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002300 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002301 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002302 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2303 + ", flags=" + event.getFlags()
2304 + ", keyCode=" + event.getKeyCode()
2305 + ", scanCode=" + event.getScanCode()
2306 + ", metaState=" + event.getMetaState()
2307 + ", repeatCount=" + event.getRepeatCount()
2308 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002309 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002310
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002311 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002312 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2313 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002314 final int keyCode = event.getKeyCode();
2315 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002316 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2317 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002318
Jeff Brown54875002011-04-06 15:33:01 -07002319 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002320 final FallbackAction fallbackAction;
2321 if (initialDown) {
2322 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2323 } else {
2324 fallbackAction = mFallbackActions.get(keyCode);
2325 }
2326
2327 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002328 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002329 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2330 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002331 }
2332
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002333 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2334 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002335 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002336 event.getAction(), fallbackAction.keyCode,
2337 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002338 event.getDeviceId(), event.getScanCode(),
2339 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002340
2341 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2342 fallbackEvent.recycle();
2343 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002344 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002345
2346 if (initialDown) {
2347 mFallbackActions.put(keyCode, fallbackAction);
2348 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2349 mFallbackActions.remove(keyCode);
2350 fallbackAction.recycle();
2351 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002352 }
2353 }
2354
Jeff Brown40013652012-05-16 21:22:36 -07002355 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002356 if (fallbackEvent == null) {
2357 Slog.d(TAG, "No fallback.");
2358 } else {
2359 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2360 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002361 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002362 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002363 }
2364
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002365 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002366 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002367 if ((actions & ACTION_PASS_TO_USER) != 0) {
2368 long delayMillis = interceptKeyBeforeDispatching(
2369 win, fallbackEvent, policyFlags);
2370 if (delayMillis == 0) {
2371 return true;
2372 }
2373 }
2374 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002375 }
2376
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002377 private void launchAssistLongPressAction() {
2378 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2379 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2380
2381 // launch the search activity
2382 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2383 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2384 try {
Jim Miller45308b12012-06-18 19:23:39 -07002385 // TODO: This only stops the factory-installed search manager.
2386 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002387 SearchManager searchManager = getSearchManager();
2388 if (searchManager != null) {
2389 searchManager.stopSearch();
2390 }
Michael Wright43e27f72013-04-10 14:06:48 -07002391 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002392 } catch (ActivityNotFoundException e) {
2393 Slog.w(TAG, "No activity to handle assist long press action.", e);
2394 }
2395 }
2396
2397 private void launchAssistAction() {
2398 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002399 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002400 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002401 if (intent != null) {
2402 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2403 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2404 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2405 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002406 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002407 } catch (ActivityNotFoundException e) {
2408 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002409 }
2410 }
2411 }
2412
2413 private SearchManager getSearchManager() {
2414 if (mSearchManager == null) {
2415 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2416 }
2417 return mSearchManager;
2418 }
2419
Jeff Browncaca8812013-05-09 13:34:33 -07002420 private void preloadRecentApps() {
2421 mPreloadedRecentApps = true;
2422 try {
2423 IStatusBarService statusbar = getStatusBarService();
2424 if (statusbar != null) {
2425 statusbar.preloadRecentApps();
2426 }
2427 } catch (RemoteException e) {
2428 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2429 // re-acquire status bar service next time it is needed.
2430 mStatusBarService = null;
2431 }
2432 }
2433
2434 private void cancelPreloadRecentApps() {
2435 if (mPreloadedRecentApps) {
2436 mPreloadedRecentApps = false;
2437 try {
2438 IStatusBarService statusbar = getStatusBarService();
2439 if (statusbar != null) {
2440 statusbar.cancelPreloadRecentApps();
2441 }
2442 } catch (RemoteException e) {
2443 Slog.e(TAG, "RemoteException when showing recent apps", e);
2444 // re-acquire status bar service next time it is needed.
2445 mStatusBarService = null;
2446 }
2447 }
2448 }
2449
2450 private void toggleRecentApps() {
2451 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2452 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_RECENT_APPS);
2453 try {
2454 IStatusBarService statusbar = getStatusBarService();
2455 if (statusbar != null) {
2456 statusbar.toggleRecentApps();
2457 }
2458 } catch (RemoteException e) {
2459 Slog.e(TAG, "RemoteException when showing recent apps", e);
2460 // re-acquire status bar service next time it is needed.
2461 mStatusBarService = null;
2462 }
2463 }
2464
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002465 /**
2466 * A home key -> launch home action was detected. Take the appropriate action
2467 * given the situation with the keyguard.
2468 */
2469 void launchHomeFromHotKey() {
Jim Miller5ecd8112013-01-09 18:50:26 -08002470 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotHidden()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002471 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002472 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002473 // when in keyguard restricted mode, must first verify unlock
2474 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002475 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002476 public void onKeyguardExitResult(boolean success) {
2477 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002478 try {
2479 ActivityManagerNative.getDefault().stopAppSwitches();
2480 } catch (RemoteException e) {
2481 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002482 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002483 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002484 }
2485 }
2486 });
2487 } else {
2488 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002489 try {
2490 ActivityManagerNative.getDefault().stopAppSwitches();
2491 } catch (RemoteException e) {
2492 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002493 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002494 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002495 }
2496 }
2497
John Spurlock04db1762013-05-13 12:46:41 -04002498 private final Runnable mClearHideNavigationFlag = new Runnable() {
2499 @Override
2500 public void run() {
2501 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2502 // Clear flags.
2503 mForceClearedSystemUiFlags &=
2504 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2505 }
2506 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002507 }
2508 };
2509
2510 /**
2511 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2512 * to determine when the nav bar should be shown and prevent applications from
2513 * receiving those touches.
2514 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002515 final class HideNavInputEventReceiver extends InputEventReceiver {
2516 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2517 super(inputChannel, looper);
2518 }
2519
Dianne Hackborndf89e652011-10-06 22:35:11 -07002520 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002521 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002522 boolean handled = false;
2523 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002524 if (event instanceof MotionEvent
2525 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2526 final MotionEvent motionEvent = (MotionEvent)event;
2527 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002528 // When the user taps down, we re-show the nav bar.
2529 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002530 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002531 // Any user activity always causes us to show the
2532 // navigation controls, if they had been hidden.
2533 // We also clear the low profile and only content
2534 // flags so that tapping on the screen will atomically
2535 // restore all currently hidden screen decorations.
2536 int newVal = mResettingSystemUiFlags |
2537 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2538 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2539 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002540 if (mResettingSystemUiFlags != newVal) {
2541 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002542 changed = true;
2543 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002544 // We don't allow the system's nav bar to be hidden
2545 // again for 1 second, to prevent applications from
2546 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002547 newVal = mForceClearedSystemUiFlags |
2548 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002549 if (mForceClearedSystemUiFlags != newVal) {
2550 mForceClearedSystemUiFlags = newVal;
2551 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002552 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002553 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002554 }
2555 if (changed) {
2556 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2557 }
2558 }
2559 }
2560 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002561 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002562 }
2563 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002564 }
2565 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2566 new InputEventReceiver.Factory() {
2567 @Override
2568 public InputEventReceiver createInputEventReceiver(
2569 InputChannel inputChannel, Looper looper) {
2570 return new HideNavInputEventReceiver(inputChannel, looper);
2571 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002572 };
2573
2574 @Override
2575 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002576 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2577 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
John Spurlock27735a42013-08-14 17:57:38 -04002578
Dianne Hackborndf89e652011-10-06 22:35:11 -07002579 // Reset any bits in mForceClearingStatusBarVisibility that
2580 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002581 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002582 // Clear any bits in the new visibility that are currently being
2583 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002584 return visibility & ~mResettingSystemUiFlags
2585 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002586 }
2587
Craig Mautner69b08182012-09-05 13:07:13 -07002588 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002589 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
2590 final int fl = attrs.flags;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002591 final int systemUiVisibility = (attrs.systemUiVisibility|attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002592
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002593 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002594 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002595 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002596 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002597 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002598 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2599 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2600 } else {
2601 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2602 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2603 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002604 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2605 if ((fl & FLAG_FULLSCREEN) != 0) {
2606 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2607 availRight - mStableFullscreenRight,
2608 availBottom - mStableFullscreenBottom);
2609 } else {
2610 contentInset.set(mStableLeft, mStableTop,
2611 availRight - mStableRight, availBottom - mStableBottom);
2612 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002613 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002614 contentInset.setEmpty();
2615 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002616 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2617 contentInset.set(mCurLeft, mCurTop,
2618 availRight - mCurRight, availBottom - mCurBottom);
2619 } else {
2620 contentInset.set(mCurLeft, mCurTop,
2621 availRight - mCurRight, availBottom - mCurBottom);
2622 }
2623 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002624 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002625 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002626 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002627
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002628 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002629 @Override
2630 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2631 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002632 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2633 if (isDefaultDisplay) {
2634 switch (displayRotation) {
2635 case Surface.ROTATION_90:
2636 overscanLeft = mOverscanTop;
2637 overscanTop = mOverscanRight;
2638 overscanRight = mOverscanBottom;
2639 overscanBottom = mOverscanLeft;
2640 break;
2641 case Surface.ROTATION_180:
2642 overscanLeft = mOverscanRight;
2643 overscanTop = mOverscanBottom;
2644 overscanRight = mOverscanLeft;
2645 overscanBottom = mOverscanTop;
2646 break;
2647 case Surface.ROTATION_270:
2648 overscanLeft = mOverscanBottom;
2649 overscanTop = mOverscanLeft;
2650 overscanRight = mOverscanTop;
2651 overscanBottom = mOverscanRight;
2652 break;
2653 default:
2654 overscanLeft = mOverscanLeft;
2655 overscanTop = mOverscanTop;
2656 overscanRight = mOverscanRight;
2657 overscanBottom = mOverscanBottom;
2658 break;
2659 }
2660 } else {
2661 overscanLeft = 0;
2662 overscanTop = 0;
2663 overscanRight = 0;
2664 overscanBottom = 0;
2665 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002666 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2667 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2668 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2669 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002670 mSystemLeft = 0;
2671 mSystemTop = 0;
2672 mSystemRight = displayWidth;
2673 mSystemBottom = displayHeight;
2674 mUnrestrictedScreenLeft = overscanLeft;
2675 mUnrestrictedScreenTop = overscanTop;
2676 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2677 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2678 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2679 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002680 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2681 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002682 mDockLeft = mContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002683 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002684 mDockTop = mContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002685 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002686 mDockRight = mContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002687 = mCurRight = displayWidth - overscanRight;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002688 mDockBottom = mContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002689 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002690 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002691 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002692
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002693 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2694 final Rect pf = mTmpParentFrame;
2695 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002696 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002697 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002698 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002699 pf.left = df.left = of.left = vf.left = mDockLeft;
2700 pf.top = df.top = of.top = vf.top = mDockTop;
2701 pf.right = df.right = of.right = vf.right = mDockRight;
2702 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04002703 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002704
Craig Mautner69b08182012-09-05 13:07:13 -07002705 if (isDefaultDisplay) {
2706 // For purposes of putting out fake window up to steal focus, we will
2707 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002708 final int sysui = mLastSystemUiFlags;
2709 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
John Spurlockbd957402013-10-03 11:38:39 -04002710 boolean navTranslucent = (sysui & View.NAVIGATION_BAR_TRANSLUCENT) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04002711 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
2712 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
2713 boolean navAllowedHidden = immersive || immersiveSticky;
2714 navTranslucent &= !immersiveSticky; // transient trumps translucent
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002715 navTranslucent &= areTranslucentBarsAllowed();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002716
Craig Mautner69b08182012-09-05 13:07:13 -07002717 // When the navigation bar isn't visible, we put up a fake
2718 // input window to catch all touch events. This way we can
2719 // detect when the user presses anywhere to bring back the nav
2720 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04002721 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07002722 if (mHideNavFakeWindow != null) {
2723 mHideNavFakeWindow.dismiss();
2724 mHideNavFakeWindow = null;
2725 }
2726 } else if (mHideNavFakeWindow == null) {
2727 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2728 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07002729 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07002730 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002731 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002732
Craig Mautner69b08182012-09-05 13:07:13 -07002733 // For purposes of positioning and showing the nav bar, if we have
2734 // decided that it can't be hidden (because of the screen aspect ratio),
2735 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002736 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002737
John Spurlockad3e6cb2013-04-30 08:47:43 -04002738 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07002739 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04002740 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07002741 // Force the navigation bar to its appropriate place and
2742 // size. We need to do this directly, instead of relying on
2743 // it to bubble up from the nav bar, because this needs to
2744 // change atomically with screen rotations.
2745 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2746 if (mNavigationBarOnBottom) {
2747 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002748 int top = displayHeight - overscanBottom
2749 - mNavigationBarHeightForRotation[displayRotation];
2750 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07002751 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04002752 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002753 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002754 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002755 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002756 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08002757 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
2758 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002759 } else {
2760 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002761 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002762 }
John Spurlockbd957402013-10-03 11:38:39 -04002763 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
2764 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002765 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002766 // and not in the process of animating on or off, then
2767 // we can tell the app that it is covered by it.
2768 mSystemBottom = mTmpNavigationFrame.top;
2769 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002770 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002771 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002772 int left = displayWidth - overscanRight
2773 - mNavigationBarWidthForRotation[displayRotation];
2774 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07002775 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04002776 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002777 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002778 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002779 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002780 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08002781 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
2782 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07002783 } else {
2784 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002785 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002786 }
John Spurlockbd957402013-10-03 11:38:39 -04002787 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
2788 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07002789 // If the nav bar is currently requested to be visible,
2790 // and not in the process of animating on or off, then
2791 // we can tell the app that it is covered by it.
2792 mSystemRight = mTmpNavigationFrame.left;
2793 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002794 }
Craig Mautner69b08182012-09-05 13:07:13 -07002795 // Make sure the content and current rectangles are updated to
2796 // account for the restrictions from the navigation bar.
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002797 mContentTop = mCurTop = mDockTop;
2798 mContentBottom = mCurBottom = mDockBottom;
2799 mContentLeft = mCurLeft = mDockLeft;
2800 mContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002801 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2802 // And compute the final frame.
2803 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
John Spurlock46646232013-09-30 22:32:42 -04002804 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf);
Craig Mautnereda67292013-04-28 13:50:14 -07002805 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04002806 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002807 updateSysUiVisibility = true;
2808 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002809 }
Craig Mautnereda67292013-04-28 13:50:14 -07002810 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07002811 mDockLeft, mDockTop, mDockRight, mDockBottom));
2812
2813 // decide where the status bar goes ahead of time
2814 if (mStatusBar != null) {
2815 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002816 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
2817 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2818 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
2819 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
2820 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002821 vf.left = mStableLeft;
2822 vf.top = mStableTop;
2823 vf.right = mStableRight;
2824 vf.bottom = mStableBottom;
2825
2826 mStatusBarLayer = mStatusBar.getSurfaceLayer();
2827
2828 // Let the status bar determine its size.
John Spurlock46646232013-09-30 22:32:42 -04002829 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf);
Craig Mautner69b08182012-09-05 13:07:13 -07002830
2831 // For layout, the status bar is always at the top with our fixed height.
2832 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
2833
John Spurlocke1f366f2013-08-05 12:22:40 -04002834 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
John Spurlockbd957402013-10-03 11:38:39 -04002835 boolean statusBarTranslucent = (sysui & View.STATUS_BAR_TRANSLUCENT) != 0;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002836 statusBarTranslucent &= areTranslucentBarsAllowed();
John Spurlock32beb2c2013-03-11 10:16:47 -04002837
Craig Mautner69b08182012-09-05 13:07:13 -07002838 // If the status bar is hidden, we don't want to cause
2839 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04002840 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07002841 // Status bar may go away, so the screen area it occupies
2842 // is available to apps but just covering them when the
2843 // status bar is visible.
2844 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
2845
2846 mContentTop = mCurTop = mDockTop;
2847 mContentBottom = mCurBottom = mDockBottom;
2848 mContentLeft = mCurLeft = mDockLeft;
2849 mContentRight = mCurRight = mDockRight;
2850
Craig Mautnereda67292013-04-28 13:50:14 -07002851 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07002852 String.format(
2853 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
2854 mDockLeft, mDockTop, mDockRight, mDockBottom,
2855 mContentLeft, mContentTop, mContentRight, mContentBottom,
2856 mCurLeft, mCurTop, mCurRight, mCurBottom));
2857 }
John Spurlocke1f366f2013-08-05 12:22:40 -04002858 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04002859 && !statusBarTransient && !statusBarTranslucent
2860 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002861 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002862 // and not in the process of animating on or off, then
2863 // we can tell the app that it is covered by it.
2864 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
2865 }
John Spurlock27735a42013-08-14 17:57:38 -04002866 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002867 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04002868 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002869 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04002870 if (updateSysUiVisibility) {
2871 updateSystemUiVisibilityLw();
2872 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002873 }
2874 }
2875
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002876 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002877 @Override
John Spurlock46646232013-09-30 22:32:42 -04002878 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002879 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
2880 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
2881 return 0;
2882 }
2883
Craig Mautner967212c2013-04-13 21:10:58 -07002884 @Override
2885 public void getContentRectLw(Rect r) {
2886 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
2887 }
2888
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002889 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
2890 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002891 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
2892 // Here's a special case: if this attached window is a panel that is
2893 // above the dock window, and the window it is attached to is below
2894 // the dock window, then the frames we computed for the window it is
2895 // attached to can not be used because the dock is effectively part
2896 // of the underlying window and the attached window is floating on top
2897 // of the whole thing. So, we ignore the attached window and explicitly
2898 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002899 df.left = of.left = cf.left = vf.left = mDockLeft;
2900 df.top = of.top = cf.top = vf.top = mDockTop;
2901 df.right = of.right = cf.right = vf.right = mDockRight;
2902 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002903 } else {
2904 // The effective display frame of the attached window depends on
2905 // whether it is taking care of insetting its content. If not,
2906 // we need to use the parent's content frame so that the entire
2907 // window is positioned within that content. Otherwise we can use
2908 // the display frame and let the attached window take care of
2909 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002910 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002911 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002912 } else {
2913 // If the window is resizing, then we want to base the content
2914 // frame on our attached content frame to resize... however,
2915 // things can be tricky if the attached window is NOT in resize
2916 // mode, in which case its content frame will be larger.
2917 // Ungh. So to deal with that, make sure the content frame
2918 // we end up using is not covering the IM dock.
2919 cf.set(attached.getContentFrameLw());
2920 if (attached.getSurfaceLayer() < mDockLayer) {
2921 if (cf.left < mContentLeft) cf.left = mContentLeft;
2922 if (cf.top < mContentTop) cf.top = mContentTop;
2923 if (cf.right > mContentRight) cf.right = mContentRight;
2924 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
2925 }
2926 }
2927 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002928 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002929 vf.set(attached.getVisibleFrameLw());
2930 }
2931 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
2932 // window should be positioned relative to its parent or the entire
2933 // screen.
2934 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
2935 ? attached.getFrameLw() : df);
2936 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002937
2938 private void applyStableConstraints(int sysui, int fl, Rect r) {
2939 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2940 // If app is requesting a stable layout, don't let the
2941 // content insets go below the stable values.
2942 if ((fl & FLAG_FULLSCREEN) != 0) {
2943 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
2944 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
2945 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
2946 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
2947 } else {
2948 if (r.left < mStableLeft) r.left = mStableLeft;
2949 if (r.top < mStableTop) r.top = mStableTop;
2950 if (r.right > mStableRight) r.right = mStableRight;
2951 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
2952 }
2953 }
2954 }
2955
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002956 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002957 @Override
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07002958 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
2959 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002960 // we've already done the status bar
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002961 if (win == mStatusBar || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002962 return;
2963 }
Craig Mautner69b08182012-09-05 13:07:13 -07002964 final boolean isDefaultDisplay = win.isDefaultDisplay();
2965 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09002966 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
2967 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07002968 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09002969 offsetInputMethodWindowLw(mLastInputMethodWindow);
2970 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002971
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002972 final int fl = attrs.flags;
2973 final int sim = attrs.softInputMode;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002974 final int sysUiFl = win.getSystemUiVisibility();
2975
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002976 final Rect pf = mTmpParentFrame;
2977 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002978 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002979 final Rect cf = mTmpContentFrame;
2980 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002981 final Rect dcf = mTmpDecorFrame;
2982 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07002983
2984 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04002985 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002986
Craig Mautnerf683b562012-10-02 11:10:57 -07002987 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
2988
Craig Mautner69b08182012-09-05 13:07:13 -07002989 if (!isDefaultDisplay) {
2990 if (attached != null) {
2991 // If this window is attached to another, our display
2992 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002993 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07002994 } else {
2995 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002996 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
2997 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
2998 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08002999 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003000 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003001 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003002 }
3003 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003004 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3005 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3006 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003007 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003008 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003009 // ...with content insets above the nav bar
3010 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003011 // IM dock windows always go to the bottom of the screen.
3012 attrs.gravity = Gravity.BOTTOM;
3013 mDockLayer = win.getSurfaceLayer();
3014 } else {
John Spurlock46646232013-09-30 22:32:42 -04003015
3016 // Default policy decor for the default display
3017 dcf.left = mSystemLeft;
3018 dcf.top = mSystemTop;
3019 dcf.right = mSystemRight;
3020 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003021 final boolean inheritTranslucentDecor = (attrs.privateFlags
3022 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003023 final boolean isAppWindow =
3024 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3025 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3026 final boolean topAtRest =
3027 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3028 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003029 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3030 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
3031 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003032 // Ensure policy decor includes status bar
3033 dcf.top = mStableTop;
3034 }
John Spurlockbd957402013-10-03 11:38:39 -04003035 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
John Spurlock8e0ca282013-10-03 11:46:06 -04003036 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003037 // Ensure policy decor includes navigation bar
3038 dcf.bottom = mStableBottom;
3039 dcf.right = mStableRight;
3040 }
3041 }
3042
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003043 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3044 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Craig Mautnereda67292013-04-28 13:50:14 -07003045 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003046 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003047 // This is the case for a normal activity window: we want it
3048 // to cover all of the screen space, and it can take care of
3049 // moving its contents to account for screen decorations that
3050 // intrude into that space.
3051 if (attached != null) {
3052 // If this window is attached to another, our display
3053 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003054 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003055 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003056 if (attrs.type == TYPE_STATUS_BAR_PANEL
3057 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003058 // Status bar panels are the only windows who can go on top of
3059 // the status bar. They are protected by the STATUS_BAR_SERVICE
3060 // permission, so they have the same privileges as the status
3061 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003062 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003063 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003064
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003065 pf.left = df.left = of.left = hasNavBar
3066 ? mDockLeft : mUnrestrictedScreenLeft;
3067 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3068 pf.right = df.right = of.right = hasNavBar
3069 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3070 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3071 pf.bottom = df.bottom = of.bottom = hasNavBar
3072 ? mRestrictedScreenTop+mRestrictedScreenHeight
3073 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003074
Craig Mautnereda67292013-04-28 13:50:14 -07003075 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003076 "Laying out status bar window: (%d,%d - %d,%d)",
3077 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003078 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003079 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3080 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3081 // Asking to layout into the overscan region, so give it that pure
3082 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003083 pf.left = df.left = of.left = mOverscanScreenLeft;
3084 pf.top = df.top = of.top = mOverscanScreenTop;
3085 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3086 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3087 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003088 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003089 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
John Spurlockf95b89a2013-10-10 22:10:42 -04003090 && (attrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD || (
3091 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3092 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003093 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003094 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003095 // only do this for application windows to ensure no window that
3096 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003097 pf.left = df.left = mOverscanScreenLeft;
3098 pf.top = df.top = mOverscanScreenTop;
3099 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3100 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003101 // We need to tell the app about where the frame inside the overscan
3102 // is, so it can inset its content by that amount -- it didn't ask
3103 // to actually extend itself into the overscan region.
3104 of.left = mUnrestrictedScreenLeft;
3105 of.top = mUnrestrictedScreenTop;
3106 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3107 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003108 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003109 pf.left = df.left = mRestrictedOverscanScreenLeft;
3110 pf.top = df.top = mRestrictedOverscanScreenTop;
3111 pf.right = df.right = mRestrictedOverscanScreenLeft
3112 + mRestrictedOverscanScreenWidth;
3113 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3114 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003115 // We need to tell the app about where the frame inside the overscan
3116 // is, so it can inset its content by that amount -- it didn't ask
3117 // to actually extend itself into the overscan region.
3118 of.left = mUnrestrictedScreenLeft;
3119 of.top = mUnrestrictedScreenTop;
3120 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3121 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003122 }
Craig Mautner69b08182012-09-05 13:07:13 -07003123
John Spurlock46646232013-09-30 22:32:42 -04003124 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003125 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3126 cf.left = mDockLeft;
3127 cf.top = mDockTop;
3128 cf.right = mDockRight;
3129 cf.bottom = mDockBottom;
3130 } else {
3131 cf.left = mContentLeft;
3132 cf.top = mContentTop;
3133 cf.right = mContentRight;
3134 cf.bottom = mContentBottom;
3135 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003136 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003137 // Full screen windows are always given a layout that is as if the
3138 // status bar and other transient decors are gone. This is to avoid
3139 // bad states when moving from a window that is not hding the
3140 // status bar to one that is.
3141 cf.left = mRestrictedScreenLeft;
3142 cf.top = mRestrictedScreenTop;
3143 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3144 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003145 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003146 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003147 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3148 vf.left = mCurLeft;
3149 vf.top = mCurTop;
3150 vf.right = mCurRight;
3151 vf.bottom = mCurBottom;
3152 } else {
3153 vf.set(cf);
3154 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003155 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003156 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3157 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3158 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003159 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3160 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003161 // A window that has requested to fill the entire screen just
3162 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003163 if (attrs.type == TYPE_STATUS_BAR_PANEL
3164 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003165 pf.left = df.left = of.left = cf.left = hasNavBar
3166 ? mDockLeft : mUnrestrictedScreenLeft;
3167 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3168 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003169 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003170 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003171 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003172 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003173 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003174 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003175 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3176 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003177 } else if (attrs.type == TYPE_NAVIGATION_BAR
3178 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003179 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003180 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3181 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3182 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3183 + mUnrestrictedScreenWidth;
3184 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3185 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003186 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003187 "Laying out navigation bar window: (%d,%d - %d,%d)",
3188 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003189 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3190 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003191 && ((fl & FLAG_FULLSCREEN) != 0)) {
3192 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003193 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3194 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3195 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3196 + mOverscanScreenWidth;
3197 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3198 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003199 } else if (attrs.type == TYPE_BOOT_PROGRESS
3200 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003201 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003202 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3203 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3204 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3205 + mOverscanScreenWidth;
3206 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3207 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003208 } else if (attrs.type == TYPE_WALLPAPER) {
3209 // The wallpaper also has Real Ultimate Power.
3210 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3211 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003212 pf.right = df.right = of.right = cf.right
John Spurlockef4adae2013-08-26 17:58:58 -04003213 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003214 pf.bottom = df.bottom = of.bottom = cf.bottom
John Spurlockef4adae2013-08-26 17:58:58 -04003215 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003216 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003217 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3218 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3219 // Asking to layout into the overscan region, so give it that pure
3220 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003221 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3222 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3223 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003224 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003225 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003226 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003227 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003228 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
John Spurlock34e13d92013-08-10 06:52:28 -04003229 && (attrs.type == TYPE_TOAST
3230 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3231 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003232 // Asking for layout as if the nav bar is hidden, lets the
3233 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003234 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003235 // can be above the nav bar can do this.
3236 // XXX This assumes that an app asking for this will also
3237 // ask for layout in only content. We can't currently figure out
3238 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003239 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3240 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3241 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3242 + mUnrestrictedScreenWidth;
3243 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3244 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003245 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003246 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3247 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3248 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3249 + mRestrictedScreenWidth;
3250 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3251 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003252 }
Craig Mautner69b08182012-09-05 13:07:13 -07003253
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003254 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003255
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003256 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3257 vf.left = mCurLeft;
3258 vf.top = mCurTop;
3259 vf.right = mCurRight;
3260 vf.bottom = mCurBottom;
3261 } else {
3262 vf.set(cf);
3263 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003264 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003265 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3266 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003267 // A child window should be placed inside of the same visible
3268 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003269 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003270 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003271 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3272 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003273 // Otherwise, a normal window must be placed inside the content
3274 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003275 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3276 // Status bar panels are the only windows who can go on top of
3277 // the status bar. They are protected by the STATUS_BAR_SERVICE
3278 // permission, so they have the same privileges as the status
3279 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003280 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3281 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3282 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3283 + mRestrictedScreenWidth;
3284 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3285 + mRestrictedScreenHeight;
John Spurlockca4d0402013-12-04 13:47:36 -05003286 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3287 || attrs.type == TYPE_VOLUME_OVERLAY) {
3288 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003289 pf.left = df.left = of.left = cf.left = mStableLeft;
3290 pf.top = df.top = of.top = cf.top = mStableTop;
3291 pf.right = df.right = of.right = cf.right = mStableRight;
3292 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003293 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003294 pf.left = mContentLeft;
3295 pf.top = mContentTop;
3296 pf.right = mContentRight;
3297 pf.bottom = mContentBottom;
3298 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003299 df.left = of.left = cf.left = mDockLeft;
3300 df.top = of.top = cf.top = mDockTop;
3301 df.right = of.right = cf.right = mDockRight;
3302 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003303 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003304 df.left = of.left = cf.left = mContentLeft;
3305 df.top = of.top = cf.top = mContentTop;
3306 df.right = of.right = cf.right = mContentRight;
3307 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003308 }
3309 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3310 vf.left = mCurLeft;
3311 vf.top = mCurTop;
3312 vf.right = mCurRight;
3313 vf.bottom = mCurBottom;
3314 } else {
3315 vf.set(cf);
3316 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003317 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003318 }
3319 }
Craig Mautner69b08182012-09-05 13:07:13 -07003320
Craig Mautnerb816bed2013-07-23 10:26:17 -07003321 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3322 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003323 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3324 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3325 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003326 }
3327
Craig Mautnereda67292013-04-28 13:50:14 -07003328 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003329 + ": sim=#" + Integer.toHexString(sim)
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003330 + " attach=" + attached + " type=" + attrs.type
3331 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003332 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003333 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003334 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
3335 + " dcf=" + dcf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003336
John Spurlock46646232013-09-30 22:32:42 -04003337 win.computeFrameLw(pf, df, of, cf, vf, dcf);
Craig Mautner69b08182012-09-05 13:07:13 -07003338
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003339 // Dock windows carve out the bottom of the screen, so normal windows
3340 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003341 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3342 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003343 setLastInputMethodWindowLw(null, null);
3344 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003345 }
3346 }
3347
satok1bc0a492012-04-25 22:47:12 +09003348 private void offsetInputMethodWindowLw(WindowState win) {
3349 int top = win.getContentFrameLw().top;
3350 top += win.getGivenContentInsetsLw().top;
3351 if (mContentBottom > top) {
3352 mContentBottom = top;
3353 }
3354 top = win.getVisibleFrameLw().top;
3355 top += win.getGivenVisibleInsetsLw().top;
3356 if (mCurBottom > top) {
3357 mCurBottom = top;
3358 }
Craig Mautnereda67292013-04-28 13:50:14 -07003359 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003360 + mDockBottom + " mContentBottom="
3361 + mContentBottom + " mCurBottom=" + mCurBottom);
3362 }
3363
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003364 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003365 @Override
3366 public void finishLayoutLw() {
3367 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003368 }
3369
3370 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003371 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003372 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003373 mTopFullscreenOpaqueWindowState = null;
Craig Mautner03924422014-03-19 19:48:38 -07003374 mAppsToBeHidden.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003375 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003376 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003377 mForcingShowNavBar = false;
3378 mForcingShowNavBarLayer = -1;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003379
3380 mHideLockScreen = false;
3381 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003382 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003383 mShowingLockscreen = false;
3384 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003385 }
3386
3387 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003388 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003389 public void applyPostLayoutPolicyLw(WindowState win,
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003390 WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003391 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3392 + win.isVisibleOrBehindKeyguardLw());
John Spurlockca4d0402013-12-04 13:47:36 -05003393 if (mTopFullscreenOpaqueWindowState == null
3394 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3395 mForcingShowNavBar = true;
3396 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003397 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003398 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003399 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003400 if ((attrs.flags & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003401 if (attrs.type == TYPE_KEYGUARD) {
3402 mForceStatusBarFromKeyguard = true;
3403 } else {
3404 mForceStatusBar = true;
3405 }
3406 }
3407 if (attrs.type == TYPE_KEYGUARD) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003408 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003409 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003410 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003411 && attrs.type <= LAST_APPLICATION_WINDOW;
3412 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003413 // If the lockscreen was showing when the dream started then wait
3414 // for the dream to draw before hiding the lockscreen.
3415 if (!mDreamingLockscreen
3416 || (win.isVisibleLw() && win.hasDrawnLw())) {
3417 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08003418 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003419 }
3420 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003421
3422 final boolean showWhenLocked = (attrs.flags & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003423 final boolean dismissKeyguard = (attrs.flags & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08003424 if (appWindow) {
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003425 if (showWhenLocked || (dismissKeyguard && !isKeyguardSecure())) {
Craig Mautner03924422014-03-19 19:48:38 -07003426 mAppsToBeHidden.remove(win.getAppToken());
3427 } else {
3428 mAppsToBeHidden.add(win.getAppToken());
3429 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003430 if (attrs.x == 0 && attrs.y == 0
3431 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3432 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
3433 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
3434 mTopFullscreenOpaqueWindowState = win;
Craig Mautner03924422014-03-19 19:48:38 -07003435 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner1f524372014-03-03 13:26:03 -08003436 if (showWhenLocked) {
Craig Mautnerff89d582014-03-13 21:09:35 -07003437 if (DEBUG_LAYOUT) Slog.v(TAG,
3438 "Setting mHideLockScreen to true by win " + win);
Craig Mautner1f524372014-03-03 13:26:03 -08003439 mHideLockScreen = true;
3440 mForceStatusBarFromKeyguard = false;
3441 }
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003442 if (dismissKeyguard && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautner1f524372014-03-03 13:26:03 -08003443 if (DEBUG_LAYOUT) Slog.v(TAG, "Setting mDismissKeyguard true by win " + win);
3444 mDismissKeyguard = mWinDismissingKeyguard == win ?
3445 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3446 mWinDismissingKeyguard = win;
Craig Mautnerff89d582014-03-13 21:09:35 -07003447 mForceStatusBarFromKeyguard = mShowingLockscreen && isKeyguardSecure();
Craig Mautner1f524372014-03-03 13:26:03 -08003448 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003449 }
3450 if ((attrs.flags & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
3451 mAllowLockscreenWhenOn = true;
3452 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003453 }
3454 }
3455 }
3456 }
3457
3458 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003459 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003460 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003461 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003462 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003463
3464 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3465 ? mTopFullscreenOpaqueWindowState.getAttrs()
3466 : null;
3467
Jeff Brownc8018eb2012-10-29 21:33:27 -07003468 // If we are not currently showing a dream then remember the current
3469 // lockscreen state. We will use this to determine whether the dream
3470 // started while the lockscreen was showing and remember this state
3471 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003472 if (!mShowingDream) {
3473 mDreamingLockscreen = mShowingLockscreen;
3474 }
3475
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003476 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003477 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003478 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003479 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003480 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003481 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003482 if (mStatusBarController.setBarShowingLw(true)) {
3483 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3484 }
Craig Mautner81defc72013-10-29 11:10:42 -07003485 // Maintain fullscreen layout until incoming animation is complete.
3486 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05003487 // Transient status bar on the lockscreen is not allowed
3488 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
3489 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
3490 mLastSystemUiFlags, mLastSystemUiFlags);
3491 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003492 } else if (mTopFullscreenOpaqueWindowState != null) {
Joe Onorato93056472010-09-10 10:30:46 -04003493 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003494 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003495 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003496 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
Joe Onorato93056472010-09-10 10:30:46 -04003497 + " lp.flags=0x" + Integer.toHexString(lp.flags));
3498 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003499 topIsFullscreen = (lp.flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
3500 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003501 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3502 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3503 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3504 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003505 if (mStatusBarController.isTransientShowing()) {
3506 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003507 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3508 }
3509 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003510 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003511 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003512 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003513 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003514 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003515 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003516 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003517 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003518 if (mStatusBarController.setBarShowingLw(true)) {
3519 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3520 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003521 }
3522 }
3523 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003524
Craig Mautner81defc72013-10-29 11:10:42 -07003525 if (mTopIsFullscreen != topIsFullscreen) {
3526 if (!topIsFullscreen) {
3527 // Force another layout when status bar becomes fully shown.
3528 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3529 }
3530 mTopIsFullscreen = topIsFullscreen;
3531 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003532
Craig Mautner39834192012-09-02 07:47:24 -07003533 // Hide the key guard if a visible window explicitly specifies that it wants to be
3534 // displayed when the screen is locked.
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003535 if (mKeyguard != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003536 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
Craig Mautner39834192012-09-02 07:47:24 -07003537 + mHideLockScreen);
Craig Mautnerab55e522014-03-03 13:26:03 -08003538 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003539 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003540 changes |= FINISH_LAYOUT_REDO_LAYOUT
3541 | FINISH_LAYOUT_REDO_CONFIG
3542 | FINISH_LAYOUT_REDO_WALLPAPER;
3543 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003544 if (mKeyguardDelegate.isShowing()) {
Dianne Hackbornb446e972009-09-20 15:23:25 -07003545 mHandler.post(new Runnable() {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003546 @Override
Dianne Hackbornb446e972009-09-20 15:23:25 -07003547 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08003548 mKeyguardDelegate.keyguardDone(false, false);
Dianne Hackbornb446e972009-09-20 15:23:25 -07003549 }
3550 });
3551 }
Dianne Hackborn05726582009-09-22 17:28:24 -07003552 } else if (mHideLockScreen) {
Dianne Hackborn08743722009-12-21 12:16:51 -08003553 if (mKeyguard.hideLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003554 changes |= FINISH_LAYOUT_REDO_LAYOUT
3555 | FINISH_LAYOUT_REDO_CONFIG
3556 | FINISH_LAYOUT_REDO_WALLPAPER;
3557 }
Craig Mautner28816302013-10-10 20:31:00 -07003558 if (!mShowingDream) {
3559 mKeyguardDelegate.setHidden(true);
3560 }
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003561 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3562 // This is the case of keyguard isSecure() and not mHideLockScreen.
3563 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3564 // Only launch the next keyguard unlock window once per window.
3565 if (mKeyguard.showLw(true)) {
3566 changes |= FINISH_LAYOUT_REDO_LAYOUT
3567 | FINISH_LAYOUT_REDO_CONFIG
3568 | FINISH_LAYOUT_REDO_WALLPAPER;
3569 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003570 mKeyguardDelegate.setHidden(false);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003571 mHandler.post(new Runnable() {
3572 @Override
3573 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08003574 mKeyguardDelegate.dismiss();
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003575 }
3576 });
3577 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003578 } else {
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003579 mWinDismissingKeyguard = null;
Dianne Hackborn08743722009-12-21 12:16:51 -08003580 if (mKeyguard.showLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003581 changes |= FINISH_LAYOUT_REDO_LAYOUT
3582 | FINISH_LAYOUT_REDO_CONFIG
3583 | FINISH_LAYOUT_REDO_WALLPAPER;
3584 }
Jim Miller5ecd8112013-01-09 18:50:26 -08003585 mKeyguardDelegate.setHidden(false);
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003586 }
3587 }
Joe Onorato664644d2011-01-23 17:53:23 -08003588
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003589 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003590 // If the navigation bar has been hidden or shown, we need to do another
3591 // layout pass to update that window.
3592 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3593 }
Joe Onorato664644d2011-01-23 17:53:23 -08003594
Mike Lockwood28569302010-01-28 11:54:40 -05003595 // update since mAllowLockscreenWhenOn might have changed
3596 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003597 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003598 }
3599
Dianne Hackborn08743722009-12-21 12:16:51 -08003600 public boolean allowAppAnimationsLw() {
Craig Mautner58004432013-10-14 12:58:42 -07003601 if (mKeyguard != null && mKeyguard.isVisibleLw() && !mKeyguard.isAnimatingLw()
3602 || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07003603 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08003604 return false;
3605 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003606 return true;
3607 }
3608
Dianne Hackborndf89e652011-10-06 22:35:11 -07003609 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003610 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003611 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003612 // If the navigation bar has been hidden or shown, we need to do another
3613 // layout pass to update that window.
3614 return FINISH_LAYOUT_REDO_LAYOUT;
3615 }
3616 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003617 }
3618
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003619 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07003620 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
3621 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003622 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3623 if (newLidState == mLidState) {
3624 return;
3625 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003626
Jeff Brownc458ce92012-04-30 14:58:40 -07003627 mLidState = newLidState;
3628 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003629 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003630
3631 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07003632 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07003633 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003634 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003635 }
3636 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003637
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003638 void setHdmiPlugged(boolean plugged) {
3639 if (mHdmiPlugged != plugged) {
3640 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003641 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003642 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003643 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003644 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003645 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003646 }
3647 }
3648
Joe Onoratoea495d42011-04-06 11:41:11 -07003649 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003650 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003651 // watch for HDMI plug messages if the hdmi switch exists
3652 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3653 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3654
Joe Onoratoea495d42011-04-06 11:41:11 -07003655 final String filename = "/sys/class/switch/hdmi/state";
3656 FileReader reader = null;
3657 try {
3658 reader = new FileReader(filename);
3659 char[] buf = new char[15];
3660 int n = reader.read(buf);
3661 if (n > 1) {
3662 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3663 }
3664 } catch (IOException ex) {
3665 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3666 } catch (NumberFormatException ex) {
3667 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3668 } finally {
3669 if (reader != null) {
3670 try {
3671 reader.close();
3672 } catch (IOException ex) {
3673 }
Joe Onoratodc100302011-01-11 17:07:41 -08003674 }
3675 }
3676 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07003677 // This dance forces the code in setHdmiPlugged to run.
3678 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
3679 mHdmiPlugged = !plugged;
3680 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08003681 }
3682
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003683 /**
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003684 * @return Whether music is being played right now "locally" (e.g. on the device's speakers
3685 * or wired headphones) or "remotely" (e.g. on a device using the Cast protocol and
3686 * controlled by this device, or through remote submix).
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003687 */
3688 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07003689 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
3690 if (am == null) {
3691 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003692 return false;
3693 }
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003694 return am.isLocalOrRemoteMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003695 }
3696
3697 /**
3698 * Tell the audio service to adjust the volume appropriate to the event.
3699 * @param keycode
3700 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04003701 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07003702 IAudioService audioService = getAudioService();
3703 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003704 return;
3705 }
3706 try {
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003707 // when audio is playing locally, we shouldn't have to hold a wake lock
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003708 // during the call, but we do it as a precaution for the rare possibility
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003709 // that the music stops right before we call this.
3710 // Otherwise we might also be in a remote playback case.
Jeff Brownb0418da2010-11-01 15:24:01 -07003711 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003712 mBroadcastWakeLock.acquire();
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003713 if (stream == AudioSystem.STREAM_MUSIC) {
3714 audioService.adjustLocalOrRemoteStreamVolume(stream,
3715 keycode == KeyEvent.KEYCODE_VOLUME_UP
3716 ? AudioManager.ADJUST_RAISE
3717 : AudioManager.ADJUST_LOWER,
3718 mContext.getOpPackageName());
3719 } else {
3720 audioService.adjustStreamVolume(stream,
3721 keycode == KeyEvent.KEYCODE_VOLUME_UP
3722 ? AudioManager.ADJUST_RAISE
3723 : AudioManager.ADJUST_LOWER,
3724 0,
3725 mContext.getOpPackageName());
3726 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003727 } catch (RemoteException e) {
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003728 Log.w(TAG, "IAudioService.adjust*StreamVolume() threw RemoteException " + e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003729 } finally {
3730 mBroadcastWakeLock.release();
3731 }
3732 }
Jeff Brown4d396052010-10-29 21:50:21 -07003733
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07003734 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003735 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003736
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003737 final Runnable mScreenshotTimeout = new Runnable() {
3738 @Override public void run() {
3739 synchronized (mScreenshotLock) {
3740 if (mScreenshotConnection != null) {
3741 mContext.unbindService(mScreenshotConnection);
3742 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003743 }
Winson Chung9112ec32011-06-27 13:15:32 -07003744 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003745 }
3746 };
3747
3748 // Assume this is called from the Handler thread.
3749 private void takeScreenshot() {
3750 synchronized (mScreenshotLock) {
3751 if (mScreenshotConnection != null) {
3752 return;
3753 }
3754 ComponentName cn = new ComponentName("com.android.systemui",
3755 "com.android.systemui.screenshot.TakeScreenshotService");
3756 Intent intent = new Intent();
3757 intent.setComponent(cn);
3758 ServiceConnection conn = new ServiceConnection() {
3759 @Override
3760 public void onServiceConnected(ComponentName name, IBinder service) {
3761 synchronized (mScreenshotLock) {
3762 if (mScreenshotConnection != this) {
3763 return;
3764 }
3765 Messenger messenger = new Messenger(service);
3766 Message msg = Message.obtain(null, 1);
3767 final ServiceConnection myConn = this;
3768 Handler h = new Handler(mHandler.getLooper()) {
3769 @Override
3770 public void handleMessage(Message msg) {
3771 synchronized (mScreenshotLock) {
3772 if (mScreenshotConnection == myConn) {
3773 mContext.unbindService(mScreenshotConnection);
3774 mScreenshotConnection = null;
3775 mHandler.removeCallbacks(mScreenshotTimeout);
3776 }
3777 }
3778 }
3779 };
3780 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07003781 msg.arg1 = msg.arg2 = 0;
3782 if (mStatusBar != null && mStatusBar.isVisibleLw())
3783 msg.arg1 = 1;
3784 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
3785 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003786 try {
3787 messenger.send(msg);
3788 } catch (RemoteException e) {
3789 }
3790 }
3791 }
3792 @Override
3793 public void onServiceDisconnected(ComponentName name) {}
3794 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08003795 if (mContext.bindServiceAsUser(
3796 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003797 mScreenshotConnection = conn;
3798 mHandler.postDelayed(mScreenshotTimeout, 10000);
3799 }
3800 }
Winson Chung9112ec32011-06-27 13:15:32 -07003801 }
3802
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003803 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003804 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07003805 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07003806 if (!mSystemBooted) {
3807 // If we have not yet booted, don't let key events do anything.
3808 return 0;
3809 }
3810
Jeff Brown037c33e2014-04-09 00:31:55 -07003811 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08003812 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3813 final boolean canceled = event.isCanceled();
3814 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07003815
Jeff Brown3122e442010-10-11 23:32:49 -07003816 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07003817
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05003818 // If screen is off then we treat the case where the keyguard is open but hidden
3819 // the same as if it were open and in front.
3820 // This will prevent any keys other than the power button from waking the screen
3821 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08003822 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07003823 (interactive ?
Jim Miller5ecd8112013-01-09 18:50:26 -08003824 mKeyguardDelegate.isShowingAndNotHidden() :
3825 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003826
Jeff Brown6212a492014-03-07 13:58:47 -08003827 if (keyCode == KeyEvent.KEYCODE_POWER
3828 || keyCode == KeyEvent.KEYCODE_SLEEP
3829 || keyCode == KeyEvent.KEYCODE_WAKEUP) {
Jeff Brown96307042012-07-27 15:51:34 -07003830 policyFlags |= WindowManagerPolicy.FLAG_WAKE;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07003831 }
3832
Jeff Brown40013652012-05-16 21:22:36 -07003833 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003834 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07003835 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08003836 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003837 }
3838
Jeff Brown98392ef2011-09-12 18:24:59 -07003839 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
3840 && event.getRepeatCount() == 0) {
Jeff Brown4d396052010-10-29 21:50:21 -07003841 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
3842 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003843
Jeff Brown037c33e2014-04-09 00:31:55 -07003844 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07003845 int result;
Jeff Brown26875502014-01-30 21:47:47 -08003846 boolean isWakeKey = (policyFlags & (WindowManagerPolicy.FLAG_WAKE
3847 | WindowManagerPolicy.FLAG_WAKE_DROPPED)) != 0;
Jeff Brown037c33e2014-04-09 00:31:55 -07003848 if (interactive || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003849 // When the screen is on or if the key is injected pass the key to the application.
3850 result = ACTION_PASS_TO_USER;
3851 } else {
3852 // When the screen is off and the key is not injected, determine whether
3853 // to wake the device but don't pass the key to the application.
3854 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08003855 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
3856 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003857 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003858 }
3859
Justin Kohd378ad72013-04-01 12:18:26 -07003860 // If the key would be handled globally, just return the result, don't worry about special
3861 // key processing.
3862 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
3863 return result;
3864 }
3865
Jeff Brown4d396052010-10-29 21:50:21 -07003866 // Handle special keys.
3867 switch (keyCode) {
3868 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07003869 case KeyEvent.KEYCODE_VOLUME_UP:
3870 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003871 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
3872 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003873 if (interactive && !mVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003874 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3875 mVolumeDownKeyTriggered = true;
3876 mVolumeDownKeyTime = event.getDownTime();
3877 mVolumeDownKeyConsumedByScreenshotChord = false;
3878 cancelPendingPowerKeyAction();
3879 interceptScreenshotChord();
3880 }
3881 } else {
3882 mVolumeDownKeyTriggered = false;
3883 cancelPendingScreenshotChordAction();
3884 }
3885 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
3886 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003887 if (interactive && !mVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003888 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3889 mVolumeUpKeyTriggered = true;
3890 cancelPendingPowerKeyAction();
3891 cancelPendingScreenshotChordAction();
3892 }
3893 } else {
3894 mVolumeUpKeyTriggered = false;
3895 cancelPendingScreenshotChordAction();
3896 }
3897 }
Jeff Brown4d396052010-10-29 21:50:21 -07003898 if (down) {
3899 ITelephony telephonyService = getTelephonyService();
3900 if (telephonyService != null) {
3901 try {
3902 if (telephonyService.isRinging()) {
3903 // If an incoming call is ringing, either VOLUME key means
3904 // "silence ringer". We handle these keys here, rather than
3905 // in the InCallScreen, to make sure we'll respond to them
3906 // even if the InCallScreen hasn't come to the foreground yet.
3907 // Look for the DOWN event here, to agree with the "fallback"
3908 // behavior in the InCallScreen.
3909 Log.i(TAG, "interceptKeyBeforeQueueing:"
3910 + " VOLUME key-down while ringing: Silence ringer!");
3911
3912 // Silence the ringer. (It's safe to call this
3913 // even if the ringer has already been silenced.)
3914 telephonyService.silenceRinger();
3915
3916 // And *don't* pass this key thru to the current activity
3917 // (which is probably the InCallScreen.)
3918 result &= ~ACTION_PASS_TO_USER;
3919 break;
3920 }
3921 if (telephonyService.isOffhook()
3922 && (result & ACTION_PASS_TO_USER) == 0) {
3923 // If we are in call but we decided not to pass the key to
3924 // the application, handle the volume change here.
3925 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
3926 break;
3927 }
3928 } catch (RemoteException ex) {
3929 Log.w(TAG, "ITelephony threw RemoteException", ex);
3930 }
3931 }
3932
3933 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
3934 // If music is playing but we decided not to pass the key to the
3935 // application, handle the volume change here.
3936 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
3937 break;
3938 }
3939 }
3940 break;
3941 }
3942
3943 case KeyEvent.KEYCODE_ENDCALL: {
3944 result &= ~ACTION_PASS_TO_USER;
3945 if (down) {
3946 ITelephony telephonyService = getTelephonyService();
3947 boolean hungUp = false;
3948 if (telephonyService != null) {
3949 try {
3950 hungUp = telephonyService.endCall();
3951 } catch (RemoteException ex) {
3952 Log.w(TAG, "ITelephony threw RemoteException", ex);
3953 }
3954 }
Jeff Brown037c33e2014-04-09 00:31:55 -07003955 interceptPowerKeyDown(!interactive || hungUp);
Jeff Brown4d396052010-10-29 21:50:21 -07003956 } else {
3957 if (interceptPowerKeyUp(canceled)) {
3958 if ((mEndcallBehavior
3959 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
3960 if (goHome()) {
3961 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07003962 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003963 }
Jeff Brown4d396052010-10-29 21:50:21 -07003964 if ((mEndcallBehavior
3965 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown26875502014-01-30 21:47:47 -08003966 mPowerManager.goToSleep(event.getEventTime());
3967 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07003968 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003969 }
Jeff Brown4d396052010-10-29 21:50:21 -07003970 }
3971 break;
3972 }
3973
3974 case KeyEvent.KEYCODE_POWER: {
3975 result &= ~ACTION_PASS_TO_USER;
3976 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003977 mImmersiveModeConfirmation.onPowerKeyDown(interactive, event.getDownTime(),
John Spurlockf1a36642013-10-12 17:50:42 -04003978 isImmersiveMode(mLastSystemUiFlags));
Jeff Brown037c33e2014-04-09 00:31:55 -07003979 if (interactive && !mPowerKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003980 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3981 mPowerKeyTriggered = true;
3982 mPowerKeyTime = event.getDownTime();
3983 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07003984 }
Winson Chung9112ec32011-06-27 13:15:32 -07003985
Jeff Brown4d396052010-10-29 21:50:21 -07003986 ITelephony telephonyService = getTelephonyService();
3987 boolean hungUp = false;
3988 if (telephonyService != null) {
3989 try {
3990 if (telephonyService.isRinging()) {
3991 // Pressing Power while there's a ringing incoming
3992 // call should silence the ringer.
3993 telephonyService.silenceRinger();
3994 } else if ((mIncallPowerBehavior
3995 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
3996 && telephonyService.isOffhook()) {
3997 // Otherwise, if "Power button ends call" is enabled,
3998 // the Power button will hang up any current active call.
3999 hungUp = telephonyService.endCall();
4000 }
4001 } catch (RemoteException ex) {
4002 Log.w(TAG, "ITelephony threw RemoteException", ex);
4003 }
4004 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004005 interceptPowerKeyDown(!interactive || hungUp
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004006 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004007 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004008 mPowerKeyTriggered = false;
4009 cancelPendingScreenshotChordAction();
4010 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown26875502014-01-30 21:47:47 -08004011 mPowerManager.goToSleep(event.getEventTime());
4012 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004013 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004014 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004015 }
4016 break;
4017 }
4018
Jeff Brown6212a492014-03-07 13:58:47 -08004019 case KeyEvent.KEYCODE_SLEEP: {
4020 result &= ~ACTION_PASS_TO_USER;
4021 mPowerManager.goToSleep(event.getEventTime());
4022 isWakeKey = false;
4023 break;
4024 }
4025
4026 case KeyEvent.KEYCODE_WAKEUP: {
4027 result &= ~ACTION_PASS_TO_USER;
4028 break;
4029 }
4030
Jeff Brown4d396052010-10-29 21:50:21 -07004031 case KeyEvent.KEYCODE_MEDIA_PLAY:
4032 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4033 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4034 if (down) {
4035 ITelephony telephonyService = getTelephonyService();
4036 if (telephonyService != null) {
4037 try {
4038 if (!telephonyService.isIdle()) {
4039 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
4040 // to avoid music playback.
4041 break;
4042 }
4043 } catch (RemoteException ex) {
4044 Log.w(TAG, "ITelephony threw RemoteException", ex);
Jeff Brown3122e442010-10-11 23:32:49 -07004045 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004046 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004047 }
Jeff Brown4d396052010-10-29 21:50:21 -07004048 case KeyEvent.KEYCODE_HEADSETHOOK:
4049 case KeyEvent.KEYCODE_MUTE:
4050 case KeyEvent.KEYCODE_MEDIA_STOP:
4051 case KeyEvent.KEYCODE_MEDIA_NEXT:
4052 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4053 case KeyEvent.KEYCODE_MEDIA_REWIND:
4054 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004055 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4056 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07004057 if ((result & ACTION_PASS_TO_USER) == 0) {
4058 // Only do this if we would otherwise not pass it to the user. In that
4059 // case, the PhoneWindow class will do the same thing, except it will
4060 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004061 // Note that we need to make a copy of the key event here because the
4062 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004063 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004064 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4065 new KeyEvent(event));
4066 msg.setAsynchronous(true);
4067 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004068 }
4069 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004070 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004071
Jeff Brown4d396052010-10-29 21:50:21 -07004072 case KeyEvent.KEYCODE_CALL: {
4073 if (down) {
4074 ITelephony telephonyService = getTelephonyService();
4075 if (telephonyService != null) {
4076 try {
4077 if (telephonyService.isRinging()) {
4078 Log.i(TAG, "interceptKeyBeforeQueueing:"
4079 + " CALL key-down while ringing: Answer the call!");
4080 telephonyService.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004081
Jeff Brown4d396052010-10-29 21:50:21 -07004082 // And *don't* pass this key thru to the current activity
4083 // (which is presumably the InCallScreen.)
4084 result &= ~ACTION_PASS_TO_USER;
4085 }
4086 } catch (RemoteException ex) {
4087 Log.w(TAG, "ITelephony threw RemoteException", ex);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004088 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004089 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004090 }
Jeff Brown4d396052010-10-29 21:50:21 -07004091 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004092 }
4093 }
Jeff Brown26875502014-01-30 21:47:47 -08004094
4095 if (isWakeKey) {
4096 mPowerManager.wakeUp(event.getEventTime());
4097 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004098 return result;
4099 }
4100
Jeff Brown1c2e4942012-11-06 16:32:01 -08004101 /**
4102 * When the screen is off we ignore some keys that might otherwise typically
4103 * be considered wake keys. We filter them out here.
4104 *
4105 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4106 * is always considered a wake key.
4107 */
4108 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4109 switch (keyCode) {
4110 // ignore volume keys unless docked
4111 case KeyEvent.KEYCODE_VOLUME_UP:
4112 case KeyEvent.KEYCODE_VOLUME_DOWN:
4113 case KeyEvent.KEYCODE_VOLUME_MUTE:
4114 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4115
4116 // ignore media and camera keys
4117 case KeyEvent.KEYCODE_MUTE:
4118 case KeyEvent.KEYCODE_HEADSETHOOK:
4119 case KeyEvent.KEYCODE_MEDIA_PLAY:
4120 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4121 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4122 case KeyEvent.KEYCODE_MEDIA_STOP:
4123 case KeyEvent.KEYCODE_MEDIA_NEXT:
4124 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4125 case KeyEvent.KEYCODE_MEDIA_REWIND:
4126 case KeyEvent.KEYCODE_MEDIA_RECORD:
4127 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004128 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004129 case KeyEvent.KEYCODE_CAMERA:
4130 return false;
4131 }
4132 return true;
4133 }
4134
4135
Jeff Brown56194eb2011-03-02 19:23:13 -08004136 /** {@inheritDoc} */
4137 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004138 public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
4139 // We already know this is a wake motion so just wake up.
4140 // Note that we would observe policyFlags containing
4141 // FLAG_WAKE and FLAG_INTERACTIVE here.
4142 mPowerManager.wakeUp(whenNanos / 1000000);
4143 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004144 }
4145
Jeff Brown40013652012-05-16 21:22:36 -07004146 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4147 if (DEBUG_INPUT) {
4148 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004149 }
4150
Jeff Brown40013652012-05-16 21:22:36 -07004151 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4152 if (DEBUG_INPUT) {
4153 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4154 }
4155
4156 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4157 mHavePendingMediaKeyRepeatWithWakeLock = false;
4158 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4159 }
4160
4161 dispatchMediaKeyWithWakeLockToAudioService(event);
4162
4163 if (event.getAction() == KeyEvent.ACTION_DOWN
4164 && event.getRepeatCount() == 0) {
4165 mHavePendingMediaKeyRepeatWithWakeLock = true;
4166
4167 Message msg = mHandler.obtainMessage(
4168 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4169 msg.setAsynchronous(true);
4170 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4171 } else {
4172 mBroadcastWakeLock.release();
4173 }
4174 }
4175
4176 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4177 mHavePendingMediaKeyRepeatWithWakeLock = false;
4178
4179 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4180 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4181 if (DEBUG_INPUT) {
4182 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4183 }
4184
4185 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4186 mBroadcastWakeLock.release();
4187 }
4188
4189 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4190 if (ActivityManagerNative.isSystemReady()) {
4191 IAudioService audioService = getAudioService();
4192 if (audioService != null) {
4193 try {
4194 audioService.dispatchMediaKeyEventUnderWakelock(event);
4195 } catch (RemoteException e) {
4196 Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
Jean-Michel Trivic6802222012-04-30 11:15:03 -07004197 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004198 }
4199 }
4200 }
4201
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004202 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004203 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004204 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004205 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4206 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4207 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004208 } else {
4209 try {
4210 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4211 ServiceManager.getService(Context.UI_MODE_SERVICE));
4212 mUiMode = uiModeService.getCurrentModeType();
4213 } catch (RemoteException e) {
4214 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004215 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004216 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004217 synchronized (mLock) {
4218 updateOrientationListenerLp();
4219 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004220 }
4221 };
4222
Jeff Brown6aaf2952012-10-05 16:01:08 -07004223 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4224 @Override
4225 public void onReceive(Context context, Intent intent) {
4226 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004227 if (mKeyguardDelegate != null) {
4228 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004229 }
4230 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004231 if (mKeyguardDelegate != null) {
4232 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004233 }
4234 }
4235 }
4236 };
4237
Christopher Tate5e08af02012-09-21 17:17:22 -07004238 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4239 @Override
4240 public void onReceive(Context context, Intent intent) {
4241 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4242 // tickle the settings observer: this first ensures that we're
4243 // observing the relevant settings for the newly-active user,
4244 // and then updates our own bookkeeping based on the now-
4245 // current user.
4246 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004247
4248 // force a re-application of focused window sysui visibility.
4249 // the window may never have been shown for this user
4250 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004251 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004252 mLastSystemUiFlags = 0;
4253 updateSystemUiVisibilityLw();
4254 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004255 }
4256 }
4257 };
4258
John Spurlocke1f366f2013-08-05 12:22:40 -04004259 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004260 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlock27735a42013-08-14 17:57:38 -04004261 boolean sb = mStatusBarController.checkShowTransientBarLw();
4262 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004263 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004264 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4265 if (sb ^ nb && barTarget != swipeTarget) {
4266 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004267 return;
4268 }
John Spurlock27735a42013-08-14 17:57:38 -04004269 if (sb) mStatusBarController.showTransient();
4270 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004271 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004272 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004273 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004274 }
4275 }
4276
Jeff Brownc38c9be2012-10-04 13:16:19 -07004277 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004278 public void screenTurnedOff(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004279 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004280 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004281 mScreenOnEarly = false;
4282 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004283 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004284 if (mKeyguardDelegate != null) {
4285 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004286 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004287 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07004288 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004289 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004290 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004291 }
4292
Jeff Brownc38c9be2012-10-04 13:16:19 -07004293 @Override
Dianne Hackborn38e29a62011-09-18 14:43:08 -07004294 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004295 EventLog.writeEvent(70000, 1);
Dianne Hackborn40011092011-09-22 13:37:48 -07004296 if (false) {
4297 RuntimeException here = new RuntimeException("here");
4298 here.fillInStackTrace();
4299 Slog.i(TAG, "Screen turning on...", here);
4300 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004301
The Android Open Source Project0727d222009-03-11 12:11:58 -07004302 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004303 mScreenOnEarly = true;
The Android Open Source Project0727d222009-03-11 12:11:58 -07004304 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004305 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004306 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004307
Jeff Brownc38c9be2012-10-04 13:16:19 -07004308 waitForKeyguard(screenOnListener);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004309 }
4310
Jeff Brownc38c9be2012-10-04 13:16:19 -07004311 private void waitForKeyguard(final ScreenOnListener screenOnListener) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004312 if (mKeyguardDelegate != null) {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004313 if (screenOnListener != null) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004314 mKeyguardDelegate.onScreenTurnedOn(new KeyguardServiceDelegate.ShowListener() {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004315 @Override
4316 public void onShown(IBinder windowToken) {
4317 waitForKeyguardWindowDrawn(windowToken, screenOnListener);
4318 }
4319 });
4320 return;
4321 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -08004322 mKeyguardDelegate.onScreenTurnedOn(null);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004323 }
4324 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -08004325 Slog.i(TAG, "No keyguard interface!");
Jeff Brownc38c9be2012-10-04 13:16:19 -07004326 }
4327 finishScreenTurningOn(screenOnListener);
4328 }
4329
4330 private void waitForKeyguardWindowDrawn(IBinder windowToken,
4331 final ScreenOnListener screenOnListener) {
Craig Mautner6f295902013-10-11 21:43:06 -07004332 if (windowToken != null && !mHideLockScreen) {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004333 try {
4334 if (mWindowManager.waitForWindowDrawn(
4335 windowToken, new IRemoteCallback.Stub() {
4336 @Override
4337 public void sendResult(Bundle data) {
4338 Slog.i(TAG, "Lock screen displayed!");
4339 finishScreenTurningOn(screenOnListener);
4340 }
4341 })) {
4342 return;
4343 }
Craig Mautner4e8a19c2013-10-08 17:26:08 -07004344 Slog.i(TAG, "No lock screen! waitForWindowDrawn false");
4345
Jeff Brownc38c9be2012-10-04 13:16:19 -07004346 } catch (RemoteException ex) {
4347 // Can't happen in system process.
4348 }
4349 }
4350
Craig Mautner4e8a19c2013-10-08 17:26:08 -07004351 Slog.i(TAG, "No lock screen! windowToken=" + windowToken);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004352 finishScreenTurningOn(screenOnListener);
4353 }
4354
4355 private void finishScreenTurningOn(ScreenOnListener screenOnListener) {
4356 synchronized (mLock) {
4357 mScreenOnFully = true;
4358 }
4359
Jeff Brown4fc45272012-10-10 18:28:14 -07004360 try {
4361 mWindowManager.setEventDispatching(true);
4362 } catch (RemoteException unhandled) {
4363 }
4364
Jeff Brownc38c9be2012-10-04 13:16:19 -07004365 if (screenOnListener != null) {
4366 screenOnListener.onScreenOn();
4367 }
4368 }
4369
4370 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004371 public boolean isScreenOnEarly() {
4372 return mScreenOnEarly;
4373 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004374
4375 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004376 public boolean isScreenOnFully() {
4377 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004378 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004379
Dianne Hackborn08743722009-12-21 12:16:51 -08004380 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004381 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004382 if (mKeyguardDelegate != null) {
4383 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004384 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004385 }
4386
4387 /** {@inheritDoc} */
4388 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004389 if (mKeyguardDelegate != null) {
4390 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004391 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004392 }
4393
Mike Lockwoodf7913302009-11-28 22:27:10 -05004394 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004395 if (mKeyguardDelegate == null) return false;
4396 return mKeyguardDelegate.isShowingAndNotHidden();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004397 }
4398
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004399
4400 /** {@inheritDoc} */
4401 public boolean isKeyguardLocked() {
4402 return keyguardOn();
4403 }
4404
4405 /** {@inheritDoc} */
4406 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004407 if (mKeyguardDelegate == null) return false;
4408 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004409 }
4410
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004411 /** {@inheritDoc} */
4412 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004413 if (mKeyguardDelegate == null) return false;
4414 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004415 }
4416
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004417 public void dismissKeyguardLw() {
Jim Miller195b5512013-02-28 03:35:57 -08004418 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004419 mHandler.post(new Runnable() {
4420 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004421 if (mKeyguardDelegate.isDismissable()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004422 // Can we just finish the keyguard straight away?
Jim Miller5ecd8112013-01-09 18:50:26 -08004423 mKeyguardDelegate.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004424 } else {
4425 // ask the keyguard to prompt the user to authenticate if necessary
Jim Miller5ecd8112013-01-09 18:50:26 -08004426 mKeyguardDelegate.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004427 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004428 }
4429 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004430 }
4431 }
4432
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004433 void sendCloseSystemWindows() {
4434 sendCloseSystemWindows(mContext, null);
4435 }
4436
4437 void sendCloseSystemWindows(String reason) {
4438 sendCloseSystemWindows(mContext, reason);
4439 }
4440
4441 static void sendCloseSystemWindows(Context context, String reason) {
4442 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004443 try {
4444 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4445 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004446 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004447 }
4448 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004449
Jeff Brown01a98dd2011-09-20 15:08:29 -07004450 @Override
4451 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004452 if (false) {
4453 Slog.v(TAG, "rotationForOrientationLw(orient="
4454 + orientation + ", last=" + lastRotation
4455 + "); user=" + mUserRotation + " "
4456 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4457 ? "USER_ROTATION_LOCKED" : "")
4458 );
4459 }
4460
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004461 if (mForceDefaultOrientation) {
4462 return Surface.ROTATION_0;
4463 }
4464
The Android Open Source Project0727d222009-03-11 12:11:58 -07004465 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004466 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4467 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004468 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004469 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004470
Jeff Browndec6cf42011-11-15 14:08:20 -08004471 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004472 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004473 // Ignore sensor when lid switch is open and rotation is forced.
4474 preferredRotation = mLidOpenRotation;
4475 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004476 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004477 // Ignore sensor when in car dock unless explicitly enabled.
4478 // This case can override the behavior of NOSENSOR, and can also
4479 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004480 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004481 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004482 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4483 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4484 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004485 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004486 // Ignore sensor when in desk dock unless explicitly enabled.
4487 // This case can override the behavior of NOSENSOR, and can also
4488 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004489 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004490 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004491 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4492 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004493 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004494 preferredRotation = mDemoHdmiRotation;
4495 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4496 && mUndockedHdmiRotation >= 0) {
4497 // Ignore sensor when plugged into HDMI and an undocked orientation has
4498 // been specified in the configuration (only for legacy devices without
4499 // full multi-display support).
4500 // Note that the dock orientation overrides the HDMI orientation.
4501 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004502 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4503 // Application just wants to remain locked in the last rotation.
4504 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08004505 } else if (!mSupportAutoRotation) {
4506 // If we don't support auto-rotation then bail out here and ignore
4507 // the sensor and any rotation lock settings.
4508 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07004509 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004510 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004511 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4512 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4513 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4514 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004515 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4516 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4517 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4518 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4519 // Otherwise, use sensor only if requested by the application or enabled
4520 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004521 if (mAllowAllRotations < 0) {
4522 // Can't read this during init() because the context doesn't
4523 // have display metrics at that time so we cannot determine
4524 // tablet vs. phone then.
4525 mAllowAllRotations = mContext.getResources().getBoolean(
4526 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4527 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004528 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004529 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004530 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4531 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004532 preferredRotation = sensorRotation;
4533 } else {
4534 preferredRotation = lastRotation;
4535 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004536 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4537 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4538 // Apply rotation lock. Does not apply to NOSENSOR.
4539 // The idea is that the user rotation expresses a weak preference for the direction
4540 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4541 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004542 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004543 } else {
4544 // No overriding preference.
4545 // We will do exactly what the application asked us to do.
4546 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004547 }
4548
Dianne Hackborne5439f22010-10-02 16:53:50 -07004549 switch (orientation) {
4550 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004551 // Return portrait unless overridden.
4552 if (isAnyPortrait(preferredRotation)) {
4553 return preferredRotation;
4554 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004555 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004556
Jeff Brown01a98dd2011-09-20 15:08:29 -07004557 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004558 // Return landscape unless overridden.
4559 if (isLandscapeOrSeascape(preferredRotation)) {
4560 return preferredRotation;
4561 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004562 return mLandscapeRotation;
4563
4564 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004565 // Return reverse portrait unless overridden.
4566 if (isAnyPortrait(preferredRotation)) {
4567 return preferredRotation;
4568 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004569 return mUpsideDownRotation;
4570
4571 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004572 // Return seascape unless overridden.
4573 if (isLandscapeOrSeascape(preferredRotation)) {
4574 return preferredRotation;
4575 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004576 return mSeascapeRotation;
4577
4578 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004579 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004580 // Return either landscape rotation.
4581 if (isLandscapeOrSeascape(preferredRotation)) {
4582 return preferredRotation;
4583 }
4584 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004585 return lastRotation;
4586 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004587 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004588
Jeff Brown01a98dd2011-09-20 15:08:29 -07004589 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004590 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004591 // Return either portrait rotation.
4592 if (isAnyPortrait(preferredRotation)) {
4593 return preferredRotation;
4594 }
4595 if (isAnyPortrait(lastRotation)) {
4596 return lastRotation;
4597 }
4598 return mPortraitRotation;
4599
4600 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004601 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4602 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004603 if (preferredRotation >= 0) {
4604 return preferredRotation;
4605 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004606 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004607 }
4608 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004609 }
4610
Jeff Brown01a98dd2011-09-20 15:08:29 -07004611 @Override
4612 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4613 switch (orientation) {
4614 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4615 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4616 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4617 return isAnyPortrait(rotation);
4618
4619 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4620 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4621 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4622 return isLandscapeOrSeascape(rotation);
4623
4624 default:
4625 return true;
4626 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004627 }
4628
Jeff Brownc0347aa2011-09-23 17:26:09 -07004629 @Override
4630 public void setRotationLw(int rotation) {
4631 mOrientationListener.setCurrentRotation(rotation);
4632 }
4633
Jeff Brown01a98dd2011-09-20 15:08:29 -07004634 private boolean isLandscapeOrSeascape(int rotation) {
4635 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004636 }
4637
Jeff Brown01a98dd2011-09-20 15:08:29 -07004638 private boolean isAnyPortrait(int rotation) {
4639 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004640 }
4641
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004642 public int getUserRotationMode() {
4643 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07004644 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
4645 WindowManagerPolicy.USER_ROTATION_FREE :
4646 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004647 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004648
4649 // User rotation: to be used when all else fails in assigning an orientation to the device
4650 public void setUserRotationMode(int mode, int rot) {
4651 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004652
4653 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004654 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004655 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004656 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004657 rot,
4658 UserHandle.USER_CURRENT);
4659 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004660 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004661 0,
4662 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004663 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004664 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004665 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004666 1,
4667 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004668 }
4669 }
4670
Jeff Brownac143512012-04-05 18:57:33 -07004671 public void setSafeMode(boolean safeMode) {
4672 mSafeMode = safeMode;
4673 performHapticFeedbackLw(null, safeMode
4674 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4675 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004676 }
Craig Mautnereda67292013-04-28 13:50:14 -07004677
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004678 static long[] getLongIntArray(Resources r, int resid) {
4679 int[] ar = r.getIntArray(resid);
4680 if (ar == null) {
4681 return null;
4682 }
4683 long[] out = new long[ar.length];
4684 for (int i=0; i<ar.length; i++) {
4685 out[i] = ar[i];
4686 }
4687 return out;
4688 }
Craig Mautnereda67292013-04-28 13:50:14 -07004689
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004690 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004691 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004692 public void systemReady() {
Mike Lockwoode63f6f72013-11-15 11:01:47 -08004693 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
4694 mKeyguardDelegate.onSystemReady();
4695
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004696 synchronized (mLock) {
4697 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08004698 mSystemReady = true;
4699 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07004700 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08004701 public void run() {
4702 updateSettings();
4703 }
4704 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004705 }
4706 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07004707
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004708 /** {@inheritDoc} */
4709 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07004710 if (mKeyguardDelegate != null) {
4711 mKeyguardDelegate.onBootCompleted();
4712 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004713 synchronized (mLock) {
4714 mSystemBooted = true;
4715 }
4716 }
4717
Dianne Hackborn661cd522011-08-22 00:26:20 -07004718 ProgressDialog mBootMsgDialog = null;
4719
4720 /** {@inheritDoc} */
4721 public void showBootMessage(final CharSequence msg, final boolean always) {
4722 mHandler.post(new Runnable() {
4723 @Override public void run() {
4724 if (mBootMsgDialog == null) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07004725 mBootMsgDialog = new ProgressDialog(mContext) {
4726 // This dialog will consume all events coming in to
4727 // it, to avoid it trying to do things too early in boot.
4728 @Override public boolean dispatchKeyEvent(KeyEvent event) {
4729 return true;
4730 }
4731 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
4732 return true;
4733 }
4734 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
4735 return true;
4736 }
4737 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
4738 return true;
4739 }
4740 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
4741 return true;
4742 }
4743 @Override public boolean dispatchPopulateAccessibilityEvent(
4744 AccessibilityEvent event) {
4745 return true;
4746 }
4747 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07004748 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
4749 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
4750 mBootMsgDialog.setIndeterminate(true);
4751 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004752 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004753 mBootMsgDialog.getWindow().addFlags(
4754 WindowManager.LayoutParams.FLAG_DIM_BEHIND
4755 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
4756 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08004757 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
4758 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
4759 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004760 mBootMsgDialog.setCancelable(false);
4761 mBootMsgDialog.show();
4762 }
4763 mBootMsgDialog.setMessage(msg);
4764 }
4765 });
4766 }
4767
4768 /** {@inheritDoc} */
4769 public void hideBootMessages() {
4770 mHandler.post(new Runnable() {
4771 @Override public void run() {
4772 if (mBootMsgDialog != null) {
4773 mBootMsgDialog.dismiss();
4774 mBootMsgDialog = null;
4775 }
4776 }
4777 });
4778 }
4779
Mike Lockwood28569302010-01-28 11:54:40 -05004780 /** {@inheritDoc} */
4781 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004782 // ***************************************
4783 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
4784 // ***************************************
4785 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
4786 // WITH ITS LOCKS HELD.
4787 //
4788 // This code must be VERY careful about the locks
4789 // it acquires.
4790 // In fact, the current code acquires way too many,
4791 // and probably has lurking deadlocks.
4792
Mike Lockwood28569302010-01-28 11:54:40 -05004793 synchronized (mScreenLockTimeout) {
4794 if (mLockScreenTimerActive) {
4795 // reset the timer
4796 mHandler.removeCallbacks(mScreenLockTimeout);
4797 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4798 }
4799 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04004800 }
4801
Adam Cohenf7522022012-10-03 20:03:18 -07004802 class ScreenLockTimeout implements Runnable {
4803 Bundle options;
4804
4805 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05004806 public void run() {
4807 synchronized (this) {
4808 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08004809 if (mKeyguardDelegate != null) {
4810 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004811 }
Mike Lockwood28569302010-01-28 11:54:40 -05004812 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07004813 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05004814 }
4815 }
Mike Lockwood28569302010-01-28 11:54:40 -05004816
Adam Cohenf7522022012-10-03 20:03:18 -07004817 public void setLockOptions(Bundle options) {
4818 this.options = options;
4819 }
4820 }
4821
4822 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
4823
4824 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08004825 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
4826 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07004827 if (options != null) {
4828 // In case multiple calls are made to lockNow, we don't wipe out the options
4829 // until the runnable actually executes.
4830 mScreenLockTimeout.setLockOptions(options);
4831 }
Jim Miller93c518e2012-01-17 15:55:31 -08004832 mHandler.post(mScreenLockTimeout);
4833 }
4834
Mike Lockwood28569302010-01-28 11:54:40 -05004835 private void updateLockScreenTimeout() {
4836 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004837 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08004838 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05004839 if (mLockScreenTimerActive != enable) {
4840 if (enable) {
4841 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
4842 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4843 } else {
4844 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
4845 mHandler.removeCallbacks(mScreenLockTimeout);
4846 }
4847 mLockScreenTimerActive = enable;
4848 }
4849 }
4850 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004851
4852 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004853 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004854 public void enableScreenAfterBoot() {
4855 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07004856 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004857 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004858 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07004859
Jeff Brownc458ce92012-04-30 14:58:40 -07004860 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07004861 if (mLidState == LID_CLOSED && mLidControlsSleep) {
4862 mPowerManager.goToSleep(SystemClock.uptimeMillis());
4863 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004864 }
4865
4866 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004867 try {
4868 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004869 mWindowManager.updateRotation(alwaysSendConfiguration, false);
4870 } catch (RemoteException e) {
4871 // Ignore
4872 }
4873 }
4874
4875 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
4876 try {
4877 //set orientation on WindowManager
4878 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004879 } catch (RemoteException e) {
4880 // Ignore
4881 }
4882 }
4883
Daniel Sandler6396c722013-04-16 20:19:09 -04004884 /**
4885 * Return an Intent to launch the currently active dock app as home. Returns
4886 * null if the standard home should be launched, which is the case if any of the following is
4887 * true:
4888 * <ul>
4889 * <li>The device is not in either car mode or desk mode
4890 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
4891 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
4892 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
4893 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
4894 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07004895 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04004896 */
4897 Intent createHomeDockIntent() {
4898 Intent intent = null;
4899
4900 // What home does is based on the mode, not the dock state. That
4901 // is, when in car mode you should be taken to car home regardless
4902 // of whether we are actually in a car dock.
4903 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
4904 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
4905 intent = mCarDockIntent;
4906 }
4907 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
4908 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
4909 intent = mDeskDockIntent;
4910 }
4911 }
4912
4913 if (intent == null) {
4914 return null;
4915 }
4916
4917 ActivityInfo ai = null;
4918 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
4919 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04004920 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07004921 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04004922 if (info != null) {
4923 ai = info.activityInfo;
4924 }
4925 if (ai != null
4926 && ai.metaData != null
4927 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
4928 intent = new Intent(intent);
4929 intent.setClassName(ai.packageName, ai.name);
4930 return intent;
4931 }
4932
4933 return null;
4934 }
4935
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004936 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04004937 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04004938
4939 Intent dock = createHomeDockIntent();
4940 if (dock != null) {
4941 try {
4942 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
4943 return;
4944 } catch (ActivityNotFoundException e) {
4945 }
4946 }
4947
Dianne Hackbornd8883992012-09-07 15:58:52 -07004948 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004949 }
Craig Mautnereda67292013-04-28 13:50:14 -07004950
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004951 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004952 * goes to the home screen
4953 * @return whether it did anything
4954 */
4955 boolean goHome() {
4956 if (false) {
4957 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07004958 try {
4959 ActivityManagerNative.getDefault().stopAppSwitches();
4960 } catch (RemoteException e) {
4961 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004962 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004963 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004964 } else {
4965 // This code brings home to the front or, if it is already
4966 // at the front, puts the device to sleep.
4967 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08004968 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
4969 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
4970 Log.d(TAG, "UTS-TEST-MODE");
4971 } else {
4972 ActivityManagerNative.getDefault().stopAppSwitches();
4973 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04004974 Intent dock = createHomeDockIntent();
4975 if (dock != null) {
4976 int result = ActivityManagerNative.getDefault()
4977 .startActivityAsUser(null, null, dock,
4978 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
4979 null, null, 0,
4980 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
4981 null, null, null, UserHandle.USER_CURRENT);
4982 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
4983 return false;
4984 }
4985 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004986 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004987 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08004988 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004989 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07004990 null, null, 0,
4991 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07004992 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07004993 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004994 return false;
4995 }
4996 } catch (RemoteException ex) {
4997 // bummer, the activity manager, which is in this process, is dead
4998 }
4999 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005000 return true;
5001 }
Craig Mautnereda67292013-04-28 13:50:14 -07005002
5003 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005004 public void setCurrentOrientationLw(int newOrientation) {
5005 synchronized (mLock) {
5006 if (newOrientation != mCurrentAppOrientation) {
5007 mCurrentAppOrientation = newOrientation;
5008 updateOrientationListenerLp();
5009 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005010 }
5011 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005012
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005013 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5014 if (!isGlobalAccessibilityGestureEnabled()) {
5015 return;
5016 }
5017 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5018 Context.AUDIO_SERVICE);
5019 if (audioManager.isSilentMode()) {
5020 return;
5021 }
5022 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5023 Settings.System.DEFAULT_NOTIFICATION_URI);
5024 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5025 ringTone.play();
5026 }
Craig Mautnereda67292013-04-28 13:50:14 -07005027
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005028 private boolean isGlobalAccessibilityGestureEnabled() {
5029 return Settings.Global.getInt(mContext.getContentResolver(),
5030 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5031 }
5032
Craig Mautnereda67292013-04-28 13:50:14 -07005033 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005034 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005035 if (!mVibrator.hasVibrator()) {
5036 return false;
5037 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005038 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5039 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jim Miller5ecd8112013-01-09 18:50:26 -08005040 if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotHidden())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005041 return false;
5042 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005043 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005044 switch (effectId) {
5045 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005046 pattern = mLongPressVibePattern;
5047 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005048 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005049 pattern = mVirtualKeyVibePattern;
5050 break;
5051 case HapticFeedbackConstants.KEYBOARD_TAP:
5052 pattern = mKeyboardTapVibePattern;
5053 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005054 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005055 pattern = mSafeModeDisabledVibePattern;
5056 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005057 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005058 pattern = mSafeModeEnabledVibePattern;
5059 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005060 default:
5061 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005062 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005063 int owningUid;
5064 String owningPackage;
5065 if (win != null) {
5066 owningUid = win.getOwningUid();
5067 owningPackage = win.getOwningPackage();
5068 } else {
5069 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005070 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005071 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005072 if (pattern.length == 1) {
5073 // One-shot vibration
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005074 mVibrator.vibrate(owningUid, owningPackage, pattern[0]);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005075 } else {
5076 // Pattern vibration
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005077 mVibrator.vibrate(owningUid, owningPackage, pattern, -1);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005078 }
5079 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005080 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005081
5082 @Override
5083 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005084 }
5085
Jeff Brownc38c9be2012-10-04 13:16:19 -07005086 @Override
5087 public void keepScreenOnStoppedLw() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005088 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotHidden()) {
Jeff Brownc38c9be2012-10-04 13:16:19 -07005089 long curTime = SystemClock.uptimeMillis();
Jim Miller25190572013-02-28 17:36:24 -08005090 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005091 }
5092 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005093
Dianne Hackborndf89e652011-10-06 22:35:11 -07005094 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005095 // If there is no window focused, there will be nobody to handle the events
5096 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005097 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5098 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005099 return 0;
5100 }
John Spurlock79da8332013-09-20 12:04:47 -04005101 if (win.getAttrs().type == TYPE_KEYGUARD && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005102 // We are updating at a point where the keyguard has gotten
5103 // focus, but we were last in a state where the top window is
5104 // hiding it. This is probably because the keyguard as been
5105 // shown while the top window was displayed, so we want to ignore
5106 // it here because this is just a very transient change and it
5107 // will quickly lose focus once it correctly gets hidden.
5108 return 0;
5109 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005110
John Spurlock79da8332013-09-20 12:04:47 -04005111 int tmpVisibility = win.getSystemUiVisibility()
Dianne Hackborne26ab702011-10-16 13:21:33 -07005112 & ~mResettingSystemUiFlags
5113 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005114 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005115 tmpVisibility &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
5116 }
John Spurlock79da8332013-09-20 12:04:47 -04005117 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005118 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005119 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005120 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005121 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005122 return 0;
5123 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005124 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005125 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005126 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005127 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005128 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005129 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005130 try {
5131 IStatusBarService statusbar = getStatusBarService();
5132 if (statusbar != null) {
5133 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5134 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005135 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005136 } catch (RemoteException e) {
5137 // re-acquire status bar service next time it is needed.
5138 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005139 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005140 }
5141 });
5142 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005143 }
5144
John Spurlock79da8332013-09-20 12:04:47 -04005145 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005146 // apply translucent bar vis flags
5147 WindowState transWin = mKeyguard != null && mKeyguard.isVisibleLw() && !mHideLockScreen
5148 ? mKeyguard
5149 : mTopFullscreenOpaqueWindowState;
5150 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5151 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5152
John Spurlock27735a42013-08-14 17:57:38 -04005153 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005154 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005155 if (statusBarHasFocus) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005156 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5157 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005158 | View.SYSTEM_UI_FLAG_IMMERSIVE
John Spurlockf1a36642013-10-12 17:50:42 -04005159 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
John Spurlockbd957402013-10-03 11:38:39 -04005160 | View.STATUS_BAR_TRANSLUCENT
5161 | View.NAVIGATION_BAR_TRANSLUCENT;
5162 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005163 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005164
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005165 if (!areTranslucentBarsAllowed()) {
5166 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005167 }
5168
John Spurlock27735a42013-08-14 17:57:38 -04005169 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04005170 boolean immersiveSticky =
5171 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005172 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04005173 mTopFullscreenOpaqueWindowState != null &&
5174 (mTopFullscreenOpaqueWindowState.getAttrs().flags
John Spurlock27735a42013-08-14 17:57:38 -04005175 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5176 boolean hideStatusBarSysui =
5177 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04005178 boolean hideNavBarSysui =
5179 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005180
John Spurlock27735a42013-08-14 17:57:38 -04005181 boolean transientStatusBarAllowed =
5182 mStatusBar != null && (
5183 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04005184 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04005185 || statusBarHasFocus);
5186
John Spurlockf1a36642013-10-12 17:50:42 -04005187 boolean transientNavBarAllowed =
5188 mNavigationBar != null &&
5189 hideNavBarSysui && immersiveSticky;
5190
John Spurlockf25706f2013-11-07 18:02:43 -05005191 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005192 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05005193 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005194 && !transientNavBarAllowed;
5195 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04005196 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04005197 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005198 }
John Spurlock27735a42013-08-14 17:57:38 -04005199
5200 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5201
5202 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04005203 boolean oldImmersiveMode = isImmersiveMode(oldVis);
5204 boolean newImmersiveMode = isImmersiveMode(vis);
5205 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04005206 final String pkg = win.getOwningPackage();
John Spurlockf1a36642013-10-12 17:50:42 -04005207 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode);
John Spurlock34e13d92013-08-10 06:52:28 -04005208 }
John Spurlock27735a42013-08-14 17:57:38 -04005209
John Spurlockf1a36642013-10-12 17:50:42 -04005210 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
5211
John Spurlocke1f366f2013-08-05 12:22:40 -04005212 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005213 }
5214
John Spurlockf1a36642013-10-12 17:50:42 -04005215 private void clearClearableFlagsLw() {
5216 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5217 if (newVal != mResettingSystemUiFlags) {
5218 mResettingSystemUiFlags = newVal;
5219 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5220 }
5221 }
5222
5223 private boolean isImmersiveMode(int vis) {
5224 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04005225 return mNavigationBar != null
5226 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04005227 && (vis & flags) != 0
5228 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04005229 }
5230
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005231 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005232 * @return whether the navigation or status bar can be made translucent
5233 *
5234 * This should return true unless touch exploration is not enabled or
5235 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005236 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005237 private boolean areTranslucentBarsAllowed() {
5238 return mTranslucentDecorEnabled && !mTouchExplorationEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005239 }
5240
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005241 // Use this instead of checking config_showNavigationBar so that it can be consistently
5242 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005243 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005244 public boolean hasNavigationBar() {
5245 return mHasNavigationBar;
5246 }
5247
satok1bc0a492012-04-25 22:47:12 +09005248 @Override
5249 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5250 mLastInputMethodWindow = ime;
5251 mLastInputMethodTargetWindow = target;
5252 }
5253
Craig Mautnerf1b67412012-09-19 13:18:29 -07005254 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005255 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005256 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005257 if (mKeyguardDelegate != null) {
5258 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005259 }
John Spurlock13451a22012-09-28 14:40:41 -04005260 if (mStatusBarService != null) {
5261 try {
5262 mStatusBarService.setCurrentUser(newUserId);
5263 } catch (RemoteException e) {
5264 // oh well
5265 }
5266 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005267 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005268 }
5269
5270 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005271 public boolean canMagnifyWindow(int windowType) {
5272 switch (windowType) {
5273 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5274 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5275 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5276 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5277 return false;
5278 }
5279 }
5280 return true;
5281 }
5282
5283 @Override
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005284 public void setTouchExplorationEnabled(boolean enabled) {
5285 mTouchExplorationEnabled = enabled;
5286 }
5287
5288 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005289 public boolean isTopLevelWindow(int windowType) {
5290 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5291 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5292 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5293 }
5294 return true;
5295 }
5296
Jim Miller4eeb4f62012-11-08 00:04:29 -08005297 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005298 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005299 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005300 pw.print(" mSystemReady="); pw.print(mSystemReady);
5301 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005302 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005303 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5304 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005305 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5306 || mForceClearedSystemUiFlags != 0) {
5307 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5308 pw.print(Integer.toHexString(mLastSystemUiFlags));
5309 pw.print(" mResettingSystemUiFlags=0x");
5310 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5311 pw.print(" mForceClearedSystemUiFlags=0x");
5312 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005313 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005314 if (mLastFocusNeedsMenu) {
5315 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5316 pw.println(mLastFocusNeedsMenu);
5317 }
Jeff Brownbcdfc622014-03-06 19:13:04 -08005318 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04005319 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5320 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005321 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5322 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5323 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5324 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005325 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005326 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005327 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5328 pw.print(mCarDockEnablesAccelerometer);
5329 pw.print(" mDeskDockEnablesAccelerometer=");
5330 pw.println(mDeskDockEnablesAccelerometer);
5331 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5332 pw.print(mLidKeyboardAccessibility);
5333 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005334 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
5335 pw.print(prefix); pw.print("mLongPressOnPowerBehavior=");
5336 pw.print(mLongPressOnPowerBehavior);
5337 pw.print(" mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005338 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5339 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005340 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005341 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5342 pw.print(","); pw.print(mOverscanScreenTop);
5343 pw.print(") "); pw.print(mOverscanScreenWidth);
5344 pw.print("x"); pw.println(mOverscanScreenHeight);
5345 if (mOverscanLeft != 0 || mOverscanTop != 0
5346 || mOverscanRight != 0 || mOverscanBottom != 0) {
5347 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5348 pw.print(" top="); pw.print(mOverscanTop);
5349 pw.print(" right="); pw.print(mOverscanRight);
5350 pw.print(" bottom="); pw.println(mOverscanBottom);
5351 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005352 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5353 pw.print(mRestrictedOverscanScreenLeft);
5354 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5355 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5356 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005357 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5358 pw.print(","); pw.print(mUnrestrictedScreenTop);
5359 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5360 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5361 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5362 pw.print(","); pw.print(mRestrictedScreenTop);
5363 pw.print(") "); pw.print(mRestrictedScreenWidth);
5364 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005365 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5366 pw.print(","); pw.print(mStableFullscreenTop);
5367 pw.print(")-("); pw.print(mStableFullscreenRight);
5368 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005369 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5370 pw.print(","); pw.print(mStableTop);
5371 pw.print(")-("); pw.print(mStableRight);
5372 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005373 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5374 pw.print(","); pw.print(mSystemTop);
5375 pw.print(")-("); pw.print(mSystemRight);
5376 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005377 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5378 pw.print(","); pw.print(mCurTop);
5379 pw.print(")-("); pw.print(mCurRight);
5380 pw.print(","); pw.print(mCurBottom); pw.println(")");
5381 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5382 pw.print(","); pw.print(mContentTop);
5383 pw.print(")-("); pw.print(mContentRight);
5384 pw.print(","); pw.print(mContentBottom); pw.println(")");
5385 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5386 pw.print(","); pw.print(mDockTop);
5387 pw.print(")-("); pw.print(mDockRight);
5388 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005389 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5390 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005391 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5392 pw.print(" mShowingDream="); pw.print(mShowingDream);
5393 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005394 if (mLastInputMethodWindow != null) {
5395 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5396 pw.println(mLastInputMethodWindow);
5397 }
5398 if (mLastInputMethodTargetWindow != null) {
5399 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5400 pw.println(mLastInputMethodTargetWindow);
5401 }
5402 if (mStatusBar != null) {
5403 pw.print(prefix); pw.print("mStatusBar=");
5404 pw.println(mStatusBar);
5405 }
5406 if (mNavigationBar != null) {
5407 pw.print(prefix); pw.print("mNavigationBar=");
5408 pw.println(mNavigationBar);
5409 }
5410 if (mKeyguard != null) {
5411 pw.print(prefix); pw.print("mKeyguard=");
5412 pw.println(mKeyguard);
5413 }
5414 if (mFocusedWindow != null) {
5415 pw.print(prefix); pw.print("mFocusedWindow=");
5416 pw.println(mFocusedWindow);
5417 }
5418 if (mFocusedApp != null) {
5419 pw.print(prefix); pw.print("mFocusedApp=");
5420 pw.println(mFocusedApp);
5421 }
5422 if (mWinDismissingKeyguard != null) {
5423 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5424 pw.println(mWinDismissingKeyguard);
5425 }
5426 if (mTopFullscreenOpaqueWindowState != null) {
5427 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5428 pw.println(mTopFullscreenOpaqueWindowState);
5429 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005430 if (mForcingShowNavBar) {
5431 pw.print(prefix); pw.print("mForcingShowNavBar=");
5432 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5433 pw.println(mForcingShowNavBarLayer);
5434 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005435 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005436 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005437 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5438 pw.print(" mForceStatusBarFromKeyguard=");
5439 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005440 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005441 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005442 pw.print(" mHomePressed="); pw.println(mHomePressed);
5443 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5444 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5445 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5446 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5447 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5448 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5449 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5450 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5451 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5452 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005453 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5454 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5455 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
John Spurlock27735a42013-08-14 17:57:38 -04005456 mStatusBarController.dump(pw, prefix);
5457 mNavigationBarController.dump(pw, prefix);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005458 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005459}