blob: 30282dd1967045c76fc1b3cb5a2b50fb15605aa3 [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;
RoboErik8a2cfc32014-05-16 11:19:38 -070049import android.media.session.MediaSessionLegacyHelper;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070050import android.os.Bundle;
Jeff Brown9a538ee2012-08-20 14:56:57 -070051import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080052import android.os.Handler;
53import android.os.IBinder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070054import android.os.IRemoteCallback;
Jeff Brown32cbc38552011-12-01 14:01:49 -080055import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070056import android.os.Message;
57import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080058import android.os.PowerManager;
59import android.os.RemoteException;
60import android.os.ServiceManager;
61import android.os.SystemClock;
62import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080063import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070064import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080065import android.os.Vibrator;
66import android.provider.Settings;
John Spurlockc8b46ca2013-04-08 12:59:26 -040067import android.service.dreams.DreamService;
68import android.service.dreams.IDreamManager;
Santos Cordon3afed572014-05-21 15:22:12 -070069import android.telephony.TelephonyManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070070import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080071import android.util.EventLog;
72import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070073import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080074import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -070075import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080076import android.view.Gravity;
77import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -080078import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080079import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -070080import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -070081import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -080082import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -080083import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -080084import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -080085import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080086import android.view.KeyEvent;
87import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080088import android.view.Surface;
89import android.view.View;
90import android.view.ViewConfiguration;
91import android.view.Window;
92import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -080093import android.view.WindowManagerGlobal;
94import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -080095import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -080096import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -080097import android.view.animation.Animation;
98import android.view.animation.AnimationUtils;
99
100import com.android.internal.R;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100101import com.android.internal.policy.IKeyguardService;
102import com.android.internal.policy.IKeyguardServiceConstants;
Craig Mautnerae446592012-12-06 19:05:05 -0800103import com.android.internal.policy.PolicyManager;
Jim Miller5ecd8112013-01-09 18:50:26 -0800104import com.android.internal.policy.impl.keyguard.KeyguardServiceDelegate;
Craig Mautnerae446592012-12-06 19:05:05 -0800105import com.android.internal.statusbar.IStatusBarService;
106import com.android.internal.telephony.ITelephony;
107import com.android.internal.widget.PointerLocationView;
108
109import java.io.File;
110import java.io.FileReader;
111import java.io.IOException;
112import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700113import java.util.HashSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800114
Dianne Hackbornc652de82013-02-15 16:32:56 -0800115import static android.view.WindowManager.LayoutParams.*;
Jeff Brownac143512012-04-05 18:57:33 -0700116import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
117import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
118import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
Dianne Hackborn08743722009-12-21 12:16:51 -0800119
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800120/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700121 * WindowManagerPolicy implementation for the Android phone UI. This
122 * introduces a new method suffix, Lp, for an internal lock of the
123 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400124 * 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 -0700125 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800126 */
127public class PhoneWindowManager implements WindowManagerPolicy {
128 static final String TAG = "WindowManager";
129 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700130 static final boolean localLOGV = false;
The Android Open Source Project11267662009-03-18 17:39:47 -0700131 static final boolean DEBUG_LAYOUT = false;
Jeff Brown40013652012-05-16 21:22:36 -0700132 static final boolean DEBUG_INPUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700133 static final boolean DEBUG_STARTING_WINDOW = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800134 static final boolean SHOW_STARTING_ANIMATIONS = true;
135 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400136
Daniel Sandler6396c722013-04-16 20:19:09 -0400137 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
138 // No longer recommended for desk docks; still useful in car docks.
139 static final boolean ENABLE_CAR_DOCK_HOME_CAPTURE = true;
140 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
141
RoboErik8a2cfc32014-05-16 11:19:38 -0700142 // Whether to use the new Session APIs
143 static final boolean USE_SESSIONS = true;
144
Jeff Brown6d8fd272014-05-20 21:24:38 -0700145 static final int SHORT_PRESS_POWER_NOTHING = 0;
146 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
147 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
148 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
149
Joe Onoratod208e702010-10-08 16:22:43 -0400150 static final int LONG_PRESS_POWER_NOTHING = 0;
151 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
152 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700153 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700154
155 // These need to match the documentation/constant in
156 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800157 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800158 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700159 static final int LONG_PRESS_HOME_ASSIST = 2;
160
161 static final int DOUBLE_TAP_HOME_NOTHING = 0;
162 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800163
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700164 static final int APPLICATION_MEDIA_SUBLAYER = -2;
165 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800166 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800167 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Craig Mautner88400d32012-09-30 12:35:45 -0700168
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800169 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
170 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
171 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500172 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700173 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800174
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700175 /**
176 * These are the system UI flags that, when changing, can cause the layout
177 * of the screen to change.
178 */
179 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400180 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400181 | View.SYSTEM_UI_FLAG_FULLSCREEN
182 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200183 | View.NAVIGATION_BAR_TRANSLUCENT
184 | View.SYSTEM_UI_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700185
Jim Miller5ecd8112013-01-09 18:50:26 -0800186 /**
187 * Keyguard stuff
188 */
189 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100190 private boolean mKeyguardHidden;
Jorim Jaggicff0acb2014-03-31 16:35:15 +0200191 private boolean mKeyguardDrawn;
Jim Miller5ecd8112013-01-09 18:50:26 -0800192
Jeff Brown6651a632011-11-28 12:59:11 -0800193 /* Table of Application Launch keys. Maps from key codes to intent categories.
194 *
195 * These are special keys that are used to launch particular kinds of applications,
196 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
197 * usage page. We don't support quite that many yet...
198 */
199 static SparseArray<String> sApplicationLaunchKeyCategories;
200 static {
201 sApplicationLaunchKeyCategories = new SparseArray<String>();
202 sApplicationLaunchKeyCategories.append(
203 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
204 sApplicationLaunchKeyCategories.append(
205 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
206 sApplicationLaunchKeyCategories.append(
207 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
208 sApplicationLaunchKeyCategories.append(
209 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
210 sApplicationLaunchKeyCategories.append(
211 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
212 sApplicationLaunchKeyCategories.append(
213 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
214 }
215
Dianne Hackborndf89e652011-10-06 22:35:11 -0700216 /**
217 * Lock protecting internal state. Must not call out into window
218 * manager with lock held. (This lock will be acquired in places
219 * where the window manager is calling in with its own lock held.)
220 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800221 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700222
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800223 Context mContext;
224 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700225 WindowManagerFuncs mWindowManagerFuncs;
Jeff Brown96307042012-07-27 15:51:34 -0700226 PowerManager mPowerManager;
Joe Onorato93056472010-09-10 10:30:46 -0400227 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700228 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700229 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800230 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700231 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800232 AccessibilityManager mAccessibilityManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800233
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700234 // Vibrator pattern for haptic feedback of a long press.
235 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700236
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700237 // Vibrator pattern for haptic feedback of virtual key press.
238 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700239
Amith Yamasanic33cb712010-02-10 15:21:49 -0800240 // Vibrator pattern for a short vibration.
241 long[] mKeyboardTapVibePattern;
242
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700243 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
244 long[] mClockTickVibePattern;
245
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700246 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
247 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700248
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700249 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
250 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700251
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800252 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
253 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400254
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800255 boolean mSafeMode;
256 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700257 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400258 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400259 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700260 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400261 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
262 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
263 int[] mNavigationBarHeightForRotation = new int[4];
264 int[] mNavigationBarWidthForRotation = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400265
Jim Miller5ecd8112013-01-09 18:50:26 -0800266 KeyguardServiceDelegate mKeyguardDelegate;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800267 GlobalActions mGlobalActions;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700268 volatile boolean mPowerKeyHandled; // accessed from input reader and handler thread
269 boolean mPendingPowerKeyUpCanceled;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800270 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900271 WindowState mLastInputMethodWindow = null;
272 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800273
Winson Chung1e8d71b2014-05-16 17:05:22 -0700274 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700275 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800276
Jeff Brown2e7760e2012-04-11 15:14:55 -0700277 int mLidState = LID_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700278 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800279
Dianne Hackbornc777e072010-02-12 13:07:59 -0800280 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700281 boolean mSystemBooted;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800282 boolean mHdmiPlugged;
Daniel Sandler6396c722013-04-16 20:19:09 -0400283 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700284 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700285 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400286 int mCarDockRotation;
287 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700288 int mUndockedHdmiRotation;
289 int mDemoHdmiRotation;
290 boolean mDemoHdmiRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400291
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700292 // Default display does not rotate, apps that require non-default orientation will have to
293 // have the orientation emulated.
294 private boolean mForceDefaultOrientation = false;
295
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400296 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
297 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700298 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400299
Jeff Brownbcdfc622014-03-06 19:13:04 -0800300 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700301 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400302 boolean mCarDockEnablesAccelerometer;
303 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700304 int mLidKeyboardAccessibility;
305 int mLidNavigationAccessibility;
Jeff Brownc458ce92012-04-30 14:58:40 -0700306 boolean mLidControlsSleep;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700307 int mShortPressOnPowerBehavior = -1;
Joe Onoratod208e702010-10-08 16:22:43 -0400308 int mLongPressOnPowerBehavior = -1;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700309 boolean mScreenOnEarly = false;
310 boolean mScreenOnFully = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800311 boolean mOrientationSensorEnabled = false;
312 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800313 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400314 boolean mTranslucentDecorEnabled = true;
Craig Mautner967212c2013-04-13 21:10:58 -0700315
Jeff Brown70825162012-03-28 17:27:48 -0700316 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800317
318 // The last window we were told about in focusChanged.
319 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800320 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800321
Jeff Brown70825162012-03-28 17:27:48 -0700322 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800323
Dianne Hackbornc652de82013-02-15 16:32:56 -0800324 // The current size of the screen; really; extends into the overscan area of
325 // the screen and doesn't account for any system elements like the status bar.
326 int mOverscanScreenLeft, mOverscanScreenTop;
327 int mOverscanScreenWidth, mOverscanScreenHeight;
328 // The current visible size of the screen; really; (ir)regardless of whether the status
329 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800330 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
331 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800332 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
333 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
334 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700335 // The current size of the screen; these may be different than (0,0)-(dw,dh)
336 // if the status bar can't be hidden; in that case it effectively carves out
337 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800338 int mRestrictedScreenLeft, mRestrictedScreenTop;
339 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700340 // During layout, the current screen borders accounting for any currently
341 // visible system UI elements.
342 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700343 // For applications requesting stable content insets, these are them.
344 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700345 // For applications requesting stable content insets but have also set the
346 // fullscreen window flag, these are the stable dimensions without the status bar.
347 int mStableFullscreenLeft, mStableFullscreenTop;
348 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800349 // During layout, the current screen borders with all outer decoration
350 // (status bar, input method dock) accounted for.
351 int mCurLeft, mCurTop, mCurRight, mCurBottom;
352 // During layout, the frame in which content should be displayed
353 // to the user, accounting for all screen decoration except for any
354 // space they deem as available for other content. This is usually
355 // the same as mCur*, but may be larger if the screen decor has supplied
356 // content insets.
357 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700358 // During layout, the frame in which voice content should be displayed
359 // to the user, accounting for all screen decoration except for any
360 // space they deem as available for other content.
361 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800362 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800363 // windows are placed.
364 int mDockLeft, mDockTop, mDockRight, mDockBottom;
365 // During layout, the layer at which the doc window is placed.
366 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700367 // During layout, this is the layer of the status bar.
368 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700369 int mLastSystemUiFlags;
370 // Bits that we are in the process of clearing, so we want to prevent
371 // them from being set by applications until everything has been updated
372 // to have them clear.
373 int mResettingSystemUiFlags = 0;
374 // Bits that we are currently always keeping cleared.
375 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800376 // What we last reported to system UI about whether the compatibility
377 // menu needs to be displayed.
378 boolean mLastFocusNeedsMenu = false;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700379
380 FakeWindow mHideNavFakeWindow = null;
381
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800382 static final Rect mTmpParentFrame = new Rect();
383 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800384 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800385 static final Rect mTmpContentFrame = new Rect();
386 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400387 static final Rect mTmpDecorFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700388 static final Rect mTmpNavigationFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700389
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800390 WindowState mTopFullscreenOpaqueWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700391 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400392 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800393 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700394 boolean mForceStatusBarFromKeyguard;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700395 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800396 boolean mForcingShowNavBar;
397 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700398
399 // States of keyguard dismiss.
400 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
401 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
402 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
403 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
404
405 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
406 * be done once per window. */
407 private WindowState mWinDismissingKeyguard;
408
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700409 boolean mShowingLockscreen;
410 boolean mShowingDream;
411 boolean mDreamingLockscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800412 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700413 boolean mHomeConsumed;
414 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800415 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700416 Intent mCarDockIntent;
417 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700418 boolean mSearchKeyShortcutPending;
419 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700420 boolean mAssistKeyLongPressed;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800421
Mike Lockwood28569302010-01-28 11:54:40 -0500422 // support for activating the lock screen while the screen is on
423 boolean mAllowLockscreenWhenOn;
424 int mLockScreenTimeout;
425 boolean mLockScreenTimerActive;
426
David Brownbaf8d092010-03-08 21:52:59 -0800427 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800428 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800429
430 // Behavior of POWER button while in-call and screen on.
431 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
432 int mIncallPowerBehavior;
433
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700434 Display mDisplay;
435
Dianne Hackborn9d132642011-04-21 17:26:39 -0700436 int mLandscapeRotation = 0; // default landscape rotation
437 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
438 int mPortraitRotation = 0; // default portrait rotation
439 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700440
Dianne Hackbornc652de82013-02-15 16:32:56 -0800441 int mOverscanLeft = 0;
442 int mOverscanTop = 0;
443 int mOverscanRight = 0;
444 int mOverscanBottom = 0;
445
Joe Onorato46b0d682010-11-22 17:37:27 -0800446 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700447 private int mLongPressOnHomeBehavior;
448
449 // What we do when the user double-taps on home
450 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800451
Winson Chung9112ec32011-06-27 13:15:32 -0700452 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700453 // Time to volume and power must be pressed within this interval of each other.
454 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700455 // Increase the chord delay when taking a screenshot from the keyguard
456 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800457 private boolean mScreenshotChordEnabled;
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700458 private boolean mVolumeDownKeyTriggered;
459 private long mVolumeDownKeyTime;
460 private boolean mVolumeDownKeyConsumedByScreenshotChord;
461 private boolean mVolumeUpKeyTriggered;
462 private boolean mPowerKeyTriggered;
463 private long mPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700464
Michael Wrightb854e242013-02-05 17:54:02 -0800465 /* The number of steps between min and max brightness */
466 private static final int BRIGHTNESS_STEPS = 10;
467
Christopher Tate5e08af02012-09-21 17:17:22 -0700468 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800469 ShortcutManager mShortcutManager;
470 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700471 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800472
Craig Mautnerd625ab22013-09-06 13:40:31 -0700473 private int mCurrentUserId;
474
Justin Kohd378ad72013-04-01 12:18:26 -0700475 // Maps global key codes to the components that will handle them.
476 private GlobalKeyManager mGlobalKeyManager;
477
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700478 // Fallback actions by key code.
479 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
480 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800481
Jeff Brown70825162012-03-28 17:27:48 -0700482 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
483 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700484 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
485 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Jeff Brown70825162012-03-28 17:27:48 -0700486
487 private class PolicyHandler extends Handler {
488 @Override
489 public void handleMessage(Message msg) {
490 switch (msg.what) {
491 case MSG_ENABLE_POINTER_LOCATION:
492 enablePointerLocation();
493 break;
494 case MSG_DISABLE_POINTER_LOCATION:
495 disablePointerLocation();
496 break;
Jeff Brown40013652012-05-16 21:22:36 -0700497 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
498 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
499 break;
500 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
501 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
502 break;
Jeff Brown70825162012-03-28 17:27:48 -0700503 }
504 }
505 }
506
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800507 private UEventObserver mHDMIObserver = new UEventObserver() {
508 @Override
509 public void onUEvent(UEventObserver.UEvent event) {
510 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
511 }
512 };
513
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800514 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800515 SettingsObserver(Handler handler) {
516 super(handler);
517 }
David Brownbaf8d092010-03-08 21:52:59 -0800518
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800519 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700520 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800521 ContentResolver resolver = mContext.getContentResolver();
522 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700523 Settings.System.END_BUTTON_BEHAVIOR), false, this,
524 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800525 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700526 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
527 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800528 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700529 Settings.System.ACCELEROMETER_ROTATION), false, this,
530 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500531 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700532 Settings.System.USER_ROTATION), false, this,
533 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400534 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700535 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
536 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800537 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700538 Settings.System.POINTER_LOCATION), false, this,
539 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800540 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700541 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
542 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500543 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400544 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700545 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500546 resolver.registerContentObserver(Settings.Global.getUriFor(
547 Settings.Global.POLICY_CONTROL), false, this,
548 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800549 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800550 }
551
552 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800553 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700554 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800555 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800556 }
Craig Mautner967212c2013-04-13 21:10:58 -0700557
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800558 class MyOrientationListener extends WindowOrientationListener {
Craig Mautnereee29c42013-01-17 14:44:34 -0800559 MyOrientationListener(Context context, Handler handler) {
560 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800561 }
Craig Mautner967212c2013-04-13 21:10:58 -0700562
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800563 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700564 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700565 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700566 updateRotation(false);
567 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800568 }
569 MyOrientationListener mOrientationListener;
570
John Spurlock27735a42013-08-14 17:57:38 -0400571 private final BarController mStatusBarController = new BarController("StatusBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400572 View.STATUS_BAR_TRANSIENT,
573 View.STATUS_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400574 View.STATUS_BAR_TRANSLUCENT,
575 StatusBarManager.WINDOW_STATUS_BAR,
576 WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
John Spurlock5b9145b2013-08-20 15:13:47 -0400577
John Spurlock27735a42013-08-14 17:57:38 -0400578 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400579 View.NAVIGATION_BAR_TRANSIENT,
580 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400581 View.NAVIGATION_BAR_TRANSLUCENT,
582 StatusBarManager.WINDOW_NAVIGATION_BAR,
583 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
John Spurlock5b9145b2013-08-20 15:13:47 -0400584
John Spurlockf1a36642013-10-12 17:50:42 -0400585 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400586
Craig Mautner037aa8d2013-06-07 10:35:44 -0700587 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400588
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700589 IStatusBarService getStatusBarService() {
590 synchronized (mServiceAquireLock) {
591 if (mStatusBarService == null) {
592 mStatusBarService = IStatusBarService.Stub.asInterface(
593 ServiceManager.getService("statusbar"));
594 }
595 return mStatusBarService;
596 }
597 }
598
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700599 /*
600 * We always let the sensor be switched on by default except when
601 * the user has explicitly disabled sensor based rotation or when the
602 * screen is switched off.
603 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700604 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800605 if (mSupportAutoRotation) {
606 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
607 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
608 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
609 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
610 // If the application has explicitly requested to follow the
611 // orientation, then we need to turn the sensor on.
612 return true;
613 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800614 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700615 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800616 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
617 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
618 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400619 // enable accelerometer if we are docked in a dock that enables accelerometer
620 // orientation management,
621 return true;
622 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700623 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800624 // If the setting for using the sensor by default is enabled, then
625 // we will always leave it on. Note that the user could go to
626 // a window that forces an orientation that does not use the
627 // sensor and in theory we could turn it off... however, when next
628 // turning it on we won't have a good value for the current
629 // orientation for a little bit, which can cause orientation
630 // changes to lag, so we'd like to keep it always on. (It will
631 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700632 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800633 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800634 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800635 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700636
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800637 /*
638 * Various use cases for invoking this function
639 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700640 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800641 * if not already enabled
642 * screen turned on and current app does not have sensor orientation, disable listeners if
643 * already enabled
644 * screen turning on and current app has sensor based orientation, enable listeners if needed
645 * screen turning on and current app has nosensor based orientation, do nothing
646 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700647 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800648 if (!mOrientationListener.canDetectOrientation()) {
649 // If sensor is turned off or nonexistent for some reason
650 return;
651 }
652 //Could have been invoked due to screen turning on or off or
653 //change of the currently visible window's orientation
Craig Mautnereda67292013-04-28 13:50:14 -0700654 if (localLOGV) Slog.v(TAG, "Screen status="+mScreenOnEarly+
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800655 ", current orientation="+mCurrentAppOrientation+
656 ", SensorEnabled="+mOrientationSensorEnabled);
657 boolean disable = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -0700658 if (mScreenOnEarly) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700659 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800660 disable = false;
661 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700662 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800663 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700664 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800665 mOrientationSensorEnabled = true;
666 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700667 }
668 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800669 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700670 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800671 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700672 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800673 mOrientationSensorEnabled = false;
674 }
675 }
676
Jeff Brown4d396052010-10-29 21:50:21 -0700677 private void interceptPowerKeyDown(boolean handled) {
678 mPowerKeyHandled = handled;
679 if (!handled) {
Justin Kohfeabd2c2014-05-02 10:02:44 -0700680 mHandler.postDelayed(mPowerLongPress,
681 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Jeff Brown4d396052010-10-29 21:50:21 -0700682 }
683 }
684
685 private boolean interceptPowerKeyUp(boolean canceled) {
686 if (!mPowerKeyHandled) {
687 mHandler.removeCallbacks(mPowerLongPress);
688 return !canceled;
Jeff Brown4d396052010-10-29 21:50:21 -0700689 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700690 return false;
691 }
692
693 private void cancelPendingPowerKeyAction() {
694 if (!mPowerKeyHandled) {
695 mHandler.removeCallbacks(mPowerLongPress);
696 }
Jeff Brownff204712011-10-25 21:27:54 -0700697 if (mPowerKeyTriggered) {
698 mPendingPowerKeyUpCanceled = true;
699 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700700 }
701
702 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -0800703 if (mScreenshotChordEnabled
704 && mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700705 final long now = SystemClock.uptimeMillis();
706 if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
707 && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
708 mVolumeDownKeyConsumedByScreenshotChord = true;
709 cancelPendingPowerKeyAction();
710
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800711 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700712 }
713 }
714 }
715
Winson Chung1cea2f32012-10-08 20:42:01 -0700716 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -0800717 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -0700718 // Double the time it takes to take a screenshot from the keyguard
719 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -0700720 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -0700721 }
Justin Kohfeabd2c2014-05-02 10:02:44 -0700722 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -0700723 }
724
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700725 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800726 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -0700727 }
728
Jeff Brown6d8fd272014-05-20 21:24:38 -0700729 private void powerShortPress(long eventTime) {
730 if (mShortPressOnPowerBehavior < 0) {
731 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
732 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
733 }
734
735 switch (mShortPressOnPowerBehavior) {
736 case SHORT_PRESS_POWER_NOTHING:
737 break;
738 case SHORT_PRESS_POWER_GO_TO_SLEEP:
739 mPowerManager.goToSleep(eventTime,
740 PowerManager.GO_TO_SLEEP_REASON_USER, 0);
741 break;
742 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
743 mPowerManager.goToSleep(eventTime,
744 PowerManager.GO_TO_SLEEP_REASON_USER,
745 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
746 break;
747 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
748 mPowerManager.goToSleep(eventTime,
749 PowerManager.GO_TO_SLEEP_REASON_USER,
750 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
751 launchHomeFromHotKey();
752 break;
753 }
754 }
755
Jeff Brown4d396052010-10-29 21:50:21 -0700756 private final Runnable mPowerLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -0700757 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800758 public void run() {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700759 // The context isn't read
760 if (mLongPressOnPowerBehavior < 0) {
Jeff Brown850c5b72012-10-01 15:17:22 -0700761 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
762 com.android.internal.R.integer.config_longPressOnPowerBehavior);
Joe Onoratod208e702010-10-08 16:22:43 -0400763 }
Jeff Brown850c5b72012-10-01 15:17:22 -0700764 int resolvedBehavior = mLongPressOnPowerBehavior;
765 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
766 resolvedBehavior = LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
767 }
768
769 switch (resolvedBehavior) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700770 case LONG_PRESS_POWER_NOTHING:
771 break;
772 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
773 mPowerKeyHandled = true;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -0700774 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
775 performAuditoryFeedbackForAccessibilityIfNeed();
776 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700777 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
778 showGlobalActionsDialog();
779 break;
780 case LONG_PRESS_POWER_SHUT_OFF:
Jeff Brown9a538ee2012-08-20 14:56:57 -0700781 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700782 mPowerKeyHandled = true;
783 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
784 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
Jeff Brown850c5b72012-10-01 15:17:22 -0700785 mWindowManagerFuncs.shutdown(resolvedBehavior == LONG_PRESS_POWER_SHUT_OFF);
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700786 break;
787 }
788 }
789 };
790
Jeff Sharkey2991fa32012-12-05 18:06:43 -0800791 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800792 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700793 public void run() {
794 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800795 }
796 };
797
798 void showGlobalActionsDialog() {
799 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -0700800 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800801 }
Mike Lockwood3a74bd32011-08-12 13:55:22 -0700802 final boolean keyguardShowing = keyguardIsShowingTq();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800803 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
804 if (keyguardShowing) {
805 // since it took two seconds of long press to bring this up,
806 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -0800807 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800808 }
809 }
810
811 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -0700812 return Settings.Global.getInt(
813 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800814 }
815
Maurice Lam99c6e072014-04-28 18:24:28 -0700816 boolean isUserSetupComplete() {
817 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
818 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
819 }
820
Patrick Dubroyece94522011-02-23 18:35:01 -0800821 private void handleLongPressOnHome() {
Joe Onorato46b0d682010-11-22 17:37:27 -0800822 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -0700823 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -0800824 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -0800825
Jeff Browncaca8812013-05-09 13:34:33 -0700826 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
827 toggleRecentApps();
828 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
829 launchAssistAction();
Jim Millere6ad1a82010-08-20 19:25:39 -0700830 }
831 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800832 }
Patrick Dubroyece94522011-02-23 18:35:01 -0800833
Jeff Browncaca8812013-05-09 13:34:33 -0700834 private void handleDoubleTapOnHome() {
835 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
836 mHomeConsumed = true;
837 toggleRecentApps();
838 }
839 }
840
841 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
842 @Override
843 public void run() {
844 if (mHomeDoubleTapPending) {
845 mHomeDoubleTapPending = false;
846 launchHomeFromHotKey();
847 }
848 }
849 };
850
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800851 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800852 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800853 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -0700854 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800855 mContext = context;
856 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700857 mWindowManagerFuncs = windowManagerFuncs;
Jeff Brown70825162012-03-28 17:27:48 -0700858 mHandler = new PolicyHandler();
Craig Mautnereee29c42013-01-17 14:44:34 -0800859 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -0700860 try {
861 mOrientationListener.setCurrentRotation(windowManager.getRotation());
862 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -0700863 mSettingsObserver = new SettingsObserver(mHandler);
864 mSettingsObserver.observe();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800865 mShortcutManager = new ShortcutManager(context, mHandler);
866 mShortcutManager.observe();
Daniel Sandler6396c722013-04-16 20:19:09 -0400867 mUiMode = context.getResources().getInteger(
868 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800869 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
870 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
871 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
872 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700873 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
874 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
875 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
876 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
877 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
878 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
879 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
880 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -0700881
Jeff Brown96307042012-07-27 15:51:34 -0700882 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
883 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800884 "PhoneWindowManager.mBroadcastWakeLock");
885 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -0800886 mSupportAutoRotation = mContext.getResources().getBoolean(
887 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700888 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400889 com.android.internal.R.integer.config_lidOpenRotation);
890 mCarDockRotation = readRotation(
891 com.android.internal.R.integer.config_carDockRotation);
892 mDeskDockRotation = readRotation(
893 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700894 mUndockedHdmiRotation = readRotation(
895 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -0400896 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
897 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
898 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
899 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700900 mLidKeyboardAccessibility = mContext.getResources().getInteger(
901 com.android.internal.R.integer.config_lidKeyboardAccessibility);
902 mLidNavigationAccessibility = mContext.getResources().getInteger(
903 com.android.internal.R.integer.config_lidNavigationAccessibility);
Jeff Brownc458ce92012-04-30 14:58:40 -0700904 mLidControlsSleep = mContext.getResources().getBoolean(
905 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400906 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
907 com.android.internal.R.bool.config_enableTranslucentDecor);
Jeff Brownf71343d2013-05-31 17:59:11 -0700908 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -0700909
Svetoslav8e3feb12014-02-24 13:46:47 -0800910 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
911 Context.ACCESSIBILITY_SERVICE);
912
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700913 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -0800914 IntentFilter filter = new IntentFilter();
915 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
916 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
917 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
918 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700919 filter.addAction(Intent.ACTION_DOCK_EVENT);
920 Intent intent = context.registerReceiver(mDockReceiver, filter);
921 if (intent != null) {
922 // Retrieve current sticky dock event broadcast.
923 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
924 Intent.EXTRA_DOCK_STATE_UNDOCKED);
925 }
Daniel Sandler7e37df52011-11-16 22:08:23 -0800926
Jeff Brown6aaf2952012-10-05 16:01:08 -0700927 // register for dream-related broadcasts
928 filter = new IntentFilter();
929 filter.addAction(Intent.ACTION_DREAMING_STARTED);
930 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
931 context.registerReceiver(mDreamReceiver, filter);
932
Christopher Tate5e08af02012-09-21 17:17:22 -0700933 // register for multiuser-relevant broadcasts
934 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
935 context.registerReceiver(mMultiuserReceiver, filter);
936
John Spurlock57306e62013-04-22 09:48:49 -0400937 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -0700938 mSystemGestures = new SystemGesturesPointerEventListener(context,
939 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -0400940 @Override
941 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -0400942 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400943 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -0400944 }
John Spurlockad3e6cb2013-04-30 08:47:43 -0400945 }
946 @Override
947 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -0400948 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400949 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400950 }
951 }
952 @Override
953 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -0400954 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -0400955 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -0400956 }
957 }
958 @Override
959 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -0400960 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -0400961 }
962 });
John Spurlockf1a36642013-10-12 17:50:42 -0400963 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -0700964 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -0400965
Jeff Brownc2346132012-04-13 01:55:38 -0700966 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700967 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
968 com.android.internal.R.array.config_longPressVibePattern);
969 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
970 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -0800971 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
972 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700973 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
974 com.android.internal.R.array.config_clockTickVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700975 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
976 com.android.internal.R.array.config_safeModeDisabledVibePattern);
977 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
978 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -0400979
Christopher Tatee90585f2012-03-05 18:56:25 -0800980 mScreenshotChordEnabled = mContext.getResources().getBoolean(
981 com.android.internal.R.bool.config_enableScreenshotChord);
982
Justin Kohd378ad72013-04-01 12:18:26 -0700983 mGlobalKeyManager = new GlobalKeyManager(mContext);
984
Joe Onoratoea495d42011-04-06 11:41:11 -0700985 // Controls rotation and the like.
986 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -0700987
988 // Match current screen state.
Jeff Brown26c6a502014-04-11 02:15:54 -0700989 if (mPowerManager.isInteractive()) {
Jeff Brown140ffc72014-05-01 15:18:00 -0700990 wakingUp(null);
Dianne Hackborn40011092011-09-22 13:37:48 -0700991 } else {
Jeff Brown140ffc72014-05-01 15:18:00 -0700992 goingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -0700993 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700994 }
995
Jeff Brownf71343d2013-05-31 17:59:11 -0700996 /**
997 * Read values from config.xml that may be overridden depending on
998 * the configuration of the device.
999 * eg. Disable long press on home goes to recents on sw600dp.
1000 */
1001 private void readConfigurationDependentBehaviors() {
1002 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1003 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1004 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1005 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1006 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1007 }
1008
1009 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1010 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1011 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1012 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1013 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1014 }
1015 }
1016
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001017 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001018 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001019 // This method might be called before the policy has been fully initialized
1020 // or for other displays we don't care about.
1021 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1022 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001023 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001024 mDisplay = display;
1025
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001026 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001027 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001028 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001029 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001030 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001031 mLandscapeRotation = Surface.ROTATION_0;
1032 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001033 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001034 mPortraitRotation = Surface.ROTATION_90;
1035 mUpsideDownRotation = Surface.ROTATION_270;
1036 } else {
1037 mPortraitRotation = Surface.ROTATION_270;
1038 mUpsideDownRotation = Surface.ROTATION_90;
1039 }
1040 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001041 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001042 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001043 mPortraitRotation = Surface.ROTATION_0;
1044 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001045 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001046 mLandscapeRotation = Surface.ROTATION_270;
1047 mSeascapeRotation = Surface.ROTATION_90;
1048 } else {
1049 mLandscapeRotation = Surface.ROTATION_90;
1050 mSeascapeRotation = Surface.ROTATION_270;
1051 }
1052 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001053
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001054 mStatusBarHeight =
1055 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001056
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001057 // Height of the navigation bar when presented horizontally at bottom
1058 mNavigationBarHeightForRotation[mPortraitRotation] =
1059 mNavigationBarHeightForRotation[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001060 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001061 mNavigationBarHeightForRotation[mLandscapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001062 mNavigationBarHeightForRotation[mSeascapeRotation] = res.getDimensionPixelSize(
1063 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001064
1065 // Width of the navigation bar when presented vertically along one side
1066 mNavigationBarWidthForRotation[mPortraitRotation] =
1067 mNavigationBarWidthForRotation[mUpsideDownRotation] =
1068 mNavigationBarWidthForRotation[mLandscapeRotation] =
1069 mNavigationBarWidthForRotation[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001070 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001071
1072 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001073 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001074 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001075
Craig Mautnerd4ec33242013-07-22 10:37:43 -07001076 // Allow the navigation bar to move on small devices (phones).
1077 mNavigationBarCanMove = shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001078
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001079 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001080 // Allow a system property to override this. Used by the emulator.
1081 // See also hasNavigationBar().
1082 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1083 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001084 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001085 } else if ("0".equals(navBarOverride)) {
1086 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001087 }
1088
Jeff Brown27f1d672012-10-17 18:32:34 -07001089 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1090 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001091 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001092 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001093 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001094 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001095 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001096 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001097
1098 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1099 // http://developer.android.com/guide/practices/screens_support.html#range
1100 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1101 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1102 // For debug purposes the next line turns this feature off with:
1103 // $ adb shell setprop config.override_forced_orient true
1104 // $ adb shell wm size reset
1105 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1106 }
1107
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001108 /**
1109 * @return whether the navigation bar can be hidden, e.g. the device has a
1110 * navigation bar and touch exploration is not enabled
1111 */
1112 private boolean canHideNavigationBar() {
Svetoslav8e3feb12014-02-24 13:46:47 -08001113 return mHasNavigationBar
1114 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001115 }
1116
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001117 @Override
1118 public boolean isDefaultOrientationForced() {
1119 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001120 }
1121
Dianne Hackbornc652de82013-02-15 16:32:56 -08001122 @Override
1123 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1124 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1125 mOverscanLeft = left;
1126 mOverscanTop = top;
1127 mOverscanRight = right;
1128 mOverscanBottom = bottom;
1129 }
1130 }
1131
Dianne Hackbornc777e072010-02-12 13:07:59 -08001132 public void updateSettings() {
1133 ContentResolver resolver = mContext.getContentResolver();
1134 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001135 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001136 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001137 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001138 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1139 UserHandle.USER_CURRENT);
1140 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001141 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001142 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1143 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001144
Jeff Brown207673cd2012-06-05 17:47:11 -07001145 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001146 int userRotation = Settings.System.getIntForUser(resolver,
1147 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1148 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001149 if (mUserRotation != userRotation) {
1150 mUserRotation = userRotation;
1151 updateRotation = true;
1152 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001153 int userRotationMode = Settings.System.getIntForUser(resolver,
1154 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001155 WindowManagerPolicy.USER_ROTATION_FREE :
1156 WindowManagerPolicy.USER_ROTATION_LOCKED;
1157 if (mUserRotationMode != userRotationMode) {
1158 mUserRotationMode = userRotationMode;
1159 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001160 updateOrientationListenerLp();
1161 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001162
Dianne Hackbornc777e072010-02-12 13:07:59 -08001163 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001164 int pointerLocation = Settings.System.getIntForUser(resolver,
1165 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001166 if (mPointerLocationMode != pointerLocation) {
1167 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001168 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1169 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001170 }
1171 }
1172 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001173 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1174 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1175 String imId = Settings.Secure.getStringForUser(resolver,
1176 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001177 boolean hasSoftInput = imId != null && imId.length() > 0;
1178 if (mHasSoftInput != hasSoftInput) {
1179 mHasSoftInput = hasSoftInput;
1180 updateRotation = true;
1181 }
John Spurlockf1a36642013-10-12 17:50:42 -04001182 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001183 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001184 }
John Spurlockc6d1c602014-01-17 15:22:06 -05001185 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001186 }
1187 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001188 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001189 }
Jeff Brown70825162012-03-28 17:27:48 -07001190 }
1191
1192 private void enablePointerLocation() {
1193 if (mPointerLocationView == null) {
1194 mPointerLocationView = new PointerLocationView(mContext);
1195 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001196 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1197 WindowManager.LayoutParams.MATCH_PARENT,
1198 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001199 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001200 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1201 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1202 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1203 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001204 if (ActivityManager.isHighEndGfx()) {
1205 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1206 lp.privateFlags |=
1207 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1208 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001209 lp.format = PixelFormat.TRANSLUCENT;
1210 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001211 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001212 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001213 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001214 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001215 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
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() {
Jeff Brown70825162012-03-28 17:27:48 -07001220 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001221 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1222 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001223 wm.removeView(mPointerLocationView);
1224 mPointerLocationView = null;
1225 }
1226 }
1227
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001228 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001229 try {
1230 int rotation = mContext.getResources().getInteger(resID);
1231 switch (rotation) {
1232 case 0:
1233 return Surface.ROTATION_0;
1234 case 90:
1235 return Surface.ROTATION_90;
1236 case 180:
1237 return Surface.ROTATION_180;
1238 case 270:
1239 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001240 }
1241 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001242 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001243 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001244 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001245 }
1246
1247 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001248 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001249 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001250 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001251
1252 outAppOp[0] = AppOpsManager.OP_NONE;
1253
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001254 if (type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
1255 || type > WindowManager.LayoutParams.LAST_SYSTEM_WINDOW) {
Jeff Brown98365d72012-08-19 20:30:52 -07001256 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001257 }
1258 String permission = null;
1259 switch (type) {
1260 case TYPE_TOAST:
1261 // XXX right now the app process has complete control over
1262 // this... should introduce a token to let the system
1263 // monitor/control what they are doing.
1264 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001265 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001266 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001267 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001268 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001269 case TYPE_VOICE_INTERACTION:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001270 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001271 break;
1272 case TYPE_PHONE:
1273 case TYPE_PRIORITY_PHONE:
1274 case TYPE_SYSTEM_ALERT:
1275 case TYPE_SYSTEM_ERROR:
1276 case TYPE_SYSTEM_OVERLAY:
1277 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001278 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001279 break;
1280 default:
1281 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1282 }
1283 if (permission != null) {
1284 if (mContext.checkCallingOrSelfPermission(permission)
1285 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07001286 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001287 }
1288 }
Jeff Brown98365d72012-08-19 20:30:52 -07001289 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001290 }
Craig Mautner88400d32012-09-30 12:35:45 -07001291
1292 @Override
1293 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
1294
1295 // If this switch statement is modified, modify the comment in the declarations of
1296 // the type in {@link WindowManager.LayoutParams} as well.
1297 switch (attrs.type) {
1298 default:
1299 // These are the windows that by default are shown only to the user that created
1300 // them. If this needs to be overridden, set
1301 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
1302 // {@link WindowManager.LayoutParams}. Note that permission
1303 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
1304 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
1305 return true;
1306 }
1307 break;
1308
1309 // These are the windows that by default are shown to all users. However, to
1310 // protect against spoofing, check permissions below.
1311 case TYPE_APPLICATION_STARTING:
1312 case TYPE_BOOT_PROGRESS:
1313 case TYPE_DISPLAY_OVERLAY:
1314 case TYPE_HIDDEN_NAV_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08001315 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07001316 case TYPE_KEYGUARD_DIALOG:
1317 case TYPE_MAGNIFICATION_OVERLAY:
1318 case TYPE_NAVIGATION_BAR:
1319 case TYPE_NAVIGATION_BAR_PANEL:
1320 case TYPE_PHONE:
1321 case TYPE_POINTER:
1322 case TYPE_PRIORITY_PHONE:
1323 case TYPE_RECENTS_OVERLAY:
1324 case TYPE_SEARCH_BAR:
1325 case TYPE_STATUS_BAR:
1326 case TYPE_STATUS_BAR_PANEL:
1327 case TYPE_STATUS_BAR_SUB_PANEL:
1328 case TYPE_SYSTEM_DIALOG:
1329 case TYPE_UNIVERSE_BACKGROUND:
1330 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07001331 case TYPE_PRIVATE_PRESENTATION:
Craig Mautner88400d32012-09-30 12:35:45 -07001332 break;
1333 }
1334
1335 // Check if third party app has set window to system window type.
1336 return mContext.checkCallingOrSelfPermission(
1337 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
1338 != PackageManager.PERMISSION_GRANTED;
1339 }
1340
Craig Mautner967212c2013-04-13 21:10:58 -07001341 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001342 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
1343 switch (attrs.type) {
1344 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07001345 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001346 // These types of windows can't receive input events.
1347 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1348 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001349 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001350 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001351 case TYPE_STATUS_BAR:
1352
1353 // If the Keyguard is in a hidden state (occluded by another window), we force to
1354 // remove the wallpaper and keyguard flag so that any change in-flight after setting
1355 // the keyguard as occluded wouldn't set these flags again.
1356 // See {@link #processKeyguardSetHiddenResultLw}.
1357 if (mKeyguardHidden) {
1358 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
1359 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1360 }
1361 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001362 }
Adrian Roos38502112014-04-09 21:04:11 +02001363
1364 if (attrs.type != TYPE_STATUS_BAR) {
1365 // The status bar is the only window allowed to exhibit keyguard behavior.
1366 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
1367 }
Adrian Roosea562512014-05-05 13:33:03 +02001368
1369 if (ActivityManager.isHighEndGfx()
1370 && (attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
1371 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE
1372 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
1373 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
1374 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001375 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001376
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001377 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07001378 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001379 }
RoboErik8a2cfc32014-05-16 11:19:38 -07001380
Jeff Browndaa37532012-05-01 15:54:03 -07001381 private boolean isHidden(int accessibilityMode) {
1382 switch (accessibilityMode) {
1383 case 1:
1384 return mLidState == LID_CLOSED;
1385 case 2:
1386 return mLidState == LID_OPEN;
1387 default:
1388 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001389 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001390 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001391
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001392 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001393 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07001394 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
1395 int navigationPresence) {
1396 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
1397
Jeff Brownf71343d2013-05-31 17:59:11 -07001398 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001399 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07001400 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08001401
Jeff Browndaa37532012-05-01 15:54:03 -07001402 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
1403 || (keyboardPresence == PRESENCE_INTERNAL
1404 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001405 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07001406 if (!mHasSoftInput) {
1407 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
1408 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001409 }
1410
Jeff Browndaa37532012-05-01 15:54:03 -07001411 if (config.navigation == Configuration.NAVIGATION_NONAV
1412 || (navigationPresence == PRESENCE_INTERNAL
1413 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08001414 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08001415 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001416 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08001417
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001418 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07001419 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001420 public int windowTypeToLayerLw(int type) {
1421 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001422 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001423 }
1424 switch (type) {
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001425 case TYPE_UNIVERSE_BACKGROUND:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001426 return 1;
keunyounga446bf02013-06-21 19:07:57 -07001427 case TYPE_PRIVATE_PRESENTATION:
1428 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001429 case TYPE_WALLPAPER:
1430 // wallpaper is at the bottom, though the window manager may move it.
1431 return 2;
1432 case TYPE_PHONE:
1433 return 3;
1434 case TYPE_SEARCH_BAR:
1435 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001436 case TYPE_VOICE_INTERACTION:
1437 // voice interaction layer is almost immediately above apps.
1438 return 5;
Craig Mautner88400d32012-09-30 12:35:45 -07001439 case TYPE_RECENTS_OVERLAY:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001440 case TYPE_SYSTEM_DIALOG:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001441 return 6;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001442 case TYPE_TOAST:
1443 // toasts and the plugged-in battery thing
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001444 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001445 case TYPE_PRIORITY_PHONE:
1446 // SIM errors and unlock. Not sure if this really should be in a high layer.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001447 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001448 case TYPE_DREAM:
1449 // used for Dreams (screensavers with TYPE_DREAM windows)
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001450 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001451 case TYPE_SYSTEM_ALERT:
1452 // like the ANR / app crashed dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001453 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001454 case TYPE_INPUT_METHOD:
1455 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001456 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001457 case TYPE_INPUT_METHOD_DIALOG:
1458 // on-screen keyboards and other such input method user interfaces go here.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001459 return 12;
Jim Miller5ecd8112013-01-09 18:50:26 -08001460 case TYPE_KEYGUARD_SCRIM:
1461 // the safety window that shows behind keyguard while keyguard is starting
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001462 return 13;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001463 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001464 return 14;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001465 case TYPE_STATUS_BAR:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001466 return 15;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001467 case TYPE_STATUS_BAR_PANEL:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001468 return 16;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001469 case TYPE_KEYGUARD_DIALOG:
1470 return 17;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001471 case TYPE_VOLUME_OVERLAY:
1472 // the on-screen volume indicator and controller shown when the user
1473 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001474 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001475 case TYPE_SYSTEM_OVERLAY:
1476 // the on-screen volume indicator and controller shown when the user
1477 // changes the device volume
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001478 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001479 case TYPE_NAVIGATION_BAR:
1480 // the navigation bar, if available, shows atop most things
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001481 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001482 case TYPE_NAVIGATION_BAR_PANEL:
1483 // some panels (e.g. search) need to show on top of the navigation bar
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001484 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001485 case TYPE_SYSTEM_ERROR:
1486 // system-level error dialogs
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001487 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001488 case TYPE_MAGNIFICATION_OVERLAY:
1489 // used to highlight the magnified portion of a display
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001490 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001491 case TYPE_DISPLAY_OVERLAY:
1492 // used to simulate secondary display devices
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001493 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001494 case TYPE_DRAG:
1495 // the drag layer: input for drag-and-drop is associated with this window,
1496 // which sits above all other focusable windows
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001497 return 25;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001498 case TYPE_SECURE_SYSTEM_OVERLAY:
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001499 return 26;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001500 case TYPE_BOOT_PROGRESS:
1501 return 27;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001502 case TYPE_POINTER:
1503 // the (mouse) pointer layer
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001504 return 28;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001505 case TYPE_HIDDEN_NAV_CONSUMER:
1506 return 29;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001507 }
1508 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001509 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001510 }
1511
1512 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001513 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001514 public int subWindowTypeToLayerLw(int type) {
1515 switch (type) {
1516 case TYPE_APPLICATION_PANEL:
1517 case TYPE_APPLICATION_ATTACHED_DIALOG:
1518 return APPLICATION_PANEL_SUBLAYER;
1519 case TYPE_APPLICATION_MEDIA:
1520 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07001521 case TYPE_APPLICATION_MEDIA_OVERLAY:
1522 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001523 case TYPE_APPLICATION_SUB_PANEL:
1524 return APPLICATION_SUB_PANEL_SUBLAYER;
1525 }
1526 Log.e(TAG, "Unknown sub-window type: " + type);
1527 return 0;
1528 }
1529
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001530 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001531 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001532 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07001533 }
1534
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001535 @Override
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001536 public int getAboveUniverseLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001537 return windowTypeToLayerLw(TYPE_SYSTEM_ERROR);
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07001538 }
1539
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001540 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001541 if (mHasNavigationBar) {
1542 // For a basic navigation bar, when we are in landscape mode we place
1543 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001544 if (mNavigationBarCanMove && fullWidth > fullHeight) {
1545 return fullWidth - mNavigationBarWidthForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001546 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001547 }
1548 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001549 }
1550
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001551 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07001552 if (mHasNavigationBar) {
1553 // For a basic navigation bar, when we are in portrait mode we place
1554 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04001555 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
1556 return fullHeight - mNavigationBarHeightForRotation[rotation];
Dianne Hackborn077ee852012-04-09 16:27:07 -07001557 }
1558 }
1559 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001560 }
1561
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001562 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation) {
1563 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07001564 }
1565
Dianne Hackborn1f903c32011-09-13 19:18:06 -07001566 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation) {
John Spurlock80f00c12013-06-13 11:10:51 -04001567 // There is a separate status bar at the top of the display. We don't count that as part
1568 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07001569 // we do want to exclude it since applications can't generally use that part
1570 // of the screen.
John Spurlock80f00c12013-06-13 11:10:51 -04001571 return getNonDecorDisplayHeight(fullWidth, fullHeight, rotation) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04001572 }
1573
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001574 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001575 public boolean doesForceHide(WindowManager.LayoutParams attrs) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001576 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001577 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001578
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001579 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02001580 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
1581 return attrs.type == TYPE_STATUS_BAR;
1582 }
1583
1584 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001585 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001586 switch (attrs.type) {
1587 case TYPE_STATUS_BAR:
1588 case TYPE_NAVIGATION_BAR:
1589 case TYPE_WALLPAPER:
1590 case TYPE_DREAM:
1591 case TYPE_UNIVERSE_BACKGROUND:
Jim Miller5ecd8112013-01-09 18:50:26 -08001592 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07001593 return false;
1594 default:
1595 return true;
1596 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001597 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001598
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001599 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001600 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001601 public View addStartingWindow(IBinder appToken, String packageName, int theme,
1602 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07001603 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001604 if (!SHOW_STARTING_ANIMATIONS) {
1605 return null;
1606 }
1607 if (packageName == null) {
1608 return null;
1609 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001610
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001611 WindowManager wm = null;
1612 View view = null;
1613
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001614 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001615 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07001616 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
1617 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
1618 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08001619 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001620 try {
1621 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08001622 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001623 } catch (PackageManager.NameNotFoundException e) {
1624 // Ignore
1625 }
1626 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001627
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001628 Window win = PolicyManager.makeNewWindow(context);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001629 final TypedArray ta = win.getWindowStyle();
1630 if (ta.getBoolean(
1631 com.android.internal.R.styleable.Window_windowDisablePreview, false)
1632 || ta.getBoolean(
1633 com.android.internal.R.styleable.Window_windowShowWallpaper,false)) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001634 return null;
1635 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001636
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001637 Resources r = context.getResources();
1638 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001639
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001640 win.setType(
1641 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
1642 // Force the window flags: this is a fake window, so it is not really
1643 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
1644 // flag because we do know that the next window will take input
1645 // focus, so we want to get the IME window up on top of us right away.
1646 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001647 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001648 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1649 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1650 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08001651 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001652 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
1653 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
1654 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001655
Adam Powell04fe6eb2013-05-31 14:39:48 -07001656 win.setDefaultIcon(icon);
1657 win.setDefaultLogo(logo);
1658
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001659 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07001660 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001661
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001662 final WindowManager.LayoutParams params = win.getAttributes();
1663 params.token = appToken;
1664 params.packageName = packageName;
1665 params.windowAnimations = win.getWindowStyle().getResourceId(
1666 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
Dianne Hackborn5d927c22011-09-02 12:22:18 -07001667 params.privateFlags |=
1668 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07001669 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07001670
1671 if (!compatInfo.supportsScreen()) {
1672 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
1673 }
1674
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001675 params.setTitle("Starting " + packageName);
1676
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001677 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
1678 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001679
1680 if (win.isFloating()) {
1681 // Whoops, there is no way to display an animation/preview
1682 // of such a thing! After all that work... let's skip it.
1683 // (Note that we must do this here because it is in
1684 // getDecorView() where the theme is evaluated... maybe
1685 // we should peek the floating attribute from the theme
1686 // earlier.)
1687 return null;
1688 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07001689
Craig Mautner6fbda632012-07-03 09:26:39 -07001690 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001691 TAG, "Adding starting window for " + packageName
1692 + " / " + appToken + ": "
1693 + (view.getParent() != null ? view : null));
1694
1695 wm.addView(view, params);
1696
1697 // Only return the view if it was successfully added to the
1698 // window manager... which we can tell by it having a parent.
1699 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07001700 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001701 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08001702 Log.w(TAG, appToken + " already running, starting window not displayed. " +
1703 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001704 } catch (RuntimeException e) {
1705 // don't crash if something else bad happens, for example a
1706 // failure loading resources because we are loading from an app
1707 // on external storage that has been unmounted.
1708 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02001709 } finally {
1710 if (view != null && view.getParent() == null) {
1711 Log.w(TAG, "view not successfully added to wm, removing view");
1712 wm.removeViewImmediate(view);
1713 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001714 }
1715
1716 return null;
1717 }
1718
1719 /** {@inheritDoc} */
1720 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner6fbda632012-07-03 09:26:39 -07001721 if (DEBUG_STARTING_WINDOW) {
1722 RuntimeException e = new RuntimeException("here");
1723 e.fillInStackTrace();
1724 Log.v(TAG, "Removing starting window for " + appToken + ": " + window, e);
1725 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001726
1727 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001728 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001729 wm.removeView(window);
1730 }
1731 }
1732
1733 /**
1734 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07001735 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001736 * Currently enforces that three window types are singletons:
1737 * <ul>
1738 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001739 * <li>KEYGUARD_TYPE</li>
1740 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07001741 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001742 * @param win The window to be added
1743 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07001744 *
Jeff Brown98365d72012-08-19 20:30:52 -07001745 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
1746 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001747 */
1748 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
1749 switch (attrs.type) {
1750 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001751 mContext.enforceCallingOrSelfPermission(
1752 android.Manifest.permission.STATUS_BAR_SERVICE,
1753 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001754 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001755 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001756 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001757 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001758 }
1759 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001760 mStatusBarController.setWindow(win);
John Spurlock8fdfe622014-05-21 17:10:10 -04001761 mKeyguardDelegate.hideScrim();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001762 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001763 case TYPE_NAVIGATION_BAR:
1764 mContext.enforceCallingOrSelfPermission(
1765 android.Manifest.permission.STATUS_BAR_SERVICE,
1766 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001767 if (mNavigationBar != null) {
1768 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07001769 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001770 }
1771 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001772 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04001773 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07001774 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001775 break;
Jim Millere898ac52012-04-06 17:10:57 -07001776 case TYPE_NAVIGATION_BAR_PANEL:
1777 mContext.enforceCallingOrSelfPermission(
1778 android.Manifest.permission.STATUS_BAR_SERVICE,
1779 "PhoneWindowManager");
1780 break;
Dianne Hackborn08743722009-12-21 12:16:51 -08001781 case TYPE_STATUS_BAR_PANEL:
Joe Onorato8bc6c512010-06-04 16:21:12 -04001782 mContext.enforceCallingOrSelfPermission(
1783 android.Manifest.permission.STATUS_BAR_SERVICE,
1784 "PhoneWindowManager");
Dianne Hackborn08743722009-12-21 12:16:51 -08001785 break;
Joe Onorato29fc2c92010-11-24 10:26:50 -08001786 case TYPE_STATUS_BAR_SUB_PANEL:
1787 mContext.enforceCallingOrSelfPermission(
1788 android.Manifest.permission.STATUS_BAR_SERVICE,
1789 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08001790 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08001791 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08001792 if (mKeyguardScrim != null) {
1793 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
1794 }
Jim Miller5ecd8112013-01-09 18:50:26 -08001795 mKeyguardScrim = win;
1796 break;
1797
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001798 }
Jeff Brown98365d72012-08-19 20:30:52 -07001799 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001800 }
1801
1802 /** {@inheritDoc} */
1803 public void removeWindowLw(WindowState win) {
1804 if (mStatusBar == win) {
1805 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001806 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07001807 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08001808 } else if (mKeyguardScrim == win) {
1809 Log.v(TAG, "Removing keyguard scrim");
1810 mKeyguardScrim = null;
1811 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04001812 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04001813 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001814 }
1815 }
1816
1817 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07001818
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001819 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08001820 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001821 public int selectAnimationLw(WindowState win, int transit) {
1822 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
1823 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001824 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001825 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001826 if (transit == TRANSIT_EXIT
1827 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001828 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001829 } else if (transit == TRANSIT_ENTER
1830 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01001831 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001832 }
1833 } else if (win == mNavigationBar) {
1834 // This can be on either the bottom or the right.
1835 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001836 if (transit == TRANSIT_EXIT
1837 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001838 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001839 } else if (transit == TRANSIT_ENTER
1840 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001841 return R.anim.dock_bottom_enter;
1842 }
1843 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08001844 if (transit == TRANSIT_EXIT
1845 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001846 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08001847 } else if (transit == TRANSIT_ENTER
1848 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001849 return R.anim.dock_right_enter;
1850 }
1851 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08001852 }
1853
1854 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001855 if (win.hasAppShownWindows()) {
1856 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
1857 return com.android.internal.R.anim.app_starting_exit;
1858 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07001859 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07001860 && transit == TRANSIT_ENTER) {
1861 // Special case: we are animating in a dream, while the keyguard
1862 // is shown. We don't want an animation on the dream, because
1863 // we need it shown immediately with the keyguard animating away
1864 // to reveal it.
1865 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001866 }
1867
1868 return 0;
1869 }
1870
Craig Mautner3c174372013-02-21 17:54:37 -08001871 @Override
1872 public void selectRotationAnimationLw(int anim[]) {
1873 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
1874 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
1875 + (mTopFullscreenOpaqueWindowState == null ?
1876 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
1877 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
1878 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
1879 case ROTATION_ANIMATION_CROSSFADE:
1880 anim[0] = R.anim.rotation_animation_xfade_exit;
1881 anim[1] = R.anim.rotation_animation_enter;
1882 break;
1883 case ROTATION_ANIMATION_JUMPCUT:
1884 anim[0] = R.anim.rotation_animation_jump_exit;
1885 anim[1] = R.anim.rotation_animation_enter;
1886 break;
1887 case ROTATION_ANIMATION_ROTATE:
1888 default:
1889 anim[0] = anim[1] = 0;
1890 break;
1891 }
1892 } else {
1893 anim[0] = anim[1] = 0;
1894 }
1895 }
1896
1897 @Override
1898 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
1899 boolean forceDefault) {
1900 switch (exitAnimId) {
1901 case R.anim.rotation_animation_xfade_exit:
1902 case R.anim.rotation_animation_jump_exit:
1903 // These are the only cases that matter.
1904 if (forceDefault) {
1905 return false;
1906 }
1907 int anim[] = new int[2];
1908 selectRotationAnimationLw(anim);
1909 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
1910 default:
1911 return true;
1912 }
1913 }
1914
1915 @Override
Dianne Hackborn0c2acff2012-04-12 15:17:07 -07001916 public Animation createForceHideEnterAnimation(boolean onWallpaper) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02001917 return AnimationUtils.loadAnimation(mContext,
1918 com.android.internal.R.anim.lock_screen_behind_enter);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07001919 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04001920
1921 private static void awakenDreams() {
1922 IDreamManager dreamManager = getDreamManager();
1923 if (dreamManager != null) {
1924 try {
1925 dreamManager.awaken();
1926 } catch (RemoteException e) {
1927 // fine, stay asleep then
1928 }
1929 }
1930 }
1931
1932 static IDreamManager getDreamManager() {
1933 return IDreamManager.Stub.asInterface(
1934 ServiceManager.checkService(DreamService.DREAM_SERVICE));
1935 }
1936
Santos Cordon3afed572014-05-21 15:22:12 -07001937 TelephonyManager getTelephonyService() {
1938 return (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001939 }
1940
Jeff Brown4d396052010-10-29 21:50:21 -07001941 static IAudioService getAudioService() {
1942 IAudioService audioService = IAudioService.Stub.asInterface(
1943 ServiceManager.checkService(Context.AUDIO_SERVICE));
1944 if (audioService == null) {
1945 Log.w(TAG, "Unable to find IAudioService interface.");
1946 }
1947 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001948 }
1949
1950 boolean keyguardOn() {
1951 return keyguardIsShowingTq() || inKeyguardRestrictedKeyInputMode();
1952 }
1953
1954 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
1955 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
1956 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
1957 };
1958
1959 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001960 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001961 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001962 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08001963 final int keyCode = event.getKeyCode();
1964 final int repeatCount = event.getRepeatCount();
1965 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001966 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08001967 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
1968 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001969
Jeff Brown40013652012-05-16 21:22:36 -07001970 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07001971 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07001972 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
1973 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001974 }
1975
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001976 // If we think we might have a volume down & power key chord on the way
1977 // but we're not sure, then tell the dispatcher to wait a little while and
1978 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08001979 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001980 if (mVolumeDownKeyTriggered && !mPowerKeyTriggered) {
1981 final long now = SystemClock.uptimeMillis();
1982 final long timeoutTime = mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
1983 if (now < timeoutTime) {
1984 return timeoutTime - now;
1985 }
1986 }
1987 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
1988 && mVolumeDownKeyConsumedByScreenshotChord) {
1989 if (!down) {
1990 mVolumeDownKeyConsumedByScreenshotChord = false;
1991 }
1992 return -1;
1993 }
1994 }
1995
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001996 // First we always handle the home key here, so applications
1997 // can never break it, although if keyguard is on, we do let
1998 // it handle it, because that gives us the correct 5 second
1999 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002000 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002001
Jeff Brown49ed71d2010-12-06 17:13:33 -08002002 // If we have released the home key, and didn't do anything else
2003 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002004 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002005 cancelPreloadRecentApps();
2006
Jeff Brown49ed71d2010-12-06 17:13:33 -08002007 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002008 if (mHomeConsumed) {
2009 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002010 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002011 }
Jeff Browncaca8812013-05-09 13:34:33 -07002012
2013 if (canceled) {
2014 Log.i(TAG, "Ignoring HOME; event canceled.");
2015 return -1;
2016 }
2017
2018 // If an incoming call is ringing, HOME is totally disabled.
2019 // (The user is already on the InCallScreen at this point,
2020 // and his ONLY options are to answer or reject the call.)
Santos Cordon3afed572014-05-21 15:22:12 -07002021 TelephonyManager telephonyManager = getTelephonyService();
2022 if (telephonyManager != null && telephonyManager.isRinging()) {
2023 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2024 return -1;
Jeff Browncaca8812013-05-09 13:34:33 -07002025 }
2026
2027 // Delay handling home if a double-tap is possible.
2028 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2029 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2030 mHomeDoubleTapPending = true;
2031 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2032 ViewConfiguration.getDoubleTapTimeout());
2033 return -1;
2034 }
2035
2036 // Go home!
2037 launchHomeFromHotKey();
2038 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002039 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002040
2041 // If a system window has focus, then it doesn't make sense
2042 // right now to interact with applications.
2043 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2044 if (attrs != null) {
2045 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002046 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2047 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2048 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002049 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002050 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002051 }
2052 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2053 for (int i=0; i<typeCount; i++) {
2054 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2055 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002056 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002057 }
2058 }
2059 }
Jeff Browncaca8812013-05-09 13:34:33 -07002060
2061 // Remember that home is pressed and handle special actions.
2062 if (repeatCount == 0) {
2063 mHomePressed = true;
2064 if (mHomeDoubleTapPending) {
2065 mHomeDoubleTapPending = false;
2066 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2067 handleDoubleTapOnHome();
2068 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2069 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2070 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002071 }
Jeff Browncaca8812013-05-09 13:34:33 -07002072 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2073 if (!keyguardOn) {
2074 handleLongPressOnHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002075 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002076 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002077 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002078 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002079 // Hijack modified menu keys for debugging features
2080 final int chordBug = KeyEvent.META_SHIFT_ON;
2081
2082 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002083 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002084 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002085 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2086 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002087 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002088 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002089 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002090 Intent service = new Intent();
2091 service.setClassName(mContext, "com.android.server.LoadAverageService");
2092 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002093 boolean shown = Settings.Global.getInt(
2094 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002095 if (!shown) {
2096 mContext.startService(service);
2097 } else {
2098 mContext.stopService(service);
2099 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002100 Settings.Global.putInt(
2101 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002102 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002103 }
2104 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002105 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002106 if (down) {
2107 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002108 mSearchKeyShortcutPending = true;
2109 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002110 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002111 } else {
2112 mSearchKeyShortcutPending = false;
2113 if (mConsumeSearchKeyUp) {
2114 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002115 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002116 }
2117 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002118 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002119 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002120 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002121 if (down && repeatCount == 0) {
2122 preloadRecentApps();
2123 } else if (!down) {
2124 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002125 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002126 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002127 return -1;
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002128 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2129 if (down) {
2130 if (repeatCount == 0) {
2131 mAssistKeyLongPressed = false;
2132 } else if (repeatCount == 1) {
2133 mAssistKeyLongPressed = true;
2134 if (!keyguardOn) {
2135 launchAssistLongPressAction();
2136 }
2137 }
2138 } else {
2139 if (mAssistKeyLongPressed) {
2140 mAssistKeyLongPressed = false;
2141 } else {
2142 if (!keyguardOn) {
2143 launchAssistAction();
2144 }
2145 }
2146 }
2147 return -1;
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002148 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2149 if (down && repeatCount == 0) {
2150 mHandler.post(mScreenshotRunnable);
2151 }
2152 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002153 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2154 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2155 if (down) {
2156 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2157
2158 // Disable autobrightness if it's on
2159 int auto = Settings.System.getIntForUser(
2160 mContext.getContentResolver(),
2161 Settings.System.SCREEN_BRIGHTNESS_MODE,
2162 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2163 UserHandle.USER_CURRENT_OR_SELF);
2164 if (auto != 0) {
2165 Settings.System.putIntForUser(mContext.getContentResolver(),
2166 Settings.System.SCREEN_BRIGHTNESS_MODE,
2167 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2168 UserHandle.USER_CURRENT_OR_SELF);
2169 }
2170
2171 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2172 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2173 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2174 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2175 Settings.System.SCREEN_BRIGHTNESS,
2176 mPowerManager.getDefaultScreenBrightnessSetting(),
2177 UserHandle.USER_CURRENT_OR_SELF);
2178 brightness += step;
2179 // Make sure we don't go beyond the limits.
2180 brightness = Math.min(max, brightness);
2181 brightness = Math.max(min, brightness);
2182
2183 Settings.System.putIntForUser(mContext.getContentResolver(),
2184 Settings.System.SCREEN_BRIGHTNESS, brightness,
2185 UserHandle.USER_CURRENT_OR_SELF);
2186 Intent intent = new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG);
2187 mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT_OR_SELF);
2188 }
2189 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002190 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002191
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002192 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08002193 // Any printing key that is chorded with Search should be consumed
2194 // even if no shortcut was invoked. This prevents text from being
2195 // inadvertently inserted when using a keyboard that has built-in macro
2196 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002197 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08002198 final KeyCharacterMap kcm = event.getKeyCharacterMap();
2199 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002200 mConsumeSearchKeyUp = true;
2201 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08002202 if (down && repeatCount == 0 && !keyguardOn) {
2203 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
2204 if (shortcutIntent != null) {
2205 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002206 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002207 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002208 } catch (ActivityNotFoundException ex) {
2209 Slog.w(TAG, "Dropping shortcut key combination because "
2210 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002211 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08002212 }
Jeff Browncaab4d02010-12-09 22:13:41 -08002213 } else {
2214 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002215 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002216 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002217 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002218 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002219 }
2220 }
2221
Jeff Brown68b909d2011-12-07 16:36:01 -08002222 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07002223 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08002224 && (metaState & KeyEvent.META_META_ON) != 0) {
2225 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07002226 if (kcm.isPrintingKey(keyCode)) {
2227 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
2228 metaState & ~(KeyEvent.META_META_ON
2229 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
2230 if (shortcutIntent != null) {
2231 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2232 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002233 mContext.startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07002234 } catch (ActivityNotFoundException ex) {
2235 Slog.w(TAG, "Dropping shortcut key combination because "
2236 + "the activity to which it is registered was not found: "
2237 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
2238 }
2239 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08002240 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002241 }
2242 }
2243
Jeff Brown6651a632011-11-28 12:59:11 -08002244 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07002245 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08002246 String category = sApplicationLaunchKeyCategories.get(keyCode);
2247 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08002248 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08002249 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2250 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002251 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08002252 } catch (ActivityNotFoundException ex) {
2253 Slog.w(TAG, "Dropping application launch key because "
2254 + "the activity to which it is registered was not found: "
2255 + "keyCode=" + keyCode + ", category=" + category, ex);
2256 }
Jeff Brown68b909d2011-12-07 16:36:01 -08002257 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08002258 }
2259 }
2260
Jeff Brown68b909d2011-12-07 16:36:01 -08002261 // Display task switcher for ALT-TAB or Meta-TAB.
2262 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002263 if (mRecentAppsHeldModifiers == 0 && !keyguardOn) {
Jeff Brown68b909d2011-12-07 16:36:01 -08002264 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
2265 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)
2266 || KeyEvent.metaStateHasModifiers(
2267 shiftlessModifiers, KeyEvent.META_META_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002268 mRecentAppsHeldModifiers = shiftlessModifiers;
2269 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002270 return -1;
2271 }
2272 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07002273 } else if (!down && mRecentAppsHeldModifiers != 0
2274 && (metaState & mRecentAppsHeldModifiers) == 0) {
2275 mRecentAppsHeldModifiers = 0;
Winson Chung6cb485f2014-05-19 10:30:43 -07002276 hideRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08002277 }
2278
Jeff Browncf39bdf2012-05-18 14:41:19 -07002279 // Handle keyboard language switching.
2280 if (down && repeatCount == 0
2281 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2282 || (keyCode == KeyEvent.KEYCODE_SPACE
2283 && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
2284 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
2285 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
2286 return -1;
2287 }
2288 if (mLanguageSwitchKeyPressed && !down
2289 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
2290 || keyCode == KeyEvent.KEYCODE_SPACE)) {
2291 mLanguageSwitchKeyPressed = false;
2292 return -1;
2293 }
2294
Justin Kohd378ad72013-04-01 12:18:26 -07002295 if (mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
2296 return -1;
2297 }
2298
Jeff Brown68b909d2011-12-07 16:36:01 -08002299 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002300 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002301 }
2302
Jeff Brown3915bb82010-11-05 15:02:16 -07002303 /** {@inheritDoc} */
2304 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08002305 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07002306 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07002307 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08002308 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
2309 + ", flags=" + event.getFlags()
2310 + ", keyCode=" + event.getKeyCode()
2311 + ", scanCode=" + event.getScanCode()
2312 + ", metaState=" + event.getMetaState()
2313 + ", repeatCount=" + event.getRepeatCount()
2314 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07002315 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002316
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002317 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002318 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
2319 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08002320 final int keyCode = event.getKeyCode();
2321 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002322 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
2323 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002324
Jeff Brown54875002011-04-06 15:33:01 -07002325 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002326 final FallbackAction fallbackAction;
2327 if (initialDown) {
2328 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
2329 } else {
2330 fallbackAction = mFallbackActions.get(keyCode);
2331 }
2332
2333 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07002334 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002335 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
2336 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08002337 }
2338
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002339 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
2340 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08002341 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002342 event.getAction(), fallbackAction.keyCode,
2343 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08002344 event.getDeviceId(), event.getScanCode(),
2345 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002346
2347 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
2348 fallbackEvent.recycle();
2349 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002350 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002351
2352 if (initialDown) {
2353 mFallbackActions.put(keyCode, fallbackAction);
2354 } else if (event.getAction() == KeyEvent.ACTION_UP) {
2355 mFallbackActions.remove(keyCode);
2356 fallbackAction.recycle();
2357 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002358 }
2359 }
2360
Jeff Brown40013652012-05-16 21:22:36 -07002361 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002362 if (fallbackEvent == null) {
2363 Slog.d(TAG, "No fallback.");
2364 } else {
2365 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
2366 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002367 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002368 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07002369 }
2370
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002371 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07002372 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002373 if ((actions & ACTION_PASS_TO_USER) != 0) {
2374 long delayMillis = interceptKeyBeforeDispatching(
2375 win, fallbackEvent, policyFlags);
2376 if (delayMillis == 0) {
2377 return true;
2378 }
2379 }
2380 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08002381 }
2382
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002383 private void launchAssistLongPressAction() {
2384 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
2385 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
2386
2387 // launch the search activity
2388 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
2389 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2390 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07002391 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07002392 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002393 SearchManager searchManager = getSearchManager();
2394 if (searchManager != null) {
2395 searchManager.stopSearch();
2396 }
Michael Wright43e27f72013-04-10 14:06:48 -07002397 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002398 } catch (ActivityNotFoundException e) {
2399 Slog.w(TAG, "No activity to handle assist long press action.", e);
2400 }
2401 }
2402
2403 private void launchAssistAction() {
2404 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Amith Yamasanic1d07a42012-08-14 09:32:02 -07002405 Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
Dianne Hackbornf9c5e0f2013-01-23 14:39:13 -08002406 .getAssistIntent(mContext, true, UserHandle.USER_CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002407 if (intent != null) {
2408 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
2409 | Intent.FLAG_ACTIVITY_SINGLE_TOP
2410 | Intent.FLAG_ACTIVITY_CLEAR_TOP);
2411 try {
Michael Wright43e27f72013-04-10 14:06:48 -07002412 mContext.startActivityAsUser(intent, UserHandle.CURRENT);
Jim Miller45308b12012-06-18 19:23:39 -07002413 } catch (ActivityNotFoundException e) {
2414 Slog.w(TAG, "No activity to handle assist action.", e);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002415 }
2416 }
2417 }
2418
2419 private SearchManager getSearchManager() {
2420 if (mSearchManager == null) {
2421 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
2422 }
2423 return mSearchManager;
2424 }
2425
Jeff Browncaca8812013-05-09 13:34:33 -07002426 private void preloadRecentApps() {
2427 mPreloadedRecentApps = true;
2428 try {
2429 IStatusBarService statusbar = getStatusBarService();
2430 if (statusbar != null) {
2431 statusbar.preloadRecentApps();
2432 }
2433 } catch (RemoteException e) {
2434 Slog.e(TAG, "RemoteException when preloading recent apps", e);
2435 // re-acquire status bar service next time it is needed.
2436 mStatusBarService = null;
2437 }
2438 }
2439
2440 private void cancelPreloadRecentApps() {
2441 if (mPreloadedRecentApps) {
2442 mPreloadedRecentApps = false;
2443 try {
2444 IStatusBarService statusbar = getStatusBarService();
2445 if (statusbar != null) {
2446 statusbar.cancelPreloadRecentApps();
2447 }
2448 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002449 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07002450 // re-acquire status bar service next time it is needed.
2451 mStatusBarService = null;
2452 }
2453 }
2454 }
2455
2456 private void toggleRecentApps() {
2457 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07002458 try {
2459 IStatusBarService statusbar = getStatusBarService();
2460 if (statusbar != null) {
2461 statusbar.toggleRecentApps();
2462 }
2463 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002464 Slog.e(TAG, "RemoteException when toggling recent apps", e);
2465 // re-acquire status bar service next time it is needed.
2466 mStatusBarService = null;
2467 }
2468 }
2469
2470 private void showRecentApps(boolean triggeredFromAltTab) {
2471 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2472 try {
2473 IStatusBarService statusbar = getStatusBarService();
2474 if (statusbar != null) {
2475 statusbar.showRecentApps(triggeredFromAltTab);
2476 }
2477 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07002478 Slog.e(TAG, "RemoteException when showing recent apps", e);
2479 // re-acquire status bar service next time it is needed.
2480 mStatusBarService = null;
2481 }
2482 }
2483
Winson Chung6cb485f2014-05-19 10:30:43 -07002484 private void hideRecentApps(boolean triggeredFromAltTab) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07002485 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
2486 try {
2487 IStatusBarService statusbar = getStatusBarService();
2488 if (statusbar != null) {
Winson Chung6cb485f2014-05-19 10:30:43 -07002489 statusbar.hideRecentApps(triggeredFromAltTab);
Winson Chung1e8d71b2014-05-16 17:05:22 -07002490 }
2491 } catch (RemoteException e) {
2492 Slog.e(TAG, "RemoteException when closing recent apps", e);
2493 // re-acquire status bar service next time it is needed.
2494 mStatusBarService = null;
2495 }
2496 }
2497
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002498 /**
2499 * A home key -> launch home action was detected. Take the appropriate action
2500 * given the situation with the keyguard.
2501 */
2502 void launchHomeFromHotKey() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01002503 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowingAndNotOccluded()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002504 // don't launch home if keyguard showing
Jim Miller5ecd8112013-01-09 18:50:26 -08002505 } else if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002506 // when in keyguard restricted mode, must first verify unlock
2507 // before launching home
Jim Miller5ecd8112013-01-09 18:50:26 -08002508 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002509 public void onKeyguardExitResult(boolean success) {
2510 if (success) {
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002511 try {
2512 ActivityManagerNative.getDefault().stopAppSwitches();
2513 } catch (RemoteException e) {
2514 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002515 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002516 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002517 }
2518 }
2519 });
2520 } else {
2521 // no keyguard stuff to worry about, just launch home!
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07002522 try {
2523 ActivityManagerNative.getDefault().stopAppSwitches();
2524 } catch (RemoteException e) {
2525 }
Joe Onoratof275f0c2009-11-24 16:11:13 -05002526 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07002527 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002528 }
2529 }
2530
John Spurlock04db1762013-05-13 12:46:41 -04002531 private final Runnable mClearHideNavigationFlag = new Runnable() {
2532 @Override
2533 public void run() {
2534 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2535 // Clear flags.
2536 mForceClearedSystemUiFlags &=
2537 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
2538 }
2539 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002540 }
2541 };
2542
2543 /**
2544 * Input handler used while nav bar is hidden. Captures any touch on the screen,
2545 * to determine when the nav bar should be shown and prevent applications from
2546 * receiving those touches.
2547 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08002548 final class HideNavInputEventReceiver extends InputEventReceiver {
2549 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
2550 super(inputChannel, looper);
2551 }
2552
Dianne Hackborndf89e652011-10-06 22:35:11 -07002553 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08002554 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002555 boolean handled = false;
2556 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08002557 if (event instanceof MotionEvent
2558 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
2559 final MotionEvent motionEvent = (MotionEvent)event;
2560 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07002561 // When the user taps down, we re-show the nav bar.
2562 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04002563 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002564 // Any user activity always causes us to show the
2565 // navigation controls, if they had been hidden.
2566 // We also clear the low profile and only content
2567 // flags so that tapping on the screen will atomically
2568 // restore all currently hidden screen decorations.
2569 int newVal = mResettingSystemUiFlags |
2570 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
2571 View.SYSTEM_UI_FLAG_LOW_PROFILE |
2572 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002573 if (mResettingSystemUiFlags != newVal) {
2574 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002575 changed = true;
2576 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002577 // We don't allow the system's nav bar to be hidden
2578 // again for 1 second, to prevent applications from
2579 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002580 newVal = mForceClearedSystemUiFlags |
2581 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07002582 if (mForceClearedSystemUiFlags != newVal) {
2583 mForceClearedSystemUiFlags = newVal;
2584 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04002585 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002586 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002587 }
2588 if (changed) {
2589 mWindowManagerFuncs.reevaluateStatusBarVisibility();
2590 }
2591 }
2592 }
2593 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08002594 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07002595 }
2596 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08002597 }
2598 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
2599 new InputEventReceiver.Factory() {
2600 @Override
2601 public InputEventReceiver createInputEventReceiver(
2602 InputChannel inputChannel, Looper looper) {
2603 return new HideNavInputEventReceiver(inputChannel, looper);
2604 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07002605 };
2606
2607 @Override
2608 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04002609 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
2610 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
John Spurlock27735a42013-08-14 17:57:38 -04002611
Dianne Hackborndf89e652011-10-06 22:35:11 -07002612 // Reset any bits in mForceClearingStatusBarVisibility that
2613 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002614 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002615 // Clear any bits in the new visibility that are currently being
2616 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07002617 return visibility & ~mResettingSystemUiFlags
2618 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07002619 }
2620
Craig Mautner69b08182012-09-05 13:07:13 -07002621 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002622 public void getContentInsetHintLw(WindowManager.LayoutParams attrs, Rect contentInset) {
John Spurlockc6d1c602014-01-17 15:22:06 -05002623 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05002624 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
2625 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002626
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002627 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002628 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002629 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002630 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002631 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002632 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
2633 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
2634 } else {
2635 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
2636 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
2637 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002638 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2639 if ((fl & FLAG_FULLSCREEN) != 0) {
2640 contentInset.set(mStableFullscreenLeft, mStableFullscreenTop,
2641 availRight - mStableFullscreenRight,
2642 availBottom - mStableFullscreenBottom);
2643 } else {
2644 contentInset.set(mStableLeft, mStableTop,
2645 availRight - mStableRight, availBottom - mStableBottom);
2646 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08002647 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002648 contentInset.setEmpty();
2649 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002650 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
2651 contentInset.set(mCurLeft, mCurTop,
2652 availRight - mCurRight, availBottom - mCurBottom);
2653 } else {
2654 contentInset.set(mCurLeft, mCurTop,
2655 availRight - mCurRight, availBottom - mCurBottom);
2656 }
2657 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002658 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002659 contentInset.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002660 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07002661
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002662 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002663 @Override
2664 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
2665 int displayRotation) {
Dianne Hackbornc652de82013-02-15 16:32:56 -08002666 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
2667 if (isDefaultDisplay) {
2668 switch (displayRotation) {
2669 case Surface.ROTATION_90:
2670 overscanLeft = mOverscanTop;
2671 overscanTop = mOverscanRight;
2672 overscanRight = mOverscanBottom;
2673 overscanBottom = mOverscanLeft;
2674 break;
2675 case Surface.ROTATION_180:
2676 overscanLeft = mOverscanRight;
2677 overscanTop = mOverscanBottom;
2678 overscanRight = mOverscanLeft;
2679 overscanBottom = mOverscanTop;
2680 break;
2681 case Surface.ROTATION_270:
2682 overscanLeft = mOverscanBottom;
2683 overscanTop = mOverscanLeft;
2684 overscanRight = mOverscanTop;
2685 overscanBottom = mOverscanRight;
2686 break;
2687 default:
2688 overscanLeft = mOverscanLeft;
2689 overscanTop = mOverscanTop;
2690 overscanRight = mOverscanRight;
2691 overscanBottom = mOverscanBottom;
2692 break;
2693 }
2694 } else {
2695 overscanLeft = 0;
2696 overscanTop = 0;
2697 overscanRight = 0;
2698 overscanBottom = 0;
2699 }
Dianne Hackborn313440842013-02-19 19:22:59 -08002700 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
2701 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
2702 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
2703 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08002704 mSystemLeft = 0;
2705 mSystemTop = 0;
2706 mSystemRight = displayWidth;
2707 mSystemBottom = displayHeight;
2708 mUnrestrictedScreenLeft = overscanLeft;
2709 mUnrestrictedScreenTop = overscanTop;
2710 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
2711 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
2712 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
2713 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04002714 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
2715 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002716 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08002717 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002718 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08002719 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002720 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08002721 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002722 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08002723 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002724 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002725 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002726
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002727 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
2728 final Rect pf = mTmpParentFrame;
2729 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002730 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002731 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04002732 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002733 pf.left = df.left = of.left = vf.left = mDockLeft;
2734 pf.top = df.top = of.top = vf.top = mDockTop;
2735 pf.right = df.right = of.right = vf.right = mDockRight;
2736 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04002737 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002738
Craig Mautner69b08182012-09-05 13:07:13 -07002739 if (isDefaultDisplay) {
2740 // For purposes of putting out fake window up to steal focus, we will
2741 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04002742 final int sysui = mLastSystemUiFlags;
2743 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02002744 boolean navTranslucent = (sysui
2745 & (View.NAVIGATION_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04002746 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
2747 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
2748 boolean navAllowedHidden = immersive || immersiveSticky;
2749 navTranslucent &= !immersiveSticky; // transient trumps translucent
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002750 navTranslucent &= areTranslucentBarsAllowed();
Dianne Hackborne26ab702011-10-16 13:21:33 -07002751
Craig Mautner69b08182012-09-05 13:07:13 -07002752 // When the navigation bar isn't visible, we put up a fake
2753 // input window to catch all touch events. This way we can
2754 // detect when the user presses anywhere to bring back the nav
2755 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04002756 if (navVisible || navAllowedHidden) {
Craig Mautner69b08182012-09-05 13:07:13 -07002757 if (mHideNavFakeWindow != null) {
2758 mHideNavFakeWindow.dismiss();
2759 mHideNavFakeWindow = null;
2760 }
2761 } else if (mHideNavFakeWindow == null) {
2762 mHideNavFakeWindow = mWindowManagerFuncs.addFakeWindow(
2763 mHandler.getLooper(), mHideNavInputEventReceiverFactory,
Adam Lesinski95c42972013-10-02 10:13:27 -07002764 "hidden nav", WindowManager.LayoutParams.TYPE_HIDDEN_NAV_CONSUMER, 0,
Craig Mautner69b08182012-09-05 13:07:13 -07002765 0, false, false, true);
Dianne Hackborne26ab702011-10-16 13:21:33 -07002766 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07002767
Craig Mautner69b08182012-09-05 13:07:13 -07002768 // For purposes of positioning and showing the nav bar, if we have
2769 // decided that it can't be hidden (because of the screen aspect ratio),
2770 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07002771 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002772
John Spurlockad3e6cb2013-04-30 08:47:43 -04002773 boolean updateSysUiVisibility = false;
Craig Mautner69b08182012-09-05 13:07:13 -07002774 if (mNavigationBar != null) {
John Spurlock27735a42013-08-14 17:57:38 -04002775 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
Craig Mautner69b08182012-09-05 13:07:13 -07002776 // Force the navigation bar to its appropriate place and
2777 // size. We need to do this directly, instead of relying on
2778 // it to bubble up from the nav bar, because this needs to
2779 // change atomically with screen rotations.
2780 mNavigationBarOnBottom = (!mNavigationBarCanMove || displayWidth < displayHeight);
2781 if (mNavigationBarOnBottom) {
2782 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002783 int top = displayHeight - overscanBottom
2784 - mNavigationBarHeightForRotation[displayRotation];
2785 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
Craig Mautner69b08182012-09-05 13:07:13 -07002786 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
John Spurlockf95b89a2013-10-10 22:10:42 -04002787 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002788 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002789 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002790 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002791 mDockBottom = mTmpNavigationFrame.top;
Dianne Hackborn313440842013-02-19 19:22:59 -08002792 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
2793 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002794 } else {
2795 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002796 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002797 }
John Spurlockc6d1c602014-01-17 15:22:06 -05002798 if (navVisible && !navTranslucent && !navAllowedHidden
2799 && !mNavigationBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04002800 && !mNavigationBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002801 // If the opaque nav bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002802 // and not in the process of animating on or off, then
2803 // we can tell the app that it is covered by it.
2804 mSystemBottom = mTmpNavigationFrame.top;
2805 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002806 } else {
Craig Mautner69b08182012-09-05 13:07:13 -07002807 // Landscape screen; nav bar goes to the right.
Dianne Hackbornc652de82013-02-15 16:32:56 -08002808 int left = displayWidth - overscanRight
2809 - mNavigationBarWidthForRotation[displayRotation];
2810 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
Craig Mautner69b08182012-09-05 13:07:13 -07002811 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
John Spurlockf95b89a2013-10-10 22:10:42 -04002812 if (transientNavBarShowing) {
John Spurlock27735a42013-08-14 17:57:38 -04002813 mNavigationBarController.setBarShowingLw(true);
John Spurlockad3e6cb2013-04-30 08:47:43 -04002814 } else if (navVisible) {
John Spurlock27735a42013-08-14 17:57:38 -04002815 mNavigationBarController.setBarShowingLw(true);
Craig Mautner69b08182012-09-05 13:07:13 -07002816 mDockRight = mTmpNavigationFrame.left;
Dianne Hackborn313440842013-02-19 19:22:59 -08002817 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
2818 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
Craig Mautner69b08182012-09-05 13:07:13 -07002819 } else {
2820 // We currently want to hide the navigation UI.
John Spurlock27735a42013-08-14 17:57:38 -04002821 mNavigationBarController.setBarShowingLw(false);
Craig Mautner69b08182012-09-05 13:07:13 -07002822 }
John Spurlockbd957402013-10-03 11:38:39 -04002823 if (navVisible && !navTranslucent && !mNavigationBar.isAnimatingLw()
2824 && !mNavigationBarController.wasRecentlyTranslucent()) {
Craig Mautner69b08182012-09-05 13:07:13 -07002825 // If the nav bar is currently requested to be visible,
2826 // and not in the process of animating on or off, then
2827 // we can tell the app that it is covered by it.
2828 mSystemRight = mTmpNavigationFrame.left;
2829 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002830 }
Craig Mautner69b08182012-09-05 13:07:13 -07002831 // Make sure the content and current rectangles are updated to
2832 // account for the restrictions from the navigation bar.
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002833 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
2834 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
2835 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
2836 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002837 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
2838 // And compute the final frame.
2839 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
John Spurlock46646232013-09-30 22:32:42 -04002840 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf);
Craig Mautnereda67292013-04-28 13:50:14 -07002841 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
John Spurlock27735a42013-08-14 17:57:38 -04002842 if (mNavigationBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002843 updateSysUiVisibility = true;
2844 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002845 }
Craig Mautnereda67292013-04-28 13:50:14 -07002846 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07002847 mDockLeft, mDockTop, mDockRight, mDockBottom));
2848
2849 // decide where the status bar goes ahead of time
2850 if (mStatusBar != null) {
2851 // apply any navigation bar insets
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002852 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
2853 pf.top = df.top = of.top = mUnrestrictedScreenTop;
2854 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
2855 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
2856 + mUnrestrictedScreenTop;
Craig Mautner69b08182012-09-05 13:07:13 -07002857 vf.left = mStableLeft;
2858 vf.top = mStableTop;
2859 vf.right = mStableRight;
2860 vf.bottom = mStableBottom;
2861
2862 mStatusBarLayer = mStatusBar.getSurfaceLayer();
2863
2864 // Let the status bar determine its size.
John Spurlock46646232013-09-30 22:32:42 -04002865 mStatusBar.computeFrameLw(pf, df, vf, vf, vf, dcf);
Craig Mautner69b08182012-09-05 13:07:13 -07002866
2867 // For layout, the status bar is always at the top with our fixed height.
2868 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
2869
John Spurlocke1f366f2013-08-05 12:22:40 -04002870 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
Adrian Roosea562512014-05-05 13:33:03 +02002871 boolean statusBarTranslucent = (sysui
2872 & (View.STATUS_BAR_TRANSLUCENT | View.SYSTEM_UI_TRANSPARENT)) != 0;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04002873 statusBarTranslucent &= areTranslucentBarsAllowed();
John Spurlock32beb2c2013-03-11 10:16:47 -04002874
Craig Mautner69b08182012-09-05 13:07:13 -07002875 // If the status bar is hidden, we don't want to cause
2876 // windows behind it to scroll.
John Spurlockeda1f692013-09-16 11:38:44 -04002877 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
Craig Mautner69b08182012-09-05 13:07:13 -07002878 // Status bar may go away, so the screen area it occupies
2879 // is available to apps but just covering them when the
2880 // status bar is visible.
2881 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
2882
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002883 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
2884 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
2885 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
2886 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
Craig Mautner69b08182012-09-05 13:07:13 -07002887
Craig Mautnereda67292013-04-28 13:50:14 -07002888 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
Craig Mautner69b08182012-09-05 13:07:13 -07002889 String.format(
2890 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
2891 mDockLeft, mDockTop, mDockRight, mDockBottom,
2892 mContentLeft, mContentTop, mContentRight, mContentBottom,
2893 mCurLeft, mCurTop, mCurRight, mCurBottom));
2894 }
John Spurlocke1f366f2013-08-05 12:22:40 -04002895 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
John Spurlockbd957402013-10-03 11:38:39 -04002896 && !statusBarTransient && !statusBarTranslucent
2897 && !mStatusBarController.wasRecentlyTranslucent()) {
John Spurlocke1f366f2013-08-05 12:22:40 -04002898 // If the opaque status bar is currently requested to be visible,
Craig Mautner69b08182012-09-05 13:07:13 -07002899 // and not in the process of animating on or off, then
2900 // we can tell the app that it is covered by it.
2901 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
2902 }
John Spurlock27735a42013-08-14 17:57:38 -04002903 if (mStatusBarController.checkHiddenLw()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04002904 updateSysUiVisibility = true;
John Spurlock32beb2c2013-03-11 10:16:47 -04002905 }
Dianne Hackborn5c58de32012-04-28 19:52:37 -07002906 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04002907 if (updateSysUiVisibility) {
2908 updateSystemUiVisibilityLw();
2909 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002910 }
2911 }
2912
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002913 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002914 @Override
John Spurlock46646232013-09-30 22:32:42 -04002915 public int getSystemDecorLayerLw() {
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07002916 if (mStatusBar != null) return mStatusBar.getSurfaceLayer();
2917 if (mNavigationBar != null) return mNavigationBar.getSurfaceLayer();
2918 return 0;
2919 }
2920
Craig Mautner967212c2013-04-13 21:10:58 -07002921 @Override
2922 public void getContentRectLw(Rect r) {
2923 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
2924 }
2925
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002926 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
2927 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002928 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
2929 // Here's a special case: if this attached window is a panel that is
2930 // above the dock window, and the window it is attached to is below
2931 // the dock window, then the frames we computed for the window it is
2932 // attached to can not be used because the dock is effectively part
2933 // of the underlying window and the attached window is floating on top
2934 // of the whole thing. So, we ignore the attached window and explicitly
2935 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002936 df.left = of.left = cf.left = vf.left = mDockLeft;
2937 df.top = of.top = cf.top = vf.top = mDockTop;
2938 df.right = of.right = cf.right = vf.right = mDockRight;
2939 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002940 } else {
2941 // The effective display frame of the attached window depends on
2942 // whether it is taking care of insetting its content. If not,
2943 // we need to use the parent's content frame so that the entire
2944 // window is positioned within that content. Otherwise we can use
2945 // the display frame and let the attached window take care of
2946 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07002947 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002948 cf.set(attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002949 } else {
2950 // If the window is resizing, then we want to base the content
2951 // frame on our attached content frame to resize... however,
2952 // things can be tricky if the attached window is NOT in resize
2953 // mode, in which case its content frame will be larger.
2954 // Ungh. So to deal with that, make sure the content frame
2955 // we end up using is not covering the IM dock.
2956 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002957 if (attached.isVoiceInteraction()) {
2958 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
2959 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
2960 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
2961 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
2962 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002963 if (cf.left < mContentLeft) cf.left = mContentLeft;
2964 if (cf.top < mContentTop) cf.top = mContentTop;
2965 if (cf.right > mContentRight) cf.right = mContentRight;
2966 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
2967 }
2968 }
2969 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08002970 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002971 vf.set(attached.getVisibleFrameLw());
2972 }
2973 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
2974 // window should be positioned relative to its parent or the entire
2975 // screen.
2976 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
2977 ? attached.getFrameLw() : df);
2978 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07002979
2980 private void applyStableConstraints(int sysui, int fl, Rect r) {
2981 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
2982 // If app is requesting a stable layout, don't let the
2983 // content insets go below the stable values.
2984 if ((fl & FLAG_FULLSCREEN) != 0) {
2985 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
2986 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
2987 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
2988 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
2989 } else {
2990 if (r.left < mStableLeft) r.left = mStableLeft;
2991 if (r.top < mStableTop) r.top = mStableTop;
2992 if (r.right > mStableRight) r.right = mStableRight;
2993 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
2994 }
2995 }
2996 }
2997
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002998 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07002999 @Override
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003000 public void layoutWindowLw(WindowState win, WindowManager.LayoutParams attrs,
3001 WindowState attached) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003002 // we've already done the status bar
Dianne Hackborn1f903c32011-09-13 19:18:06 -07003003 if (win == mStatusBar || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003004 return;
3005 }
Craig Mautner69b08182012-09-05 13:07:13 -07003006 final boolean isDefaultDisplay = win.isDefaultDisplay();
3007 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003008 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3009 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003010 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003011 offsetInputMethodWindowLw(mLastInputMethodWindow);
3012 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003013
John Spurlockc6d1c602014-01-17 15:22:06 -05003014 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003015 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003016 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003017
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003018 final Rect pf = mTmpParentFrame;
3019 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003020 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003021 final Rect cf = mTmpContentFrame;
3022 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003023 final Rect dcf = mTmpDecorFrame;
3024 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07003025
3026 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04003027 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003028
Craig Mautnerf683b562012-10-02 11:10:57 -07003029 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
3030
Craig Mautner69b08182012-09-05 13:07:13 -07003031 if (!isDefaultDisplay) {
3032 if (attached != null) {
3033 // If this window is attached to another, our display
3034 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003035 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07003036 } else {
3037 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003038 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3039 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3040 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003041 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003042 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003043 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07003044 }
3045 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003046 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
3047 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
3048 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04003049 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04003050 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04003051 // ...with content insets above the nav bar
3052 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003053 // IM dock windows always go to the bottom of the screen.
3054 attrs.gravity = Gravity.BOTTOM;
3055 mDockLayer = win.getSurfaceLayer();
3056 } else {
John Spurlock46646232013-09-30 22:32:42 -04003057
3058 // Default policy decor for the default display
3059 dcf.left = mSystemLeft;
3060 dcf.top = mSystemTop;
3061 dcf.right = mSystemRight;
3062 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04003063 final boolean inheritTranslucentDecor = (attrs.privateFlags
3064 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04003065 final boolean isAppWindow =
3066 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
3067 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
3068 final boolean topAtRest =
3069 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
3070 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04003071 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
3072 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003073 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
3074 && (fl & WindowManager.LayoutParams.
3075 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003076 // Ensure policy decor includes status bar
3077 dcf.top = mStableTop;
3078 }
John Spurlockbd957402013-10-03 11:38:39 -04003079 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02003080 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
3081 && (fl & WindowManager.LayoutParams.
3082 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04003083 // Ensure policy decor includes navigation bar
3084 dcf.bottom = mStableBottom;
3085 dcf.right = mStableRight;
3086 }
3087 }
3088
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003089 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
3090 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07003091 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003092 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003093 // This is the case for a normal activity window: we want it
3094 // to cover all of the screen space, and it can take care of
3095 // moving its contents to account for screen decorations that
3096 // intrude into that space.
3097 if (attached != null) {
3098 // If this window is attached to another, our display
3099 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003100 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003101 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003102 if (attrs.type == TYPE_STATUS_BAR_PANEL
3103 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08003104 // Status bar panels are the only windows who can go on top of
3105 // the status bar. They are protected by the STATUS_BAR_SERVICE
3106 // permission, so they have the same privileges as the status
3107 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003108 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003109 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003110
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003111 pf.left = df.left = of.left = hasNavBar
3112 ? mDockLeft : mUnrestrictedScreenLeft;
3113 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3114 pf.right = df.right = of.right = hasNavBar
3115 ? mRestrictedScreenLeft+mRestrictedScreenWidth
3116 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3117 pf.bottom = df.bottom = of.bottom = hasNavBar
3118 ? mRestrictedScreenTop+mRestrictedScreenHeight
3119 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003120
Craig Mautnereda67292013-04-28 13:50:14 -07003121 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003122 "Laying out status bar window: (%d,%d - %d,%d)",
3123 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04003124 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003125 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3126 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3127 // Asking to layout into the overscan region, so give it that pure
3128 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003129 pf.left = df.left = of.left = mOverscanScreenLeft;
3130 pf.top = df.top = of.top = mOverscanScreenTop;
3131 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
3132 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
3133 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003134 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003135 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003136 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3137 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003138 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08003139 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003140 // only do this for application windows to ensure no window that
3141 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08003142 pf.left = df.left = mOverscanScreenLeft;
3143 pf.top = df.top = mOverscanScreenTop;
3144 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
3145 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003146 // We need to tell the app about where the frame inside the overscan
3147 // is, so it can inset its content by that amount -- it didn't ask
3148 // to actually extend itself into the overscan region.
3149 of.left = mUnrestrictedScreenLeft;
3150 of.top = mUnrestrictedScreenTop;
3151 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3152 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003153 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08003154 pf.left = df.left = mRestrictedOverscanScreenLeft;
3155 pf.top = df.top = mRestrictedOverscanScreenTop;
3156 pf.right = df.right = mRestrictedOverscanScreenLeft
3157 + mRestrictedOverscanScreenWidth;
3158 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
3159 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003160 // We need to tell the app about where the frame inside the overscan
3161 // is, so it can inset its content by that amount -- it didn't ask
3162 // to actually extend itself into the overscan region.
3163 of.left = mUnrestrictedScreenLeft;
3164 of.top = mUnrestrictedScreenTop;
3165 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3166 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003167 }
Craig Mautner69b08182012-09-05 13:07:13 -07003168
John Spurlock46646232013-09-30 22:32:42 -04003169 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003170 if (win.isVoiceInteraction()) {
3171 cf.left = mVoiceContentLeft;
3172 cf.top = mVoiceContentTop;
3173 cf.right = mVoiceContentRight;
3174 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003175 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003176 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
3177 cf.left = mDockLeft;
3178 cf.top = mDockTop;
3179 cf.right = mDockRight;
3180 cf.bottom = mDockBottom;
3181 } else {
3182 cf.left = mContentLeft;
3183 cf.top = mContentTop;
3184 cf.right = mContentRight;
3185 cf.bottom = mContentBottom;
3186 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003187 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003188 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003189 // Full screen windows are always given a layout that is as if the
3190 // status bar and other transient decors are gone. This is to avoid
3191 // bad states when moving from a window that is not hding the
3192 // status bar to one that is.
3193 cf.left = mRestrictedScreenLeft;
3194 cf.top = mRestrictedScreenTop;
3195 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
3196 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003197 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003198 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003199 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3200 vf.left = mCurLeft;
3201 vf.top = mCurTop;
3202 vf.right = mCurRight;
3203 vf.bottom = mCurBottom;
3204 } else {
3205 vf.set(cf);
3206 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003207 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003208 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
3209 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
3210 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07003211 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3212 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003213 // A window that has requested to fill the entire screen just
3214 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003215 if (attrs.type == TYPE_STATUS_BAR_PANEL
3216 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003217 pf.left = df.left = of.left = cf.left = hasNavBar
3218 ? mDockLeft : mUnrestrictedScreenLeft;
3219 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3220 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003221 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08003222 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003223 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003224 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003225 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003226 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04003227 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
3228 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07003229 } else if (attrs.type == TYPE_NAVIGATION_BAR
3230 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003231 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003232 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3233 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3234 pf.right = df.right = of.right = mUnrestrictedScreenLeft
3235 + mUnrestrictedScreenWidth;
3236 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
3237 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07003238 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04003239 "Laying out navigation bar window: (%d,%d - %d,%d)",
3240 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08003241 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
3242 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07003243 && ((fl & FLAG_FULLSCREEN) != 0)) {
3244 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003245 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3246 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3247 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3248 + mOverscanScreenWidth;
3249 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3250 + mOverscanScreenHeight;
Dianne Hackborna4b7f2f2012-05-21 11:28:41 -07003251 } else if (attrs.type == TYPE_BOOT_PROGRESS
3252 || attrs.type == TYPE_UNIVERSE_BACKGROUND) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08003253 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003254 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3255 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3256 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
3257 + mOverscanScreenWidth;
3258 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
3259 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04003260 } else if (attrs.type == TYPE_WALLPAPER) {
3261 // The wallpaper also has Real Ultimate Power.
3262 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3263 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003264 pf.right = df.right = of.right = cf.right
John Spurlockef4adae2013-08-26 17:58:58 -04003265 = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003266 pf.bottom = df.bottom = of.bottom = cf.bottom
John Spurlockef4adae2013-08-26 17:58:58 -04003267 = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04003268 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08003269 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3270 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
3271 // Asking to layout into the overscan region, so give it that pure
3272 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003273 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
3274 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
3275 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08003276 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003277 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003278 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003279 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003280 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
John Spurlock34e13d92013-08-10 06:52:28 -04003281 && (attrs.type == TYPE_TOAST
3282 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
3283 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003284 // Asking for layout as if the nav bar is hidden, lets the
3285 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04003286 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003287 // can be above the nav bar can do this.
3288 // XXX This assumes that an app asking for this will also
3289 // ask for layout in only content. We can't currently figure out
3290 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003291 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
3292 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
3293 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
3294 + mUnrestrictedScreenWidth;
3295 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
3296 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003297 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003298 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3299 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3300 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3301 + mRestrictedScreenWidth;
3302 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3303 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08003304 }
Craig Mautner69b08182012-09-05 13:07:13 -07003305
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003306 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07003307
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003308 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3309 vf.left = mCurLeft;
3310 vf.top = mCurTop;
3311 vf.right = mCurRight;
3312 vf.bottom = mCurBottom;
3313 } else {
3314 vf.set(cf);
3315 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003316 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003317 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3318 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003319 // A child window should be placed inside of the same visible
3320 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003321 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003322 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003323 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
3324 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003325 // Otherwise, a normal window must be placed inside the content
3326 // of all screen decorations.
Dianne Hackborna239c842011-06-01 12:28:20 -07003327 if (attrs.type == TYPE_STATUS_BAR_PANEL) {
3328 // Status bar panels are the only windows who can go on top of
3329 // the status bar. They are protected by the STATUS_BAR_SERVICE
3330 // permission, so they have the same privileges as the status
3331 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003332 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
3333 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
3334 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
3335 + mRestrictedScreenWidth;
3336 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
3337 + mRestrictedScreenHeight;
John Spurlock414c1f02013-12-04 13:47:36 -05003338 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT
3339 || attrs.type == TYPE_VOLUME_OVERLAY) {
3340 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04003341 pf.left = df.left = of.left = cf.left = mStableLeft;
3342 pf.top = df.top = of.top = cf.top = mStableTop;
3343 pf.right = df.right = of.right = cf.right = mStableRight;
3344 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003345 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07003346 pf.left = mContentLeft;
3347 pf.top = mContentTop;
3348 pf.right = mContentRight;
3349 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07003350 if (win.isVoiceInteraction()) {
3351 df.left = of.left = cf.left = mVoiceContentLeft;
3352 df.top = of.top = cf.top = mVoiceContentTop;
3353 df.right = of.right = cf.right = mVoiceContentRight;
3354 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
3355 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003356 df.left = of.left = cf.left = mDockLeft;
3357 df.top = of.top = cf.top = mDockTop;
3358 df.right = of.right = cf.right = mDockRight;
3359 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003360 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003361 df.left = of.left = cf.left = mContentLeft;
3362 df.top = of.top = cf.top = mContentTop;
3363 df.right = of.right = cf.right = mContentRight;
3364 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07003365 }
3366 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
3367 vf.left = mCurLeft;
3368 vf.top = mCurTop;
3369 vf.right = mCurRight;
3370 vf.bottom = mCurBottom;
3371 } else {
3372 vf.set(cf);
3373 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003374 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003375 }
3376 }
Craig Mautner69b08182012-09-05 13:07:13 -07003377
Craig Mautnerb816bed2013-07-23 10:26:17 -07003378 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
3379 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003380 df.left = df.top = of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
3381 df.right = df.bottom = of.right = of.bottom = cf.right = cf.bottom
3382 = vf.right = vf.bottom = 10000;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003383 }
3384
Craig Mautnereda67292013-04-28 13:50:14 -07003385 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07003386 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07003387 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003388 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07003389 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003390 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04003391 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
3392 + " dcf=" + dcf.toShortString());
Craig Mautner69b08182012-09-05 13:07:13 -07003393
John Spurlock46646232013-09-30 22:32:42 -04003394 win.computeFrameLw(pf, df, of, cf, vf, dcf);
Craig Mautner69b08182012-09-05 13:07:13 -07003395
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003396 // Dock windows carve out the bottom of the screen, so normal windows
3397 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07003398 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
3399 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09003400 setLastInputMethodWindowLw(null, null);
3401 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003402 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003403 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
3404 && !win.getGivenInsetsPendingLw()) {
3405 offsetVoiceInputWindowLw(win);
3406 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003407 }
3408
satok1bc0a492012-04-25 22:47:12 +09003409 private void offsetInputMethodWindowLw(WindowState win) {
3410 int top = win.getContentFrameLw().top;
3411 top += win.getGivenContentInsetsLw().top;
3412 if (mContentBottom > top) {
3413 mContentBottom = top;
3414 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003415 if (mVoiceContentBottom > top) {
3416 mVoiceContentBottom = top;
3417 }
satok1bc0a492012-04-25 22:47:12 +09003418 top = win.getVisibleFrameLw().top;
3419 top += win.getGivenVisibleInsetsLw().top;
3420 if (mCurBottom > top) {
3421 mCurBottom = top;
3422 }
Craig Mautnereda67292013-04-28 13:50:14 -07003423 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09003424 + mDockBottom + " mContentBottom="
3425 + mContentBottom + " mCurBottom=" + mCurBottom);
3426 }
3427
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003428 private void offsetVoiceInputWindowLw(WindowState win) {
3429 final int gravity = win.getAttrs().gravity;
3430 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3431 << Gravity.AXIS_X_SHIFT)) {
3432 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_X_SHIFT: {
3433 int right = win.getContentFrameLw().right - win.getGivenContentInsetsLw().right;
3434 if (mVoiceContentLeft < right) {
3435 mVoiceContentLeft = right;
3436 }
3437 } break;
3438 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_X_SHIFT: {
3439 int left = win.getContentFrameLw().left - win.getGivenContentInsetsLw().left;
3440 if (mVoiceContentRight < left) {
3441 mVoiceContentRight = left;
3442 }
3443 } break;
3444 }
3445 switch (gravity&((Gravity.AXIS_PULL_BEFORE|Gravity.AXIS_PULL_AFTER)
3446 << Gravity.AXIS_Y_SHIFT)) {
3447 case Gravity.AXIS_PULL_BEFORE<<Gravity.AXIS_Y_SHIFT: {
3448 int bottom = win.getContentFrameLw().bottom - win.getGivenContentInsetsLw().bottom;
3449 if (mVoiceContentTop < bottom) {
3450 mVoiceContentTop = bottom;
3451 }
3452 } break;
3453 case Gravity.AXIS_PULL_AFTER<<Gravity.AXIS_Y_SHIFT: {
3454 int top = win.getContentFrameLw().top - win.getGivenContentInsetsLw().top;
3455 if (mVoiceContentBottom < top) {
3456 mVoiceContentBottom = top;
3457 }
3458 } break;
3459 }
3460 }
3461
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003462 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08003463 @Override
3464 public void finishLayoutLw() {
3465 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003466 }
3467
3468 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003469 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003470 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003471 mTopFullscreenOpaqueWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003472 mAppsToBeHidden.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003473 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003474 mForceStatusBarFromKeyguard = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003475 mForcingShowNavBar = false;
3476 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07003477
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003478 mHideLockScreen = false;
3479 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003480 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003481 mShowingLockscreen = false;
3482 mShowingDream = false;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003483 }
3484
3485 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003486 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003487 public void applyPostLayoutPolicyLw(WindowState win,
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003488 WindowManager.LayoutParams attrs) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003489 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
3490 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05003491 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05003492 if (mTopFullscreenOpaqueWindowState == null
3493 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
3494 mForcingShowNavBar = true;
3495 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08003496 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003497 if (attrs.type == TYPE_STATUS_BAR && (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Jorim Jaggiafd4a552014-04-08 15:13:05 +02003498 mForceStatusBarFromKeyguard = true;
3499 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003500 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08003501 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003502 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003503 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003504 mForceStatusBarFromKeyguard = true;
3505 } else {
3506 mForceStatusBar = true;
3507 }
3508 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003509 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003510 mShowingLockscreen = true;
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07003511 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003512 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003513 && attrs.type <= LAST_APPLICATION_WINDOW;
3514 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07003515 // If the lockscreen was showing when the dream started then wait
3516 // for the dream to draw before hiding the lockscreen.
3517 if (!mDreamingLockscreen
3518 || (win.isVisibleLw() && win.hasDrawnLw())) {
3519 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08003520 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003521 }
3522 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003523
Craig Mautner00156ec2014-03-06 22:29:02 -08003524 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
Craig Mautner74ee9382014-04-01 15:20:16 -07003525 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Craig Mautnerab55e522014-03-03 13:26:03 -08003526 if (appWindow) {
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003527 if (showWhenLocked || (dismissKeyguard && !isKeyguardSecure())) {
Craig Mautner2bc789b2014-03-19 19:48:38 -07003528 mAppsToBeHidden.remove(win.getAppToken());
3529 } else {
3530 mAppsToBeHidden.add(win.getAppToken());
3531 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003532 if (attrs.x == 0 && attrs.y == 0
3533 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
3534 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
3535 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
3536 mTopFullscreenOpaqueWindowState = win;
Craig Mautner2bc789b2014-03-19 19:48:38 -07003537 if (mAppsToBeHidden.isEmpty()) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003538 if (showWhenLocked) {
3539 if (DEBUG_LAYOUT) Slog.v(TAG,
3540 "Setting mHideLockScreen to true by win " + win);
3541 mHideLockScreen = true;
3542 mForceStatusBarFromKeyguard = false;
3543 }
Craig Mautner4bdab6b2014-04-01 12:05:11 -07003544 if (dismissKeyguard && mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
Craig Mautnerda09ae32014-03-03 13:26:03 -08003545 if (DEBUG_LAYOUT) Slog.v(TAG,
3546 "Setting mDismissKeyguard true by win " + win);
3547 mDismissKeyguard = mWinDismissingKeyguard == win ?
3548 DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
3549 mWinDismissingKeyguard = win;
3550 mForceStatusBarFromKeyguard = mShowingLockscreen && isKeyguardSecure();
3551 }
Craig Mautnerab55e522014-03-03 13:26:03 -08003552 }
Craig Mautner00156ec2014-03-06 22:29:02 -08003553 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08003554 mAllowLockscreenWhenOn = true;
3555 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08003556 }
3557 }
3558 }
3559 }
3560
3561 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07003562 @Override
Craig Mautner39834192012-09-02 07:47:24 -07003563 public int finishPostLayoutPolicyLw() {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003564 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04003565 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04003566
3567 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
3568 ? mTopFullscreenOpaqueWindowState.getAttrs()
3569 : null;
3570
Jeff Brownc8018eb2012-10-29 21:33:27 -07003571 // If we are not currently showing a dream then remember the current
3572 // lockscreen state. We will use this to determine whether the dream
3573 // started while the lockscreen was showing and remember this state
3574 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07003575 if (!mShowingDream) {
3576 mDreamingLockscreen = mShowingLockscreen;
3577 }
3578
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003579 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07003580 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003581 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07003582 + " top=" + mTopFullscreenOpaqueWindowState);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07003583 if (mForceStatusBar || mForceStatusBarFromKeyguard) {
Craig Mautnereda67292013-04-28 13:50:14 -07003584 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04003585 if (mStatusBarController.setBarShowingLw(true)) {
3586 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3587 }
Craig Mautner81defc72013-10-29 11:10:42 -07003588 // Maintain fullscreen layout until incoming animation is complete.
3589 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05003590 // Transient status bar on the lockscreen is not allowed
3591 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
3592 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
3593 mLastSystemUiFlags, mLastSystemUiFlags);
3594 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003595 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003596 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04003597 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07003598 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Joe Onorato93056472010-09-10 10:30:46 -04003599 + " shown frame: " + mTopFullscreenOpaqueWindowState.getShownFrameLw());
Craig Mautnereda67292013-04-28 13:50:14 -07003600 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05003601 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04003602 }
John Spurlockc6d1c602014-01-17 15:22:06 -05003603 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003604 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04003605 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
3606 // and mTopIsFullscreen is that that mTopIsFullscreen is set only if the window
3607 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
3608 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04003609 if (mStatusBarController.isTransientShowing()) {
3610 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04003611 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3612 }
3613 } else if (topIsFullscreen) {
Craig Mautnereda67292013-04-28 13:50:14 -07003614 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04003615 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003616 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07003617 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07003618 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04003619 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003620 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07003621 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04003622 if (mStatusBarController.setBarShowingLw(true)) {
3623 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3624 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003625 }
3626 }
3627 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003628
Craig Mautner81defc72013-10-29 11:10:42 -07003629 if (mTopIsFullscreen != topIsFullscreen) {
3630 if (!topIsFullscreen) {
3631 // Force another layout when status bar becomes fully shown.
3632 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3633 }
3634 mTopIsFullscreen = topIsFullscreen;
3635 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04003636
Craig Mautner39834192012-09-02 07:47:24 -07003637 // Hide the key guard if a visible window explicitly specifies that it wants to be
3638 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003639 if (mKeyguardDelegate != null && mStatusBar != null) {
3640 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
3641 + mHideLockScreen);
3642 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !isKeyguardSecure()) {
3643 mKeyguardHidden = true;
3644 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003645 changes |= FINISH_LAYOUT_REDO_LAYOUT
3646 | FINISH_LAYOUT_REDO_CONFIG
3647 | FINISH_LAYOUT_REDO_WALLPAPER;
3648 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003649 if (mKeyguardDelegate.isShowing()) {
3650 mHandler.post(new Runnable() {
3651 @Override
3652 public void run() {
3653 mKeyguardDelegate.keyguardDone(false, false);
3654 }
3655 });
3656 }
3657 } else if (mHideLockScreen) {
3658 mKeyguardHidden = true;
3659 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(true))) {
3660 changes |= FINISH_LAYOUT_REDO_LAYOUT
3661 | FINISH_LAYOUT_REDO_CONFIG
3662 | FINISH_LAYOUT_REDO_WALLPAPER;
3663 }
3664 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
3665 // This is the case of keyguard isSecure() and not mHideLockScreen.
3666 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
3667 // Only launch the next keyguard unlock window once per window.
3668 mKeyguardHidden = false;
3669 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3670 changes |= FINISH_LAYOUT_REDO_LAYOUT
3671 | FINISH_LAYOUT_REDO_CONFIG
3672 | FINISH_LAYOUT_REDO_WALLPAPER;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003673 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003674 mHandler.post(new Runnable() {
3675 @Override
3676 public void run() {
3677 mKeyguardDelegate.dismiss();
3678 }
3679 });
3680 }
3681 } else {
3682 mWinDismissingKeyguard = null;
3683 mKeyguardHidden = false;
3684 if (processKeyguardSetHiddenResultLw(mKeyguardDelegate.setOccluded(false))) {
3685 changes |= FINISH_LAYOUT_REDO_LAYOUT
3686 | FINISH_LAYOUT_REDO_CONFIG
3687 | FINISH_LAYOUT_REDO_WALLPAPER;
3688 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07003689 }
3690 }
Joe Onorato664644d2011-01-23 17:53:23 -08003691
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003692 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003693 // If the navigation bar has been hidden or shown, we need to do another
3694 // layout pass to update that window.
3695 changes |= FINISH_LAYOUT_REDO_LAYOUT;
3696 }
Joe Onorato664644d2011-01-23 17:53:23 -08003697
Mike Lockwood28569302010-01-28 11:54:40 -05003698 // update since mAllowLockscreenWhenOn might have changed
3699 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07003700 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003701 }
3702
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003703 /**
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003704 * Processes the result code of {@link IKeyguardService#setOccluded}. This is needed because we
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003705 * immediately need to put the wallpaper directly behind the Keyguard when a window with flag
3706 * {@link android.view.WindowManager.LayoutParams#FLAG_SHOW_WHEN_LOCKED} gets dismissed. If we
3707 * would wait for Keyguard to change the flags, that would be running asynchronously and thus be
3708 * too late so the user might see the window behind.
3709 *
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003710 * @param setHiddenResult The result code from {@link IKeyguardService#setOccluded}.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003711 * @return Whether the flags have changed and we have to redo the layout.
3712 */
3713 private boolean processKeyguardSetHiddenResultLw(int setHiddenResult) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003714 if (setHiddenResult
3715 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_SET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003716 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
3717 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
3718 return true;
3719 } else if (setHiddenResult
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003720 == IKeyguardServiceConstants.KEYGUARD_SERVICE_SET_OCCLUDED_RESULT_UNSET_FLAGS) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003721 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
3722 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
3723 return true;
3724 } else {
3725 return false;
3726 }
3727 }
3728
3729 private boolean isStatusBarKeyguard() {
3730 return mStatusBar != null
3731 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
3732 }
3733
Dianne Hackborn08743722009-12-21 12:16:51 -08003734 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01003735 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07003736 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08003737 return false;
3738 }
Dianne Hackborn08743722009-12-21 12:16:51 -08003739 return true;
3740 }
3741
Dianne Hackborndf89e652011-10-06 22:35:11 -07003742 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08003743 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003744 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003745 // If the navigation bar has been hidden or shown, we need to do another
3746 // layout pass to update that window.
3747 return FINISH_LAYOUT_REDO_LAYOUT;
3748 }
3749 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08003750 }
3751
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07003752 /** {@inheritDoc} */
Jeff Brown46b9ac02010-04-22 18:58:52 -07003753 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
3754 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07003755 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
3756 if (newLidState == mLidState) {
3757 return;
3758 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07003759
Jeff Brownc458ce92012-04-30 14:58:40 -07003760 mLidState = newLidState;
3761 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07003762 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07003763
3764 if (lidOpen) {
Jim Millere51cf7ae2013-06-25 18:31:56 -07003765 mPowerManager.wakeUp(SystemClock.uptimeMillis());
Jeff Brownc458ce92012-04-30 14:58:40 -07003766 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07003767 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07003768 }
3769 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003770
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003771 void setHdmiPlugged(boolean plugged) {
3772 if (mHdmiPlugged != plugged) {
3773 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003774 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003775 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08003776 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003777 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07003778 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08003779 }
3780 }
3781
Joe Onoratoea495d42011-04-06 11:41:11 -07003782 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07003783 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07003784 // watch for HDMI plug messages if the hdmi switch exists
3785 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
3786 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
3787
Joe Onoratoea495d42011-04-06 11:41:11 -07003788 final String filename = "/sys/class/switch/hdmi/state";
3789 FileReader reader = null;
3790 try {
3791 reader = new FileReader(filename);
3792 char[] buf = new char[15];
3793 int n = reader.read(buf);
3794 if (n > 1) {
3795 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
3796 }
3797 } catch (IOException ex) {
3798 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3799 } catch (NumberFormatException ex) {
3800 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
3801 } finally {
3802 if (reader != null) {
3803 try {
3804 reader.close();
3805 } catch (IOException ex) {
3806 }
Joe Onoratodc100302011-01-11 17:07:41 -08003807 }
3808 }
3809 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07003810 // This dance forces the code in setHdmiPlugged to run.
3811 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
3812 mHdmiPlugged = !plugged;
3813 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08003814 }
3815
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003816 /**
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003817 * @return Whether music is being played right now "locally" (e.g. on the device's speakers
3818 * or wired headphones) or "remotely" (e.g. on a device using the Cast protocol and
3819 * controlled by this device, or through remote submix).
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003820 */
3821 boolean isMusicActive() {
Eric Laurent413cb9d2009-07-17 11:52:43 -07003822 final AudioManager am = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
3823 if (am == null) {
3824 Log.w(TAG, "isMusicActive: couldn't get AudioManager reference");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003825 return false;
3826 }
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003827 return am.isLocalOrRemoteMusicActive();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003828 }
3829
3830 /**
3831 * Tell the audio service to adjust the volume appropriate to the event.
3832 * @param keycode
3833 */
Mike Lockwooda53e3812009-09-25 10:51:39 -04003834 void handleVolumeKey(int stream, int keycode) {
Jeff Brown4d396052010-10-29 21:50:21 -07003835 IAudioService audioService = getAudioService();
3836 if (audioService == null) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003837 return;
3838 }
3839 try {
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003840 // when audio is playing locally, we shouldn't have to hold a wake lock
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003841 // during the call, but we do it as a precaution for the rare possibility
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003842 // that the music stops right before we call this.
3843 // Otherwise we might also be in a remote playback case.
Jeff Brownb0418da2010-11-01 15:24:01 -07003844 // TODO: Actually handle MUTE.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003845 mBroadcastWakeLock.acquire();
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003846 if (stream == AudioSystem.STREAM_MUSIC) {
3847 audioService.adjustLocalOrRemoteStreamVolume(stream,
3848 keycode == KeyEvent.KEYCODE_VOLUME_UP
3849 ? AudioManager.ADJUST_RAISE
3850 : AudioManager.ADJUST_LOWER,
3851 mContext.getOpPackageName());
3852 } else {
3853 audioService.adjustStreamVolume(stream,
3854 keycode == KeyEvent.KEYCODE_VOLUME_UP
3855 ? AudioManager.ADJUST_RAISE
3856 : AudioManager.ADJUST_LOWER,
3857 0,
3858 mContext.getOpPackageName());
3859 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003860 } catch (RemoteException e) {
Jean-Michel Trivifca1e602013-10-10 18:12:59 -07003861 Log.w(TAG, "IAudioService.adjust*StreamVolume() threw RemoteException " + e);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003862 } finally {
3863 mBroadcastWakeLock.release();
3864 }
3865 }
Jeff Brown4d396052010-10-29 21:50:21 -07003866
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07003867 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003868 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003869
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003870 final Runnable mScreenshotTimeout = new Runnable() {
3871 @Override public void run() {
3872 synchronized (mScreenshotLock) {
3873 if (mScreenshotConnection != null) {
3874 mContext.unbindService(mScreenshotConnection);
3875 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07003876 }
Winson Chung9112ec32011-06-27 13:15:32 -07003877 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003878 }
3879 };
3880
3881 // Assume this is called from the Handler thread.
3882 private void takeScreenshot() {
3883 synchronized (mScreenshotLock) {
3884 if (mScreenshotConnection != null) {
3885 return;
3886 }
3887 ComponentName cn = new ComponentName("com.android.systemui",
3888 "com.android.systemui.screenshot.TakeScreenshotService");
3889 Intent intent = new Intent();
3890 intent.setComponent(cn);
3891 ServiceConnection conn = new ServiceConnection() {
3892 @Override
3893 public void onServiceConnected(ComponentName name, IBinder service) {
3894 synchronized (mScreenshotLock) {
3895 if (mScreenshotConnection != this) {
3896 return;
3897 }
3898 Messenger messenger = new Messenger(service);
3899 Message msg = Message.obtain(null, 1);
3900 final ServiceConnection myConn = this;
3901 Handler h = new Handler(mHandler.getLooper()) {
3902 @Override
3903 public void handleMessage(Message msg) {
3904 synchronized (mScreenshotLock) {
3905 if (mScreenshotConnection == myConn) {
3906 mContext.unbindService(mScreenshotConnection);
3907 mScreenshotConnection = null;
3908 mHandler.removeCallbacks(mScreenshotTimeout);
3909 }
3910 }
3911 }
3912 };
3913 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07003914 msg.arg1 = msg.arg2 = 0;
3915 if (mStatusBar != null && mStatusBar.isVisibleLw())
3916 msg.arg1 = 1;
3917 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
3918 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003919 try {
3920 messenger.send(msg);
3921 } catch (RemoteException e) {
3922 }
3923 }
3924 }
3925 @Override
3926 public void onServiceDisconnected(ComponentName name) {}
3927 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08003928 if (mContext.bindServiceAsUser(
3929 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003930 mScreenshotConnection = conn;
3931 mHandler.postDelayed(mScreenshotTimeout, 10000);
3932 }
3933 }
Winson Chung9112ec32011-06-27 13:15:32 -07003934 }
3935
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003936 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003937 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07003938 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07003939 if (!mSystemBooted) {
3940 // If we have not yet booted, don't let key events do anything.
3941 return 0;
3942 }
3943
Jeff Brown037c33e2014-04-09 00:31:55 -07003944 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08003945 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
3946 final boolean canceled = event.isCanceled();
3947 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07003948
Jeff Brown3122e442010-10-11 23:32:49 -07003949 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07003950
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05003951 // If screen is off then we treat the case where the keyguard is open but hidden
3952 // the same as if it were open and in front.
3953 // This will prevent any keys other than the power button from waking the screen
3954 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08003955 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07003956 (interactive ?
Jorim Jaggi5cf17872014-03-26 18:31:48 +01003957 mKeyguardDelegate.isShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08003958 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003959
Jeff Brown40013652012-05-16 21:22:36 -07003960 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07003961 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07003962 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08003963 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003964 }
3965
Jeff Brown98392ef2011-09-12 18:24:59 -07003966 if (down && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
3967 && event.getRepeatCount() == 0) {
Jeff Brown4d396052010-10-29 21:50:21 -07003968 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
3969 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003970
Jeff Brown037c33e2014-04-09 00:31:55 -07003971 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07003972 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07003973 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
3974 || event.isWakeKey();
Jeff Brown037c33e2014-04-09 00:31:55 -07003975 if (interactive || (isInjected && !isWakeKey)) {
Jeff Brown4d396052010-10-29 21:50:21 -07003976 // When the screen is on or if the key is injected pass the key to the application.
3977 result = ACTION_PASS_TO_USER;
3978 } else {
3979 // When the screen is off and the key is not injected, determine whether
3980 // to wake the device but don't pass the key to the application.
3981 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08003982 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
3983 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003984 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003985 }
3986
Justin Kohd378ad72013-04-01 12:18:26 -07003987 // If the key would be handled globally, just return the result, don't worry about special
3988 // key processing.
3989 if (mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
3990 return result;
3991 }
3992
Jeff Brown4d396052010-10-29 21:50:21 -07003993 // Handle special keys.
3994 switch (keyCode) {
3995 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07003996 case KeyEvent.KEYCODE_VOLUME_UP:
3997 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003998 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
3999 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004000 if (interactive && !mVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004001 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4002 mVolumeDownKeyTriggered = true;
4003 mVolumeDownKeyTime = event.getDownTime();
4004 mVolumeDownKeyConsumedByScreenshotChord = false;
4005 cancelPendingPowerKeyAction();
4006 interceptScreenshotChord();
4007 }
4008 } else {
4009 mVolumeDownKeyTriggered = false;
4010 cancelPendingScreenshotChordAction();
4011 }
4012 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
4013 if (down) {
Jeff Brown037c33e2014-04-09 00:31:55 -07004014 if (interactive && !mVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004015 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4016 mVolumeUpKeyTriggered = true;
4017 cancelPendingPowerKeyAction();
4018 cancelPendingScreenshotChordAction();
4019 }
4020 } else {
4021 mVolumeUpKeyTriggered = false;
4022 cancelPendingScreenshotChordAction();
4023 }
4024 }
Jeff Brown4d396052010-10-29 21:50:21 -07004025 if (down) {
Santos Cordon3afed572014-05-21 15:22:12 -07004026 TelephonyManager telephonyManager = getTelephonyService();
4027 if (telephonyManager != null) {
4028 if (telephonyManager.isRinging()) {
4029 // If an incoming call is ringing, either VOLUME key means
4030 // "silence ringer". We handle these keys here, rather than
4031 // in the InCallScreen, to make sure we'll respond to them
4032 // even if the InCallScreen hasn't come to the foreground yet.
4033 // Look for the DOWN event here, to agree with the "fallback"
4034 // behavior in the InCallScreen.
4035 Log.i(TAG, "interceptKeyBeforeQueueing:"
4036 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07004037
Santos Cordon3afed572014-05-21 15:22:12 -07004038 // Silence the ringer. (It's safe to call this
4039 // even if the ringer has already been silenced.)
4040 telephonyManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07004041
Santos Cordon3afed572014-05-21 15:22:12 -07004042 // And *don't* pass this key thru to the current activity
4043 // (which is probably the InCallScreen.)
4044 result &= ~ACTION_PASS_TO_USER;
4045 break;
4046 }
4047 if (telephonyManager.isOffhook()
4048 && (result & ACTION_PASS_TO_USER) == 0) {
4049 // If we are in call but we decided not to pass the key to
4050 // the application, handle the volume change here.
4051 handleVolumeKey(AudioManager.STREAM_VOICE_CALL, keyCode);
4052 break;
Jeff Brown4d396052010-10-29 21:50:21 -07004053 }
4054 }
4055
4056 if (isMusicActive() && (result & ACTION_PASS_TO_USER) == 0) {
4057 // If music is playing but we decided not to pass the key to the
4058 // application, handle the volume change here.
4059 handleVolumeKey(AudioManager.STREAM_MUSIC, keyCode);
4060 break;
4061 }
4062 }
4063 break;
4064 }
4065
4066 case KeyEvent.KEYCODE_ENDCALL: {
4067 result &= ~ACTION_PASS_TO_USER;
4068 if (down) {
Santos Cordon3afed572014-05-21 15:22:12 -07004069 TelephonyManager telephonyManager = getTelephonyService();
Jeff Brown4d396052010-10-29 21:50:21 -07004070 boolean hungUp = false;
Santos Cordon3afed572014-05-21 15:22:12 -07004071 if (telephonyManager != null) {
4072 hungUp = telephonyManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004073 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004074 interceptPowerKeyDown(!interactive || hungUp);
Jeff Brown4d396052010-10-29 21:50:21 -07004075 } else {
4076 if (interceptPowerKeyUp(canceled)) {
4077 if ((mEndcallBehavior
4078 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
4079 if (goHome()) {
4080 break;
Dianne Hackborn0041e972009-07-24 17:14:43 -07004081 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004082 }
Jeff Brown4d396052010-10-29 21:50:21 -07004083 if ((mEndcallBehavior
4084 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
Jeff Brown26875502014-01-30 21:47:47 -08004085 mPowerManager.goToSleep(event.getEventTime());
4086 isWakeKey = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004087 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004088 }
Jeff Brown4d396052010-10-29 21:50:21 -07004089 }
4090 break;
4091 }
4092
4093 case KeyEvent.KEYCODE_POWER: {
4094 result &= ~ACTION_PASS_TO_USER;
4095 if (down) {
Jeff Brown26c6a502014-04-11 02:15:54 -07004096 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
John Spurlockd9b70bd2014-02-06 17:02:44 -05004097 event.getDownTime(), isImmersiveMode(mLastSystemUiFlags));
4098 if (panic) {
4099 mHandler.post(mRequestTransientNav);
4100 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004101 if (interactive && !mPowerKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004102 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
4103 mPowerKeyTriggered = true;
4104 mPowerKeyTime = event.getDownTime();
4105 interceptScreenshotChord();
Winson Chung9112ec32011-06-27 13:15:32 -07004106 }
Winson Chung9112ec32011-06-27 13:15:32 -07004107
Santos Cordon3afed572014-05-21 15:22:12 -07004108 TelephonyManager telephonyManager = getTelephonyService();
Jeff Brown4d396052010-10-29 21:50:21 -07004109 boolean hungUp = false;
Santos Cordon3afed572014-05-21 15:22:12 -07004110 if (telephonyManager != null) {
4111 if (telephonyManager.isRinging()) {
4112 // Pressing Power while there's a ringing incoming
4113 // call should silence the ringer.
4114 telephonyManager.silenceRinger();
4115 } else if ((mIncallPowerBehavior
4116 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
4117 && telephonyManager.isOffhook() && interactive) {
4118 // Otherwise, if "Power button ends call" is enabled,
4119 // the Power button will hang up any current active call.
4120 hungUp = telephonyManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07004121 }
4122 }
Jeff Brown037c33e2014-04-09 00:31:55 -07004123 interceptPowerKeyDown(!interactive || hungUp
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004124 || mVolumeDownKeyTriggered || mVolumeUpKeyTriggered);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004125 } else {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004126 mPowerKeyTriggered = false;
4127 cancelPendingScreenshotChordAction();
4128 if (interceptPowerKeyUp(canceled || mPendingPowerKeyUpCanceled)) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07004129 powerShortPress(event.getEventTime());
Jeff Brown26875502014-01-30 21:47:47 -08004130 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004131 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004132 mPendingPowerKeyUpCanceled = false;
Jeff Brown4d396052010-10-29 21:50:21 -07004133 }
4134 break;
4135 }
4136
Jeff Brown6212a492014-03-07 13:58:47 -08004137 case KeyEvent.KEYCODE_SLEEP: {
4138 result &= ~ACTION_PASS_TO_USER;
4139 mPowerManager.goToSleep(event.getEventTime());
4140 isWakeKey = false;
4141 break;
4142 }
4143
4144 case KeyEvent.KEYCODE_WAKEUP: {
4145 result &= ~ACTION_PASS_TO_USER;
4146 break;
4147 }
4148
Jeff Brown4d396052010-10-29 21:50:21 -07004149 case KeyEvent.KEYCODE_MEDIA_PLAY:
4150 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4151 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4152 if (down) {
Santos Cordon3afed572014-05-21 15:22:12 -07004153 TelephonyManager telephonyManager = getTelephonyService();
4154 if (telephonyManager != null) {
4155 if (!telephonyManager.isIdle()) {
4156 // Suppress PLAY/PAUSE toggle when phone is ringing or in-call
4157 // to avoid music playback.
4158 break;
Jeff Brown3122e442010-10-11 23:32:49 -07004159 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004160 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004161 }
Jeff Brown4d396052010-10-29 21:50:21 -07004162 case KeyEvent.KEYCODE_HEADSETHOOK:
4163 case KeyEvent.KEYCODE_MUTE:
4164 case KeyEvent.KEYCODE_MEDIA_STOP:
4165 case KeyEvent.KEYCODE_MEDIA_NEXT:
4166 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4167 case KeyEvent.KEYCODE_MEDIA_REWIND:
4168 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004169 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
4170 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
Jeff Brown4d396052010-10-29 21:50:21 -07004171 if ((result & ACTION_PASS_TO_USER) == 0) {
4172 // Only do this if we would otherwise not pass it to the user. In that
4173 // case, the PhoneWindow class will do the same thing, except it will
4174 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07004175 // Note that we need to make a copy of the key event here because the
4176 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07004177 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07004178 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
4179 new KeyEvent(event));
4180 msg.setAsynchronous(true);
4181 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07004182 }
4183 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004184 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004185
Jeff Brown4d396052010-10-29 21:50:21 -07004186 case KeyEvent.KEYCODE_CALL: {
4187 if (down) {
Santos Cordon3afed572014-05-21 15:22:12 -07004188 TelephonyManager telephonyManager = getTelephonyService();
4189 if (telephonyManager != null) {
4190 if (telephonyManager.isRinging()) {
4191 Log.i(TAG, "interceptKeyBeforeQueueing:"
4192 + " CALL key-down while ringing: Answer the call!");
4193 telephonyManager.answerRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004194
Santos Cordon3afed572014-05-21 15:22:12 -07004195 // And *don't* pass this key thru to the current activity
4196 // (which is presumably the InCallScreen.)
4197 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004198 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004199 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07004200 }
Jeff Brown4d396052010-10-29 21:50:21 -07004201 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004202 }
4203 }
Jeff Brown26875502014-01-30 21:47:47 -08004204
4205 if (isWakeKey) {
4206 mPowerManager.wakeUp(event.getEventTime());
4207 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004208 return result;
4209 }
4210
Jeff Brown1c2e4942012-11-06 16:32:01 -08004211 /**
4212 * When the screen is off we ignore some keys that might otherwise typically
4213 * be considered wake keys. We filter them out here.
4214 *
4215 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
4216 * is always considered a wake key.
4217 */
4218 private boolean isWakeKeyWhenScreenOff(int keyCode) {
4219 switch (keyCode) {
4220 // ignore volume keys unless docked
4221 case KeyEvent.KEYCODE_VOLUME_UP:
4222 case KeyEvent.KEYCODE_VOLUME_DOWN:
4223 case KeyEvent.KEYCODE_VOLUME_MUTE:
4224 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
4225
4226 // ignore media and camera keys
4227 case KeyEvent.KEYCODE_MUTE:
4228 case KeyEvent.KEYCODE_HEADSETHOOK:
4229 case KeyEvent.KEYCODE_MEDIA_PLAY:
4230 case KeyEvent.KEYCODE_MEDIA_PAUSE:
4231 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
4232 case KeyEvent.KEYCODE_MEDIA_STOP:
4233 case KeyEvent.KEYCODE_MEDIA_NEXT:
4234 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
4235 case KeyEvent.KEYCODE_MEDIA_REWIND:
4236 case KeyEvent.KEYCODE_MEDIA_RECORD:
4237 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09004238 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08004239 case KeyEvent.KEYCODE_CAMERA:
4240 return false;
4241 }
4242 return true;
4243 }
4244
4245
Jeff Brown56194eb2011-03-02 19:23:13 -08004246 /** {@inheritDoc} */
4247 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07004248 public int interceptWakeMotionBeforeQueueing(long whenNanos, int policyFlags) {
4249 // We already know this is a wake motion so just wake up.
4250 // Note that we would observe policyFlags containing
4251 // FLAG_WAKE and FLAG_INTERACTIVE here.
4252 mPowerManager.wakeUp(whenNanos / 1000000);
4253 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08004254 }
4255
Jeff Brown40013652012-05-16 21:22:36 -07004256 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
4257 if (DEBUG_INPUT) {
4258 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004259 }
4260
Jeff Brown40013652012-05-16 21:22:36 -07004261 if (mHavePendingMediaKeyRepeatWithWakeLock) {
4262 if (DEBUG_INPUT) {
4263 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
4264 }
4265
4266 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
4267 mHavePendingMediaKeyRepeatWithWakeLock = false;
4268 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
4269 }
4270
4271 dispatchMediaKeyWithWakeLockToAudioService(event);
4272
4273 if (event.getAction() == KeyEvent.ACTION_DOWN
4274 && event.getRepeatCount() == 0) {
4275 mHavePendingMediaKeyRepeatWithWakeLock = true;
4276
4277 Message msg = mHandler.obtainMessage(
4278 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
4279 msg.setAsynchronous(true);
4280 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
4281 } else {
4282 mBroadcastWakeLock.release();
4283 }
4284 }
4285
4286 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
4287 mHavePendingMediaKeyRepeatWithWakeLock = false;
4288
4289 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
4290 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
4291 if (DEBUG_INPUT) {
4292 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
4293 }
4294
4295 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
4296 mBroadcastWakeLock.release();
4297 }
4298
4299 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
4300 if (ActivityManagerNative.isSystemReady()) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004301 if (USE_SESSIONS) {
4302 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
4303 } else {
4304 IAudioService audioService = getAudioService();
4305 if (audioService != null) {
4306 try {
4307 audioService.dispatchMediaKeyEventUnderWakelock(event);
4308 } catch (RemoteException e) {
4309 Log.e(TAG, "dispatchMediaKeyEvent threw exception " + e);
4310 }
Jean-Michel Trivic6802222012-04-30 11:15:03 -07004311 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004312 }
4313 }
4314 }
4315
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004316 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08004317 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004318 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07004319 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
4320 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
4321 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04004322 } else {
4323 try {
4324 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
4325 ServiceManager.getService(Context.UI_MODE_SERVICE));
4326 mUiMode = uiModeService.getCurrentModeType();
4327 } catch (RemoteException e) {
4328 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07004329 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004330 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08004331 synchronized (mLock) {
4332 updateOrientationListenerLp();
4333 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07004334 }
4335 };
4336
Jeff Brown6aaf2952012-10-05 16:01:08 -07004337 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
4338 @Override
4339 public void onReceive(Context context, Intent intent) {
4340 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004341 if (mKeyguardDelegate != null) {
4342 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004343 }
4344 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004345 if (mKeyguardDelegate != null) {
4346 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07004347 }
4348 }
4349 }
4350 };
4351
Christopher Tate5e08af02012-09-21 17:17:22 -07004352 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
4353 @Override
4354 public void onReceive(Context context, Intent intent) {
4355 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
4356 // tickle the settings observer: this first ensures that we're
4357 // observing the relevant settings for the newly-active user,
4358 // and then updates our own bookkeeping based on the now-
4359 // current user.
4360 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05004361
4362 // force a re-application of focused window sysui visibility.
4363 // the window may never have been shown for this user
4364 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04004365 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05004366 mLastSystemUiFlags = 0;
4367 updateSystemUiVisibilityLw();
4368 }
Christopher Tate5e08af02012-09-21 17:17:22 -07004369 }
4370 }
4371 };
4372
John Spurlockd9b70bd2014-02-06 17:02:44 -05004373 private final Runnable mRequestTransientNav = new Runnable() {
4374 @Override
4375 public void run() {
4376 requestTransientBars(mNavigationBar);
4377 }
4378 };
4379
John Spurlocke1f366f2013-08-05 12:22:40 -04004380 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04004381 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07004382 if (!isUserSetupComplete()) {
4383 // Swipe-up for navigation bar is disabled during setup
4384 return;
4385 }
John Spurlock27735a42013-08-14 17:57:38 -04004386 boolean sb = mStatusBarController.checkShowTransientBarLw();
4387 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004388 if (sb || nb) {
John Spurlocke1f366f2013-08-05 12:22:40 -04004389 WindowState barTarget = sb ? mStatusBar : mNavigationBar;
4390 if (sb ^ nb && barTarget != swipeTarget) {
4391 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04004392 return;
4393 }
John Spurlock27735a42013-08-14 17:57:38 -04004394 if (sb) mStatusBarController.showTransient();
4395 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04004396 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04004397 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04004398 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04004399 }
4400 }
4401
Jeff Brownc38c9be2012-10-04 13:16:19 -07004402 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004403 public void goingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004404 EventLog.writeEvent(70000, 0);
The Android Open Source Project0727d222009-03-11 12:11:58 -07004405 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004406 mScreenOnEarly = false;
4407 mScreenOnFully = false;
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004408 }
Jim Miller5ecd8112013-01-09 18:50:26 -08004409 if (mKeyguardDelegate != null) {
4410 mKeyguardDelegate.onScreenTurnedOff(why);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004411 }
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004412 synchronized (mLock) {
The Android Open Source Project0727d222009-03-11 12:11:58 -07004413 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004414 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004415 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004416 }
4417
Jeff Brownc38c9be2012-10-04 13:16:19 -07004418 @Override
Jeff Brown140ffc72014-05-01 15:18:00 -07004419 public void wakingUp(final ScreenOnListener screenOnListener) {
Dianne Hackborn74489012009-03-24 20:50:09 -07004420 EventLog.writeEvent(70000, 1);
Dianne Hackborn40011092011-09-22 13:37:48 -07004421 if (false) {
4422 RuntimeException here = new RuntimeException("here");
4423 here.fillInStackTrace();
4424 Slog.i(TAG, "Screen turning on...", here);
4425 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004426
The Android Open Source Project0727d222009-03-11 12:11:58 -07004427 synchronized (mLock) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004428 mScreenOnEarly = true;
The Android Open Source Project0727d222009-03-11 12:11:58 -07004429 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05004430 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07004431 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004432
Jeff Brownc38c9be2012-10-04 13:16:19 -07004433 waitForKeyguard(screenOnListener);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004434 }
4435
Jeff Brownc38c9be2012-10-04 13:16:19 -07004436 private void waitForKeyguard(final ScreenOnListener screenOnListener) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004437 if (mKeyguardDelegate != null) {
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004438 mKeyguardDelegate.onScreenTurnedOn(new KeyguardServiceDelegate.ShowListener() {
4439 @Override
4440 public void onShown(IBinder windowToken) {
4441 waitForKeyguardWindowDrawn(windowToken, screenOnListener);
4442 }
4443 });
Jeff Brownc38c9be2012-10-04 13:16:19 -07004444 } else {
Jim Miller5ecd8112013-01-09 18:50:26 -08004445 Slog.i(TAG, "No keyguard interface!");
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004446 finishScreenTurningOn(screenOnListener);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004447 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004448 }
4449
4450 private void waitForKeyguardWindowDrawn(IBinder windowToken,
4451 final ScreenOnListener screenOnListener) {
Craig Mautner6f295902013-10-11 21:43:06 -07004452 if (windowToken != null && !mHideLockScreen) {
Jeff Brownc38c9be2012-10-04 13:16:19 -07004453 try {
4454 if (mWindowManager.waitForWindowDrawn(
4455 windowToken, new IRemoteCallback.Stub() {
4456 @Override
4457 public void sendResult(Bundle data) {
4458 Slog.i(TAG, "Lock screen displayed!");
4459 finishScreenTurningOn(screenOnListener);
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004460 setKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004461 }
4462 })) {
4463 return;
4464 }
Craig Mautner4e8a19c2013-10-08 17:26:08 -07004465 Slog.i(TAG, "No lock screen! waitForWindowDrawn false");
4466
Jeff Brownc38c9be2012-10-04 13:16:19 -07004467 } catch (RemoteException ex) {
4468 // Can't happen in system process.
4469 }
4470 }
4471
Craig Mautner4e8a19c2013-10-08 17:26:08 -07004472 Slog.i(TAG, "No lock screen! windowToken=" + windowToken);
Jeff Brownc38c9be2012-10-04 13:16:19 -07004473 finishScreenTurningOn(screenOnListener);
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004474 setKeyguardDrawn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07004475 }
4476
4477 private void finishScreenTurningOn(ScreenOnListener screenOnListener) {
4478 synchronized (mLock) {
4479 mScreenOnFully = true;
4480 }
4481
Jeff Brown4fc45272012-10-10 18:28:14 -07004482 try {
4483 mWindowManager.setEventDispatching(true);
4484 } catch (RemoteException unhandled) {
4485 }
4486
Jeff Brownc38c9be2012-10-04 13:16:19 -07004487 if (screenOnListener != null) {
4488 screenOnListener.onScreenOn();
4489 }
4490 }
4491
4492 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004493 public boolean isScreenOnEarly() {
4494 return mScreenOnEarly;
4495 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004496
4497 @Override
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004498 public boolean isScreenOnFully() {
4499 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08004500 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07004501
Dianne Hackborn08743722009-12-21 12:16:51 -08004502 /** {@inheritDoc} */
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004503 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004504 if (mKeyguardDelegate != null) {
4505 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004506 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004507 }
4508
4509 /** {@inheritDoc} */
4510 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08004511 if (mKeyguardDelegate != null) {
4512 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004513 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004514 }
4515
Mike Lockwoodf7913302009-11-28 22:27:10 -05004516 private boolean keyguardIsShowingTq() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004517 if (mKeyguardDelegate == null) return false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004518 return mKeyguardDelegate.isShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004519 }
4520
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004521
4522 /** {@inheritDoc} */
4523 public boolean isKeyguardLocked() {
4524 return keyguardOn();
4525 }
4526
4527 /** {@inheritDoc} */
4528 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004529 if (mKeyguardDelegate == null) return false;
4530 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05004531 }
4532
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004533 /** {@inheritDoc} */
4534 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004535 if (mKeyguardDelegate == null) return false;
4536 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004537 }
4538
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004539 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07004540 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004541 mHandler.post(new Runnable() {
4542 public void run() {
Jim Miller5ecd8112013-01-09 18:50:26 -08004543 if (mKeyguardDelegate.isDismissable()) {
Daniel Sandler1ce804392012-11-07 15:07:12 -05004544 // Can we just finish the keyguard straight away?
Jim Miller5ecd8112013-01-09 18:50:26 -08004545 mKeyguardDelegate.keyguardDone(false, true);
Daniel Sandler1ce804392012-11-07 15:07:12 -05004546 } else {
4547 // ask the keyguard to prompt the user to authenticate if necessary
Jim Miller5ecd8112013-01-09 18:50:26 -08004548 mKeyguardDelegate.dismiss();
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004549 }
Daniel Sandler1ce804392012-11-07 15:07:12 -05004550 }
4551 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07004552 }
4553 }
4554
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004555 private void setKeyguardDrawn() {
4556 synchronized (mLock) {
4557 mKeyguardDrawn = true;
4558 }
4559 try {
4560 mWindowManager.enableScreenIfNeeded();
4561 } catch (RemoteException unhandled) {
4562 }
4563 }
4564
4565 @Override
4566 public boolean isKeyguardDrawnLw() {
4567 synchronized (mLock) {
4568 return mKeyguardDrawn;
4569 }
4570 }
4571
Jorim Jaggi0d674622014-05-21 01:34:15 +02004572 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004573 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02004574 if (mKeyguardDelegate != null) {
Jorim Jaggie29b2db2014-05-30 23:17:03 +02004575 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02004576 }
4577 }
4578
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004579 void sendCloseSystemWindows() {
4580 sendCloseSystemWindows(mContext, null);
4581 }
4582
4583 void sendCloseSystemWindows(String reason) {
4584 sendCloseSystemWindows(mContext, reason);
4585 }
4586
4587 static void sendCloseSystemWindows(Context context, String reason) {
4588 if (ActivityManagerNative.isSystemReady()) {
Dianne Hackborn94a679d2009-07-28 17:51:07 -07004589 try {
4590 ActivityManagerNative.getDefault().closeSystemDialogs(reason);
4591 } catch (RemoteException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004592 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004593 }
4594 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07004595
Jeff Brown01a98dd2011-09-20 15:08:29 -07004596 @Override
4597 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004598 if (false) {
4599 Slog.v(TAG, "rotationForOrientationLw(orient="
4600 + orientation + ", last=" + lastRotation
4601 + "); user=" + mUserRotation + " "
4602 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
4603 ? "USER_ROTATION_LOCKED" : "")
4604 );
4605 }
4606
Craig Mautner46ac6fa2013-08-01 10:06:34 -07004607 if (mForceDefaultOrientation) {
4608 return Surface.ROTATION_0;
4609 }
4610
The Android Open Source Project0727d222009-03-11 12:11:58 -07004611 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07004612 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
4613 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07004614 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07004615 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004616
Jeff Browndec6cf42011-11-15 14:08:20 -08004617 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07004618 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004619 // Ignore sensor when lid switch is open and rotation is forced.
4620 preferredRotation = mLidOpenRotation;
4621 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07004622 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004623 // Ignore sensor when in car dock unless explicitly enabled.
4624 // This case can override the behavior of NOSENSOR, and can also
4625 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004626 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004627 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08004628 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
4629 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
4630 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07004631 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004632 // Ignore sensor when in desk dock unless explicitly enabled.
4633 // This case can override the behavior of NOSENSOR, and can also
4634 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07004635 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07004636 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004637 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
4638 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08004639 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07004640 preferredRotation = mDemoHdmiRotation;
4641 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
4642 && mUndockedHdmiRotation >= 0) {
4643 // Ignore sensor when plugged into HDMI and an undocked orientation has
4644 // been specified in the configuration (only for legacy devices without
4645 // full multi-display support).
4646 // Note that the dock orientation overrides the HDMI orientation.
4647 preferredRotation = mUndockedHdmiRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004648 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
4649 // Application just wants to remain locked in the last rotation.
4650 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08004651 } else if (!mSupportAutoRotation) {
4652 // If we don't support auto-rotation then bail out here and ignore
4653 // the sensor and any rotation lock settings.
4654 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07004655 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07004656 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004657 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
4658 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
4659 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
4660 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07004661 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
4662 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4663 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
4664 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
4665 // Otherwise, use sensor only if requested by the application or enabled
4666 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07004667 if (mAllowAllRotations < 0) {
4668 // Can't read this during init() because the context doesn't
4669 // have display metrics at that time so we cannot determine
4670 // tablet vs. phone then.
4671 mAllowAllRotations = mContext.getResources().getBoolean(
4672 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
4673 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004674 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07004675 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004676 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
4677 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07004678 preferredRotation = sensorRotation;
4679 } else {
4680 preferredRotation = lastRotation;
4681 }
Jeff Brown207673cd2012-06-05 17:47:11 -07004682 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
4683 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
4684 // Apply rotation lock. Does not apply to NOSENSOR.
4685 // The idea is that the user rotation expresses a weak preference for the direction
4686 // of gravity and as NOSENSOR is never affected by gravity, then neither should
4687 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07004688 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08004689 } else {
4690 // No overriding preference.
4691 // We will do exactly what the application asked us to do.
4692 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07004693 }
4694
Dianne Hackborne5439f22010-10-02 16:53:50 -07004695 switch (orientation) {
4696 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004697 // Return portrait unless overridden.
4698 if (isAnyPortrait(preferredRotation)) {
4699 return preferredRotation;
4700 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07004701 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004702
Jeff Brown01a98dd2011-09-20 15:08:29 -07004703 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004704 // Return landscape unless overridden.
4705 if (isLandscapeOrSeascape(preferredRotation)) {
4706 return preferredRotation;
4707 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004708 return mLandscapeRotation;
4709
4710 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08004711 // Return reverse portrait unless overridden.
4712 if (isAnyPortrait(preferredRotation)) {
4713 return preferredRotation;
4714 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004715 return mUpsideDownRotation;
4716
4717 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08004718 // Return seascape unless overridden.
4719 if (isLandscapeOrSeascape(preferredRotation)) {
4720 return preferredRotation;
4721 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004722 return mSeascapeRotation;
4723
4724 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004725 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004726 // Return either landscape rotation.
4727 if (isLandscapeOrSeascape(preferredRotation)) {
4728 return preferredRotation;
4729 }
4730 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08004731 return lastRotation;
4732 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004733 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004734
Jeff Brown01a98dd2011-09-20 15:08:29 -07004735 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07004736 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07004737 // Return either portrait rotation.
4738 if (isAnyPortrait(preferredRotation)) {
4739 return preferredRotation;
4740 }
4741 if (isAnyPortrait(lastRotation)) {
4742 return lastRotation;
4743 }
4744 return mPortraitRotation;
4745
4746 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07004747 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
4748 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07004749 if (preferredRotation >= 0) {
4750 return preferredRotation;
4751 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07004752 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05004753 }
4754 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004755 }
4756
Jeff Brown01a98dd2011-09-20 15:08:29 -07004757 @Override
4758 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
4759 switch (orientation) {
4760 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
4761 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
4762 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
4763 return isAnyPortrait(rotation);
4764
4765 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
4766 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
4767 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
4768 return isLandscapeOrSeascape(rotation);
4769
4770 default:
4771 return true;
4772 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07004773 }
4774
Jeff Brownc0347aa2011-09-23 17:26:09 -07004775 @Override
4776 public void setRotationLw(int rotation) {
4777 mOrientationListener.setCurrentRotation(rotation);
4778 }
4779
Jeff Brown01a98dd2011-09-20 15:08:29 -07004780 private boolean isLandscapeOrSeascape(int rotation) {
4781 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004782 }
4783
Jeff Brown01a98dd2011-09-20 15:08:29 -07004784 private boolean isAnyPortrait(int rotation) {
4785 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07004786 }
4787
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004788 public int getUserRotationMode() {
4789 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07004790 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
4791 WindowManagerPolicy.USER_ROTATION_FREE :
4792 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08004793 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004794
4795 // User rotation: to be used when all else fails in assigning an orientation to the device
4796 public void setUserRotationMode(int mode, int rot) {
4797 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004798
4799 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004800 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07004801 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004802 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004803 rot,
4804 UserHandle.USER_CURRENT);
4805 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05004806 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004807 0,
4808 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004809 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07004810 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004811 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07004812 1,
4813 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04004814 }
4815 }
4816
Jeff Brownac143512012-04-05 18:57:33 -07004817 public void setSafeMode(boolean safeMode) {
4818 mSafeMode = safeMode;
4819 performHapticFeedbackLw(null, safeMode
4820 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
4821 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004822 }
Craig Mautnereda67292013-04-28 13:50:14 -07004823
Dianne Hackborn181ceb52009-08-27 22:16:40 -07004824 static long[] getLongIntArray(Resources r, int resid) {
4825 int[] ar = r.getIntArray(resid);
4826 if (ar == null) {
4827 return null;
4828 }
4829 long[] out = new long[ar.length];
4830 for (int i=0; i<ar.length; i++) {
4831 out[i] = ar[i];
4832 }
4833 return out;
4834 }
Craig Mautnereda67292013-04-28 13:50:14 -07004835
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004836 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07004837 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004838 public void systemReady() {
Mike Lockwooded8902d2013-11-15 11:01:47 -08004839 mKeyguardDelegate = new KeyguardServiceDelegate(mContext, null);
4840 mKeyguardDelegate.onSystemReady();
4841
Dianne Hackbornb1a79802009-09-29 15:18:31 -07004842 synchronized (mLock) {
4843 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08004844 mSystemReady = true;
4845 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07004846 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08004847 public void run() {
4848 updateSettings();
4849 }
4850 });
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004851 }
4852 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07004853
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004854 /** {@inheritDoc} */
4855 public void systemBooted() {
Jim Millere5f910a2013-10-16 18:15:46 -07004856 if (mKeyguardDelegate != null) {
4857 mKeyguardDelegate.onBootCompleted();
4858 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004859 synchronized (mLock) {
4860 mSystemBooted = true;
4861 }
Jorim Jaggicff0acb2014-03-31 16:35:15 +02004862 waitForKeyguard(null);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07004863 }
4864
Dianne Hackborn661cd522011-08-22 00:26:20 -07004865 ProgressDialog mBootMsgDialog = null;
4866
4867 /** {@inheritDoc} */
4868 public void showBootMessage(final CharSequence msg, final boolean always) {
4869 mHandler.post(new Runnable() {
4870 @Override public void run() {
4871 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07004872 int theme;
4873 if (mContext.getPackageManager().hasSystemFeature(
4874 PackageManager.FEATURE_WATCH)) {
4875 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
4876 } else if (mContext.getPackageManager().hasSystemFeature(
4877 PackageManager.FEATURE_TELEVISION)) {
4878 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
4879 } else {
4880 theme = 0;
4881 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07004882
4883 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07004884 // This dialog will consume all events coming in to
4885 // it, to avoid it trying to do things too early in boot.
4886 @Override public boolean dispatchKeyEvent(KeyEvent event) {
4887 return true;
4888 }
4889 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
4890 return true;
4891 }
4892 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
4893 return true;
4894 }
4895 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
4896 return true;
4897 }
4898 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
4899 return true;
4900 }
4901 @Override public boolean dispatchPopulateAccessibilityEvent(
4902 AccessibilityEvent event) {
4903 return true;
4904 }
4905 };
Dianne Hackborn661cd522011-08-22 00:26:20 -07004906 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
4907 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
4908 mBootMsgDialog.setIndeterminate(true);
4909 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07004910 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004911 mBootMsgDialog.getWindow().addFlags(
4912 WindowManager.LayoutParams.FLAG_DIM_BEHIND
4913 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
4914 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08004915 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
4916 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
4917 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07004918 mBootMsgDialog.setCancelable(false);
4919 mBootMsgDialog.show();
4920 }
4921 mBootMsgDialog.setMessage(msg);
4922 }
4923 });
4924 }
4925
4926 /** {@inheritDoc} */
4927 public void hideBootMessages() {
4928 mHandler.post(new Runnable() {
4929 @Override public void run() {
4930 if (mBootMsgDialog != null) {
4931 mBootMsgDialog.dismiss();
4932 mBootMsgDialog = null;
4933 }
4934 }
4935 });
4936 }
4937
Mike Lockwood28569302010-01-28 11:54:40 -05004938 /** {@inheritDoc} */
4939 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004940 // ***************************************
4941 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
4942 // ***************************************
4943 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
4944 // WITH ITS LOCKS HELD.
4945 //
4946 // This code must be VERY careful about the locks
4947 // it acquires.
4948 // In fact, the current code acquires way too many,
4949 // and probably has lurking deadlocks.
4950
Mike Lockwood28569302010-01-28 11:54:40 -05004951 synchronized (mScreenLockTimeout) {
4952 if (mLockScreenTimerActive) {
4953 // reset the timer
4954 mHandler.removeCallbacks(mScreenLockTimeout);
4955 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
4956 }
4957 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04004958 }
4959
Adam Cohenf7522022012-10-03 20:03:18 -07004960 class ScreenLockTimeout implements Runnable {
4961 Bundle options;
4962
4963 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05004964 public void run() {
4965 synchronized (this) {
4966 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08004967 if (mKeyguardDelegate != null) {
4968 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004969 }
Mike Lockwood28569302010-01-28 11:54:40 -05004970 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07004971 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05004972 }
4973 }
Mike Lockwood28569302010-01-28 11:54:40 -05004974
Adam Cohenf7522022012-10-03 20:03:18 -07004975 public void setLockOptions(Bundle options) {
4976 this.options = options;
4977 }
4978 }
4979
4980 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
4981
4982 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08004983 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
4984 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07004985 if (options != null) {
4986 // In case multiple calls are made to lockNow, we don't wipe out the options
4987 // until the runnable actually executes.
4988 mScreenLockTimeout.setLockOptions(options);
4989 }
Jim Miller93c518e2012-01-17 15:55:31 -08004990 mHandler.post(mScreenLockTimeout);
4991 }
4992
Mike Lockwood28569302010-01-28 11:54:40 -05004993 private void updateLockScreenTimeout() {
4994 synchronized (mScreenLockTimeout) {
Mike Lockwood3a74bd32011-08-12 13:55:22 -07004995 boolean enable = (mAllowLockscreenWhenOn && mScreenOnEarly &&
Jim Miller5ecd8112013-01-09 18:50:26 -08004996 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05004997 if (mLockScreenTimerActive != enable) {
4998 if (enable) {
4999 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
5000 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
5001 } else {
5002 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
5003 mHandler.removeCallbacks(mScreenLockTimeout);
5004 }
5005 mLockScreenTimerActive = enable;
5006 }
5007 }
5008 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005009
5010 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07005011 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005012 public void enableScreenAfterBoot() {
5013 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07005014 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005015 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005016 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07005017
Jeff Brownc458ce92012-04-30 14:58:40 -07005018 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07005019 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07005020 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
5021 PowerManager.GO_TO_SLEEP_REASON_USER,
5022 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Jeff Brownc458ce92012-04-30 14:58:40 -07005023 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005024 }
5025
5026 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005027 try {
5028 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005029 mWindowManager.updateRotation(alwaysSendConfiguration, false);
5030 } catch (RemoteException e) {
5031 // Ignore
5032 }
5033 }
5034
5035 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
5036 try {
5037 //set orientation on WindowManager
5038 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005039 } catch (RemoteException e) {
5040 // Ignore
5041 }
5042 }
5043
Daniel Sandler6396c722013-04-16 20:19:09 -04005044 /**
5045 * Return an Intent to launch the currently active dock app as home. Returns
5046 * null if the standard home should be launched, which is the case if any of the following is
5047 * true:
5048 * <ul>
5049 * <li>The device is not in either car mode or desk mode
5050 * <li>The device is in car mode but ENABLE_CAR_DOCK_HOME_CAPTURE is false
5051 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
5052 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
5053 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
5054 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07005055 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04005056 */
5057 Intent createHomeDockIntent() {
5058 Intent intent = null;
5059
5060 // What home does is based on the mode, not the dock state. That
5061 // is, when in car mode you should be taken to car home regardless
5062 // of whether we are actually in a car dock.
5063 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
5064 if (ENABLE_CAR_DOCK_HOME_CAPTURE) {
5065 intent = mCarDockIntent;
5066 }
5067 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
5068 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
5069 intent = mDeskDockIntent;
5070 }
5071 }
5072
5073 if (intent == null) {
5074 return null;
5075 }
5076
5077 ActivityInfo ai = null;
5078 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
5079 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04005080 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07005081 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04005082 if (info != null) {
5083 ai = info.activityInfo;
5084 }
5085 if (ai != null
5086 && ai.metaData != null
5087 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
5088 intent = new Intent(intent);
5089 intent.setClassName(ai.packageName, ai.name);
5090 return intent;
5091 }
5092
5093 return null;
5094 }
5095
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005096 void startDockOrHome() {
John Spurlockc8b46ca2013-04-08 12:59:26 -04005097 awakenDreams();
Daniel Sandler6396c722013-04-16 20:19:09 -04005098
5099 Intent dock = createHomeDockIntent();
5100 if (dock != null) {
5101 try {
5102 mContext.startActivityAsUser(dock, UserHandle.CURRENT);
5103 return;
5104 } catch (ActivityNotFoundException e) {
5105 }
5106 }
5107
Dianne Hackbornd8883992012-09-07 15:58:52 -07005108 mContext.startActivityAsUser(mHomeIntent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005109 }
Craig Mautnereda67292013-04-28 13:50:14 -07005110
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005111 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005112 * goes to the home screen
5113 * @return whether it did anything
5114 */
5115 boolean goHome() {
5116 if (false) {
5117 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07005118 try {
5119 ActivityManagerNative.getDefault().stopAppSwitches();
5120 } catch (RemoteException e) {
5121 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07005122 sendCloseSystemWindows();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005123 startDockOrHome();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005124 } else {
5125 // This code brings home to the front or, if it is already
5126 // at the front, puts the device to sleep.
5127 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08005128 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
5129 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
5130 Log.d(TAG, "UTS-TEST-MODE");
5131 } else {
5132 ActivityManagerNative.getDefault().stopAppSwitches();
5133 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04005134 Intent dock = createHomeDockIntent();
5135 if (dock != null) {
5136 int result = ActivityManagerNative.getDefault()
5137 .startActivityAsUser(null, null, dock,
5138 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
5139 null, null, 0,
5140 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
5141 null, null, null, UserHandle.USER_CURRENT);
5142 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
5143 return false;
5144 }
5145 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07005146 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005147 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005148 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005149 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07005150 null, null, 0,
5151 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Dianne Hackborn5e03e2c2012-09-06 14:21:19 -07005152 null, null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07005153 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005154 return false;
5155 }
5156 } catch (RemoteException ex) {
5157 // bummer, the activity manager, which is in this process, is dead
5158 }
5159 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005160 return true;
5161 }
Craig Mautnereda67292013-04-28 13:50:14 -07005162
5163 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005164 public void setCurrentOrientationLw(int newOrientation) {
5165 synchronized (mLock) {
5166 if (newOrientation != mCurrentAppOrientation) {
5167 mCurrentAppOrientation = newOrientation;
5168 updateOrientationListenerLp();
5169 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005170 }
5171 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005172
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005173 private void performAuditoryFeedbackForAccessibilityIfNeed() {
5174 if (!isGlobalAccessibilityGestureEnabled()) {
5175 return;
5176 }
5177 AudioManager audioManager = (AudioManager) mContext.getSystemService(
5178 Context.AUDIO_SERVICE);
5179 if (audioManager.isSilentMode()) {
5180 return;
5181 }
5182 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
5183 Settings.System.DEFAULT_NOTIFICATION_URI);
5184 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
5185 ringTone.play();
5186 }
Craig Mautnereda67292013-04-28 13:50:14 -07005187
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07005188 private boolean isGlobalAccessibilityGestureEnabled() {
5189 return Settings.Global.getInt(mContext.getContentResolver(),
5190 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
5191 }
5192
Craig Mautnereda67292013-04-28 13:50:14 -07005193 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07005194 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07005195 if (!mVibrator.hasVibrator()) {
5196 return false;
5197 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005198 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
5199 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005200 if (!always && (hapticsDisabled || mKeyguardDelegate.isShowingAndNotOccluded())) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005201 return false;
5202 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005203 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005204 switch (effectId) {
5205 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005206 pattern = mLongPressVibePattern;
5207 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005208 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005209 pattern = mVirtualKeyVibePattern;
5210 break;
5211 case HapticFeedbackConstants.KEYBOARD_TAP:
5212 pattern = mKeyboardTapVibePattern;
5213 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07005214 case HapticFeedbackConstants.CLOCK_TICK:
5215 pattern = mClockTickVibePattern;
5216 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005217 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005218 pattern = mSafeModeDisabledVibePattern;
5219 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07005220 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08005221 pattern = mSafeModeEnabledVibePattern;
5222 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08005223 default:
5224 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005225 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005226 int owningUid;
5227 String owningPackage;
5228 if (win != null) {
5229 owningUid = win.getOwningUid();
5230 owningPackage = win.getOwningPackage();
5231 } else {
5232 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07005233 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08005234 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08005235 if (pattern.length == 1) {
5236 // One-shot vibration
John Spurlock1af30c72014-03-10 08:33:35 -04005237 mVibrator.vibrate(owningUid, owningPackage, pattern[0], AudioManager.STREAM_SYSTEM);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005238 } else {
5239 // Pattern vibration
John Spurlock1af30c72014-03-10 08:33:35 -04005240 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, AudioManager.STREAM_SYSTEM);
Amith Yamasanic33cb712010-02-10 15:21:49 -08005241 }
5242 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005243 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005244
5245 @Override
5246 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04005247 }
5248
Jeff Brownc38c9be2012-10-04 13:16:19 -07005249 @Override
5250 public void keepScreenOnStoppedLw() {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005251 if (mKeyguardDelegate != null && !mKeyguardDelegate.isShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08005252 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005253 }
5254 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04005255
Dianne Hackborndf89e652011-10-06 22:35:11 -07005256 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08005257 // If there is no window focused, there will be nobody to handle the events
5258 // anyway, so just hang on in whatever state we're in until things settle down.
John Spurlock79da8332013-09-20 12:04:47 -04005259 WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
5260 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005261 return 0;
5262 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005263 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005264 // We are updating at a point where the keyguard has gotten
5265 // focus, but we were last in a state where the top window is
5266 // hiding it. This is probably because the keyguard as been
5267 // shown while the top window was displayed, so we want to ignore
5268 // it here because this is just a very transient change and it
5269 // will quickly lose focus once it correctly gets hidden.
5270 return 0;
5271 }
John Spurlock32beb2c2013-03-11 10:16:47 -04005272
John Spurlock1db8b682014-02-18 11:18:59 -05005273 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07005274 & ~mResettingSystemUiFlags
5275 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005276 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05005277 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005278 }
John Spurlock79da8332013-09-20 12:04:47 -04005279 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005280 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04005281 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08005282 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04005283 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07005284 return 0;
5285 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07005286 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005287 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04005288 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07005289 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07005290 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07005291 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005292 try {
5293 IStatusBarService statusbar = getStatusBarService();
5294 if (statusbar != null) {
5295 statusbar.setSystemUiVisibility(visibility, 0xffffffff);
5296 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08005297 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07005298 } catch (RemoteException e) {
5299 // re-acquire status bar service next time it is needed.
5300 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08005301 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07005302 }
5303 });
5304 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08005305 }
5306
John Spurlock79da8332013-09-20 12:04:47 -04005307 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
John Spurlockbd957402013-10-03 11:38:39 -04005308 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005309 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
5310 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04005311 : mTopFullscreenOpaqueWindowState;
5312 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5313 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
5314
John Spurlock27735a42013-08-14 17:57:38 -04005315 // prevent status bar interaction from clearing certain flags
John Spurlock79da8332013-09-20 12:04:47 -04005316 boolean statusBarHasFocus = win.getAttrs().type == TYPE_STATUS_BAR;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005317 if (statusBarHasFocus) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04005318 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
5319 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04005320 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi5cf17872014-03-26 18:31:48 +01005321 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
5322 if (!isStatusBarKeyguard() || mHideLockScreen) {
5323 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
5324 }
John Spurlockbd957402013-10-03 11:38:39 -04005325 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04005326 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005327
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005328 if (!areTranslucentBarsAllowed()) {
Adrian Roosea562512014-05-05 13:33:03 +02005329 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
5330 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005331 }
5332
John Spurlock27735a42013-08-14 17:57:38 -04005333 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04005334 boolean immersiveSticky =
5335 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
John Spurlock27735a42013-08-14 17:57:38 -04005336 boolean hideStatusBarWM =
John Spurlockbd957402013-10-03 11:38:39 -04005337 mTopFullscreenOpaqueWindowState != null &&
John Spurlockc6d1c602014-01-17 15:22:06 -05005338 (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04005339 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
5340 boolean hideStatusBarSysui =
5341 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04005342 boolean hideNavBarSysui =
5343 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005344
John Spurlock27735a42013-08-14 17:57:38 -04005345 boolean transientStatusBarAllowed =
5346 mStatusBar != null && (
5347 hideStatusBarWM
John Spurlockf1a36642013-10-12 17:50:42 -04005348 || (hideStatusBarSysui && immersiveSticky)
John Spurlock27735a42013-08-14 17:57:38 -04005349 || statusBarHasFocus);
5350
John Spurlockf1a36642013-10-12 17:50:42 -04005351 boolean transientNavBarAllowed =
5352 mNavigationBar != null &&
5353 hideNavBarSysui && immersiveSticky;
5354
John Spurlockf25706f2013-11-07 18:02:43 -05005355 boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005356 && !transientStatusBarAllowed && hideStatusBarSysui;
John Spurlockf25706f2013-11-07 18:02:43 -05005357 boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04005358 && !transientNavBarAllowed;
5359 if (denyTransientStatus || denyTransientNav) {
John Spurlock27735a42013-08-14 17:57:38 -04005360 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04005361 clearClearableFlagsLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005362 }
John Spurlock27735a42013-08-14 17:57:38 -04005363
5364 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
5365
5366 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04005367 boolean oldImmersiveMode = isImmersiveMode(oldVis);
5368 boolean newImmersiveMode = isImmersiveMode(vis);
5369 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04005370 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07005371 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
5372 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04005373 }
John Spurlock27735a42013-08-14 17:57:38 -04005374
John Spurlockf1a36642013-10-12 17:50:42 -04005375 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
5376
John Spurlocke1f366f2013-08-05 12:22:40 -04005377 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04005378 }
5379
John Spurlockf1a36642013-10-12 17:50:42 -04005380 private void clearClearableFlagsLw() {
5381 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
5382 if (newVal != mResettingSystemUiFlags) {
5383 mResettingSystemUiFlags = newVal;
5384 mWindowManagerFuncs.reevaluateStatusBarVisibility();
5385 }
5386 }
5387
5388 private boolean isImmersiveMode(int vis) {
5389 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04005390 return mNavigationBar != null
5391 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04005392 && (vis & flags) != 0
5393 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04005394 }
5395
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005396 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005397 * @return whether the navigation or status bar can be made translucent
5398 *
5399 * This should return true unless touch exploration is not enabled or
5400 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005401 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04005402 private boolean areTranslucentBarsAllowed() {
Svetoslav8e3feb12014-02-24 13:46:47 -08005403 return mTranslucentDecorEnabled
5404 && !mAccessibilityManager.isTouchExplorationEnabled();
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07005405 }
5406
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005407 // Use this instead of checking config_showNavigationBar so that it can be consistently
5408 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07005409 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04005410 public boolean hasNavigationBar() {
5411 return mHasNavigationBar;
5412 }
5413
satok1bc0a492012-04-25 22:47:12 +09005414 @Override
5415 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
5416 mLastInputMethodWindow = ime;
5417 mLastInputMethodTargetWindow = target;
5418 }
5419
Craig Mautnerf1b67412012-09-19 13:18:29 -07005420 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09005421 public int getInputMethodWindowVisibleHeightLw() {
5422 return mDockBottom - mCurBottom;
5423 }
5424
5425 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07005426 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07005427 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08005428 if (mKeyguardDelegate != null) {
5429 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005430 }
John Spurlock13451a22012-09-28 14:40:41 -04005431 if (mStatusBarService != null) {
5432 try {
5433 mStatusBarService.setCurrentUser(newUserId);
5434 } catch (RemoteException e) {
5435 // oh well
5436 }
5437 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005438 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07005439 }
5440
5441 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08005442 public boolean canMagnifyWindow(int windowType) {
5443 switch (windowType) {
5444 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
5445 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
5446 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
5447 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
5448 return false;
5449 }
5450 }
5451 return true;
5452 }
5453
5454 @Override
5455 public boolean isTopLevelWindow(int windowType) {
5456 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
5457 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
5458 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
5459 }
5460 return true;
5461 }
5462
Jim Miller4eeb4f62012-11-08 00:04:29 -08005463 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07005464 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005465 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07005466 pw.print(" mSystemReady="); pw.print(mSystemReady);
5467 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07005468 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005469 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
5470 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07005471 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
5472 || mForceClearedSystemUiFlags != 0) {
5473 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
5474 pw.print(Integer.toHexString(mLastSystemUiFlags));
5475 pw.print(" mResettingSystemUiFlags=0x");
5476 pw.print(Integer.toHexString(mResettingSystemUiFlags));
5477 pw.print(" mForceClearedSystemUiFlags=0x");
5478 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07005479 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08005480 if (mLastFocusNeedsMenu) {
5481 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
5482 pw.println(mLastFocusNeedsMenu);
5483 }
Jeff Brownbcdfc622014-03-06 19:13:04 -08005484 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04005485 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
5486 pw.print(" mDockMode="); pw.print(mDockMode);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005487 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
5488 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
5489 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
5490 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005491 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005492 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005493 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
5494 pw.print(mCarDockEnablesAccelerometer);
5495 pw.print(" mDeskDockEnablesAccelerometer=");
5496 pw.println(mDeskDockEnablesAccelerometer);
5497 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
5498 pw.print(mLidKeyboardAccessibility);
5499 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005500 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07005501 pw.print(prefix);
5502 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
5503 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
5504 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07005505 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
5506 pw.print(" mScreenOnFully="); pw.print(mScreenOnFully);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07005507 pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08005508 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
5509 pw.print(","); pw.print(mOverscanScreenTop);
5510 pw.print(") "); pw.print(mOverscanScreenWidth);
5511 pw.print("x"); pw.println(mOverscanScreenHeight);
5512 if (mOverscanLeft != 0 || mOverscanTop != 0
5513 || mOverscanRight != 0 || mOverscanBottom != 0) {
5514 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
5515 pw.print(" top="); pw.print(mOverscanTop);
5516 pw.print(" right="); pw.print(mOverscanRight);
5517 pw.print(" bottom="); pw.println(mOverscanBottom);
5518 }
Dianne Hackborn313440842013-02-19 19:22:59 -08005519 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
5520 pw.print(mRestrictedOverscanScreenLeft);
5521 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
5522 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
5523 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005524 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
5525 pw.print(","); pw.print(mUnrestrictedScreenTop);
5526 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
5527 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
5528 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
5529 pw.print(","); pw.print(mRestrictedScreenTop);
5530 pw.print(") "); pw.print(mRestrictedScreenWidth);
5531 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07005532 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
5533 pw.print(","); pw.print(mStableFullscreenTop);
5534 pw.print(")-("); pw.print(mStableFullscreenRight);
5535 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07005536 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
5537 pw.print(","); pw.print(mStableTop);
5538 pw.print(")-("); pw.print(mStableRight);
5539 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005540 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
5541 pw.print(","); pw.print(mSystemTop);
5542 pw.print(")-("); pw.print(mSystemRight);
5543 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005544 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
5545 pw.print(","); pw.print(mCurTop);
5546 pw.print(")-("); pw.print(mCurRight);
5547 pw.print(","); pw.print(mCurBottom); pw.println(")");
5548 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
5549 pw.print(","); pw.print(mContentTop);
5550 pw.print(")-("); pw.print(mContentRight);
5551 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07005552 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
5553 pw.print(","); pw.print(mVoiceContentTop);
5554 pw.print(")-("); pw.print(mVoiceContentRight);
5555 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005556 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
5557 pw.print(","); pw.print(mDockTop);
5558 pw.print(")-("); pw.print(mDockRight);
5559 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07005560 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
5561 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005562 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
5563 pw.print(" mShowingDream="); pw.print(mShowingDream);
5564 pw.print(" mDreamingLockscreen="); pw.println(mDreamingLockscreen);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005565 if (mLastInputMethodWindow != null) {
5566 pw.print(prefix); pw.print("mLastInputMethodWindow=");
5567 pw.println(mLastInputMethodWindow);
5568 }
5569 if (mLastInputMethodTargetWindow != null) {
5570 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
5571 pw.println(mLastInputMethodTargetWindow);
5572 }
5573 if (mStatusBar != null) {
5574 pw.print(prefix); pw.print("mStatusBar=");
5575 pw.println(mStatusBar);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01005576 pw.print(prefix); pw.print("isStatusBarKeyguard=");
5577 pw.print(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005578 }
5579 if (mNavigationBar != null) {
5580 pw.print(prefix); pw.print("mNavigationBar=");
5581 pw.println(mNavigationBar);
5582 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07005583 if (mFocusedWindow != null) {
5584 pw.print(prefix); pw.print("mFocusedWindow=");
5585 pw.println(mFocusedWindow);
5586 }
5587 if (mFocusedApp != null) {
5588 pw.print(prefix); pw.print("mFocusedApp=");
5589 pw.println(mFocusedApp);
5590 }
5591 if (mWinDismissingKeyguard != null) {
5592 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
5593 pw.println(mWinDismissingKeyguard);
5594 }
5595 if (mTopFullscreenOpaqueWindowState != null) {
5596 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
5597 pw.println(mTopFullscreenOpaqueWindowState);
5598 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08005599 if (mForcingShowNavBar) {
5600 pw.print(prefix); pw.print("mForcingShowNavBar=");
5601 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
5602 pw.println(mForcingShowNavBarLayer);
5603 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07005604 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005605 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07005606 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
5607 pw.print(" mForceStatusBarFromKeyguard=");
5608 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005609 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07005610 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005611 pw.print(" mHomePressed="); pw.println(mHomePressed);
5612 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
5613 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
5614 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
5615 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
5616 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
5617 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
5618 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
5619 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
5620 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
5621 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07005622 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
5623 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
5624 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07005625 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04005626 mStatusBarController.dump(pw, prefix);
5627 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05005628 PolicyControl.dump(prefix, pw);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08005629 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005630}