blob: de1c1ea091df58fe97240085f59415c900503458 [file] [log] [blame]
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001/*
Jeff Brown37df39a92015-02-25 15:42:31 -08002 * Copyright (C) 2006 The Android Open Source Project
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Jorim Jaggib10e33f2015-02-04 21:57:40 +010017package com.android.server.policy;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080018
Wale Ogunwale3797c222015-10-27 14:21:58 -070019import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
20import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -080021import static android.content.res.Configuration.UI_MODE_TYPE_CAR;
22import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070023import static android.view.WindowManager.LayoutParams.*;
24import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
25import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
26import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
27import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
28import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
29import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
30
Dianne Hackborna4972e92012-03-14 10:38:05 -070031import android.app.ActivityManager;
Jeff Brown061ea992015-04-17 19:55:47 -070032import android.app.ActivityManagerInternal;
33import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080034import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080035import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040036import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070037import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070038import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040039import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080040import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070041import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080042import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040043import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080044import android.content.ContentResolver;
45import android.content.Context;
46import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070047import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070048import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080049import android.content.pm.ActivityInfo;
50import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040051import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070052import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080053import android.content.res.Configuration;
54import android.content.res.Resources;
55import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080056import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080057import android.graphics.Rect;
Jinsuk Kime601b712015-07-07 08:01:02 +090058import android.hardware.hdmi.HdmiControlManager;
59import android.hardware.hdmi.HdmiPlaybackClient;
60import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
John Spurlock7b414672014-07-18 13:02:39 -040061import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080062import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050063import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080064import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070065import android.media.Ringtone;
66import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070067import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +010068import android.os.Binder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070069import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080070import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070071import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080072import android.os.Handler;
73import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070074import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080075import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070076import android.os.Message;
77import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080078import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -070079import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +010080import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080081import android.os.RemoteException;
82import android.os.ServiceManager;
83import android.os.SystemClock;
84import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080085import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070086import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080087import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070088import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080089import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070090import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040091import android.service.dreams.DreamService;
92import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070093import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -070094import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -070095import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080096import android.util.EventLog;
97import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -070098import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -080099import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700100import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800101import android.view.Gravity;
102import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800103import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800104import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -0700105import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -0700106import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -0800107import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800108import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800109import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -0800110import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800111import android.view.KeyEvent;
112import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800113import android.view.Surface;
114import android.view.View;
115import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800116import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800117import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700118import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800119import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800120import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800121import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800122import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200123import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800124import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800125import com.android.internal.R;
Jason Monk8f7f3182015-11-18 16:35:14 -0500126import com.android.internal.logging.MetricsLogger;
127import com.android.internal.policy.PhoneWindow;
Craig Mautnerae446592012-12-06 19:05:05 -0800128import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700129import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800130import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700131import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700132import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100133import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700134import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Craig Mautnerae446592012-12-06 19:05:05 -0800135
136import java.io.File;
137import java.io.FileReader;
138import java.io.IOException;
139import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700140import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800141import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800142
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800143/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700144 * WindowManagerPolicy implementation for the Android phone UI. This
145 * introduces a new method suffix, Lp, for an internal lock of the
146 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400147 * 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 -0700148 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800149 */
150public class PhoneWindowManager implements WindowManagerPolicy {
151 static final String TAG = "WindowManager";
152 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700153 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700154 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700155 static final boolean DEBUG_KEYGUARD = false;
156 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700157 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700158 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800159 static final boolean SHOW_STARTING_ANIMATIONS = true;
160 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400161
Daniel Sandler6396c722013-04-16 20:19:09 -0400162 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
keunyounga7710492015-09-23 11:33:58 -0700163 // No longer recommended for desk docks;
Daniel Sandler6396c722013-04-16 20:19:09 -0400164 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
165
Jeff Brown6d8fd272014-05-20 21:24:38 -0700166 static final int SHORT_PRESS_POWER_NOTHING = 0;
167 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
168 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
169 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800170 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700171
Joe Onoratod208e702010-10-08 16:22:43 -0400172 static final int LONG_PRESS_POWER_NOTHING = 0;
173 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
174 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700175 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700176
Jeff Brown13f00f02014-10-31 14:45:50 -0700177 static final int MULTI_PRESS_POWER_NOTHING = 0;
178 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
179 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
180
Michael Jurka3b1fc472011-06-13 10:54:40 -0700181 // These need to match the documentation/constant in
182 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800183 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800184 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700185 static final int LONG_PRESS_HOME_ASSIST = 2;
186
187 static final int DOUBLE_TAP_HOME_NOTHING = 0;
188 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800189
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000190 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
191 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
192
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700193 static final int APPLICATION_MEDIA_SUBLAYER = -2;
194 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800195 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800196 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700197 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700198
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800199 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
200 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
201 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500202 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700203 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800204
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700205 /**
206 * These are the system UI flags that, when changing, can cause the layout
207 * of the screen to change.
208 */
209 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400210 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400211 | View.SYSTEM_UI_FLAG_FULLSCREEN
212 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200213 | View.NAVIGATION_BAR_TRANSLUCENT
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800214 | View.STATUS_BAR_TRANSPARENT
215 | View.NAVIGATION_BAR_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700216
John Spurlock7b414672014-07-18 13:02:39 -0400217 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
218 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
219 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
220 .build();
221
Adrian Roosddc8b272015-05-21 16:28:27 -0700222 // The panic gesture may become active only after the keyguard is dismissed and the immersive
223 // app shows again. If that doesn't happen for 30s we drop the gesture.
224 private static final long PANIC_GESTURE_EXPIRATION = 30000;
225
Jim Miller5ecd8112013-01-09 18:50:26 -0800226 /**
227 * Keyguard stuff
228 */
229 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100230 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700231 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800232
Jeff Brown6651a632011-11-28 12:59:11 -0800233 /* Table of Application Launch keys. Maps from key codes to intent categories.
234 *
235 * These are special keys that are used to launch particular kinds of applications,
236 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
237 * usage page. We don't support quite that many yet...
238 */
239 static SparseArray<String> sApplicationLaunchKeyCategories;
240 static {
241 sApplicationLaunchKeyCategories = new SparseArray<String>();
242 sApplicationLaunchKeyCategories.append(
243 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
244 sApplicationLaunchKeyCategories.append(
245 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
246 sApplicationLaunchKeyCategories.append(
247 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
248 sApplicationLaunchKeyCategories.append(
249 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
250 sApplicationLaunchKeyCategories.append(
251 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
252 sApplicationLaunchKeyCategories.append(
253 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
254 }
255
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700256 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700257 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700258
Dianne Hackborndf89e652011-10-06 22:35:11 -0700259 /**
260 * Lock protecting internal state. Must not call out into window
261 * manager with lock held. (This lock will be acquired in places
262 * where the window manager is calling in with its own lock held.)
263 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800264 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700265
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800266 Context mContext;
267 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700268 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700269 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700270 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700271 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700272 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100273 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400274 IStatusBarService mStatusBarService;
Jeff Browncaca8812013-05-09 13:34:33 -0700275 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700276 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800277 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700278 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800279 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000280 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100281 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800282
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700283 // Vibrator pattern for haptic feedback of a long press.
284 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700285
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700286 // Vibrator pattern for haptic feedback of virtual key press.
287 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700288
Amith Yamasanic33cb712010-02-10 15:21:49 -0800289 // Vibrator pattern for a short vibration.
290 long[] mKeyboardTapVibePattern;
291
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700292 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
293 long[] mClockTickVibePattern;
294
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700295 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
296 long[] mCalendarDateVibePattern;
297
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700298 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
299 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700300
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700301 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
302 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700303
Mady Mellore8608912015-06-05 09:02:55 -0700304 // Vibrator pattern for haptic feedback of a context click.
305 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700306
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800307 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
308 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400309
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800310 boolean mSafeMode;
311 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700312 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400313 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400314 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700315 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400316 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
317 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -0800318 int[] mNavigationBarHeightForRotationDefault = new int[4];
319 int[] mNavigationBarWidthForRotationDefault = new int[4];
320 int[] mNavigationBarHeightForRotationInCarMode = new int[4];
321 int[] mNavigationBarWidthForRotationInCarMode = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400322
keunyounga7710492015-09-23 11:33:58 -0700323 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
324 // This is for car dock and this is updated from resource.
325 private boolean mEnableCarDockHomeCapture = true;
326
Craig Mautnera631d492014-08-05 15:16:01 -0700327 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800328 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700329 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700330 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700331 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700332 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
333 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
334 }
335 };
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700336 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700337 @Override
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700338 public void onDrawn() {
339 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700340 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
341 }
342 };
343
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800344 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800345 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900346 WindowState mLastInputMethodWindow = null;
347 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800348
Jeff Brown13f00f02014-10-31 14:45:50 -0700349 // FIXME This state is shared between the input reader and handler thread.
350 // Technically it's broken and buggy but it has been like this for many years
351 // and we have not yet seen any problems. Someday we'll rewrite this logic
352 // so that only one thread is involved in handling input policy. Unfortunately
353 // it's on a critical path for power management so we can't just post the work to the
354 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
355 // to hold wakelocks during dispatch and eliminating the critical path.
356 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800357 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700358 volatile int mPowerKeyPressCounter;
359 volatile boolean mEndCallKeyHandled;
360
Winson Chungd42a6cf2014-06-03 16:24:04 -0700361 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700362 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700363 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800364
Jeff Brown2e7760e2012-04-11 15:14:55 -0700365 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700366 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700367 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800368
Dianne Hackbornc777e072010-02-12 13:07:59 -0800369 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700370 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700371 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800372 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900373 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700374 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400375 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700376 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700377 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400378 int mCarDockRotation;
379 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700380 int mUndockedHdmiRotation;
381 int mDemoHdmiRotation;
382 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800383 int mDemoRotation;
384 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400385
Jeff Browna20dda42014-05-27 20:57:24 -0700386 boolean mWakeGestureEnabledSetting;
387 MyWakeGestureListener mWakeGestureListener;
388
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700389 // Default display does not rotate, apps that require non-default orientation will have to
390 // have the orientation emulated.
391 private boolean mForceDefaultOrientation = false;
392
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400393 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
394 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700395 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400396
Jeff Brownbcdfc622014-03-06 19:13:04 -0800397 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700398 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400399 boolean mCarDockEnablesAccelerometer;
400 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700401 int mLidKeyboardAccessibility;
402 int mLidNavigationAccessibility;
Edward Savage-Jones7def60d2015-11-13 13:27:03 +0100403 boolean mLidControlsScreenLock;
Jeff Brownc458ce92012-04-30 14:58:40 -0700404 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700405 int mShortPressOnPowerBehavior;
406 int mLongPressOnPowerBehavior;
407 int mDoublePressOnPowerBehavior;
408 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000409 int mShortPressOnSleepBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700410 boolean mAwake;
411 boolean mScreenOnEarly;
412 boolean mScreenOnFully;
413 ScreenOnListener mScreenOnListener;
414 boolean mKeyguardDrawComplete;
415 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800416 boolean mOrientationSensorEnabled = false;
417 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800418 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400419 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800420 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700421
Jeff Brown70825162012-03-28 17:27:48 -0700422 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800423
424 // The last window we were told about in focusChanged.
425 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800426 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800427
Jeff Brown70825162012-03-28 17:27:48 -0700428 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800429
Dianne Hackbornc652de82013-02-15 16:32:56 -0800430 // The current size of the screen; really; extends into the overscan area of
431 // the screen and doesn't account for any system elements like the status bar.
432 int mOverscanScreenLeft, mOverscanScreenTop;
433 int mOverscanScreenWidth, mOverscanScreenHeight;
434 // The current visible size of the screen; really; (ir)regardless of whether the status
435 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800436 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
437 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800438 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
439 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
440 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700441 // The current size of the screen; these may be different than (0,0)-(dw,dh)
442 // if the status bar can't be hidden; in that case it effectively carves out
443 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800444 int mRestrictedScreenLeft, mRestrictedScreenTop;
445 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700446 // During layout, the current screen borders accounting for any currently
447 // visible system UI elements.
448 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700449 // For applications requesting stable content insets, these are them.
450 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700451 // For applications requesting stable content insets but have also set the
452 // fullscreen window flag, these are the stable dimensions without the status bar.
453 int mStableFullscreenLeft, mStableFullscreenTop;
454 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800455 // During layout, the current screen borders with all outer decoration
456 // (status bar, input method dock) accounted for.
457 int mCurLeft, mCurTop, mCurRight, mCurBottom;
458 // During layout, the frame in which content should be displayed
459 // to the user, accounting for all screen decoration except for any
460 // space they deem as available for other content. This is usually
461 // the same as mCur*, but may be larger if the screen decor has supplied
462 // content insets.
463 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700464 // During layout, the frame in which voice content should be displayed
465 // to the user, accounting for all screen decoration except for any
466 // space they deem as available for other content.
467 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800468 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800469 // windows are placed.
470 int mDockLeft, mDockTop, mDockRight, mDockBottom;
471 // During layout, the layer at which the doc window is placed.
472 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700473 // During layout, this is the layer of the status bar.
474 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700475 int mLastSystemUiFlags;
476 // Bits that we are in the process of clearing, so we want to prevent
477 // them from being set by applications until everything has been updated
478 // to have them clear.
479 int mResettingSystemUiFlags = 0;
480 // Bits that we are currently always keeping cleared.
481 int mForceClearedSystemUiFlags = 0;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800482 // What we last reported to system UI about whether the compatibility
483 // menu needs to be displayed.
484 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700485 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
486 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700487
Selim Cinekf83e8242015-05-19 18:08:14 -0700488 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700489
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800490 static final Rect mTmpParentFrame = new Rect();
491 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800492 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800493 static final Rect mTmpContentFrame = new Rect();
494 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400495 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700496 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700497 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700498 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700499
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800500 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100501 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700502 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200503 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400504 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800505 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700506 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700507 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700508 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800509 boolean mForcingShowNavBar;
510 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700511
512 // States of keyguard dismiss.
513 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
514 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
515 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
516 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
517
518 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
519 * be done once per window. */
520 private WindowState mWinDismissingKeyguard;
521
tingna_sunge785ffa2015-05-12 13:23:15 +0800522 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
523 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
524 * lock SIM card. This variable is used to record the previous keyguard secure state for
525 * monitoring secure state change on window dismissing keyguard. */
526 private boolean mSecureDismissingKeyguard;
527
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700528 /** The window that is currently showing "over" the keyguard. If there is an app window
529 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
530 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
531 * the wallpaper. */
532 private WindowState mWinShowWhenLocked;
533
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700534 boolean mShowingLockscreen;
535 boolean mShowingDream;
536 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700537 boolean mDreamingSleepTokenNeeded;
538 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700539 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700540 boolean mKeyguardSecure;
541 boolean mKeyguardSecureIncludingHidden;
542 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800543 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700544 boolean mHomeConsumed;
545 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800546 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700547 Intent mCarDockIntent;
548 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700549 boolean mSearchKeyShortcutPending;
550 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700551 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700552 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800553
Mike Lockwood28569302010-01-28 11:54:40 -0500554 // support for activating the lock screen while the screen is on
555 boolean mAllowLockscreenWhenOn;
556 int mLockScreenTimeout;
557 boolean mLockScreenTimerActive;
558
David Brownbaf8d092010-03-08 21:52:59 -0800559 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800560 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800561
562 // Behavior of POWER button while in-call and screen on.
563 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
564 int mIncallPowerBehavior;
565
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700566 Display mDisplay;
567
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700568 private int mDisplayRotation;
569
Dianne Hackborn9d132642011-04-21 17:26:39 -0700570 int mLandscapeRotation = 0; // default landscape rotation
571 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
572 int mPortraitRotation = 0; // default portrait rotation
573 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700574
Dianne Hackbornc652de82013-02-15 16:32:56 -0800575 int mOverscanLeft = 0;
576 int mOverscanTop = 0;
577 int mOverscanRight = 0;
578 int mOverscanBottom = 0;
579
Joe Onorato46b0d682010-11-22 17:37:27 -0800580 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700581 private int mLongPressOnHomeBehavior;
582
583 // What we do when the user double-taps on home
584 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800585
Bryce Lee584a4452014-10-21 15:55:55 -0700586 // Allowed theater mode wake actions
587 private boolean mAllowTheaterModeWakeFromKey;
588 private boolean mAllowTheaterModeWakeFromPowerKey;
589 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800590 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700591 private boolean mAllowTheaterModeWakeFromCameraLens;
592 private boolean mAllowTheaterModeWakeFromLidSwitch;
593 private boolean mAllowTheaterModeWakeFromWakeGesture;
594
Bryce Leed3b28402015-03-09 15:49:13 +0000595 // Whether to support long press from power button in non-interactive mode
596 private boolean mSupportLongPressPowerWhenNonInteractive;
597
Bryce Lee55e846d2014-11-04 12:43:44 -0800598 // Whether to go to sleep entering theater mode from power button
599 private boolean mGoToSleepOnButtonPressTheaterMode;
600
Winson Chung9112ec32011-06-27 13:15:32 -0700601 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700602 // Time to volume and power must be pressed within this interval of each other.
603 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700604 // Increase the chord delay when taking a screenshot from the keyguard
605 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800606 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700607 private boolean mScreenshotChordVolumeDownKeyTriggered;
608 private long mScreenshotChordVolumeDownKeyTime;
609 private boolean mScreenshotChordVolumeDownKeyConsumed;
610 private boolean mScreenshotChordVolumeUpKeyTriggered;
611 private boolean mScreenshotChordPowerKeyTriggered;
612 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700613
Michael Wrightb854e242013-02-05 17:54:02 -0800614 /* The number of steps between min and max brightness */
615 private static final int BRIGHTNESS_STEPS = 10;
616
Christopher Tate5e08af02012-09-21 17:17:22 -0700617 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800618 ShortcutManager mShortcutManager;
619 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700620 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700621 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800622
Craig Mautnerd625ab22013-09-06 13:40:31 -0700623 private int mCurrentUserId;
624
Justin Kohd378ad72013-04-01 12:18:26 -0700625 // Maps global key codes to the components that will handle them.
626 private GlobalKeyManager mGlobalKeyManager;
627
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700628 // Fallback actions by key code.
629 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
630 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800631
Jorim Jaggi76a16232014-08-08 17:00:47 +0200632 private final LogDecelerateInterpolator mLogDecelerateInterpolator
633 = new LogDecelerateInterpolator(100, 0);
634
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800635 private boolean mForceWindowDrawsStatusBarBackground;
636
Jeff Brown70825162012-03-28 17:27:48 -0700637 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
638 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700639 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
640 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700641 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
642 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
643 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700644 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700645 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700646 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700647 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700648 private static final int MSG_POWER_DELAYED_PRESS = 13;
649 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700650 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700651 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
652
653 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
654 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700655
656 private class PolicyHandler extends Handler {
657 @Override
658 public void handleMessage(Message msg) {
659 switch (msg.what) {
660 case MSG_ENABLE_POINTER_LOCATION:
661 enablePointerLocation();
662 break;
663 case MSG_DISABLE_POINTER_LOCATION:
664 disablePointerLocation();
665 break;
Jeff Brown40013652012-05-16 21:22:36 -0700666 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
667 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
668 break;
669 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
670 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
671 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700672 case MSG_DISPATCH_SHOW_RECENTS:
673 showRecentApps(false);
674 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700675 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
676 showGlobalActionsInternal();
677 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700678 case MSG_KEYGUARD_DRAWN_COMPLETE:
679 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700680 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700681 break;
682 case MSG_KEYGUARD_DRAWN_TIMEOUT:
683 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700684 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700685 break;
686 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
687 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700688 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700689 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700690 case MSG_HIDE_BOOT_MESSAGE:
691 handleHideBootMessage();
692 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700693 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
694 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
695 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700696 case MSG_POWER_DELAYED_PRESS:
697 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
698 finishPowerKeyPress();
699 break;
700 case MSG_POWER_LONG_PRESS:
701 powerLongPress();
702 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700703 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
704 updateDreamingSleepToken(msg.arg1 != 0);
705 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700706 case MSG_REQUEST_TRANSIENT_BARS:
707 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
708 mStatusBar : mNavigationBar;
709 if (targetBar != null) {
710 requestTransientBars(targetBar);
711 }
712 break;
Jeff Brown70825162012-03-28 17:27:48 -0700713 }
714 }
715 }
716
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800717 private UEventObserver mHDMIObserver = new UEventObserver() {
718 @Override
719 public void onUEvent(UEventObserver.UEvent event) {
720 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
721 }
722 };
723
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800724 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800725 SettingsObserver(Handler handler) {
726 super(handler);
727 }
David Brownbaf8d092010-03-08 21:52:59 -0800728
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800729 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700730 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800731 ContentResolver resolver = mContext.getContentResolver();
732 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700733 Settings.System.END_BUTTON_BEHAVIOR), false, this,
734 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800735 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700736 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
737 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700738 resolver.registerContentObserver(Settings.Secure.getUriFor(
739 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
740 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800741 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700742 Settings.System.ACCELEROMETER_ROTATION), false, this,
743 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500744 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700745 Settings.System.USER_ROTATION), false, this,
746 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400747 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700748 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
749 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800750 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700751 Settings.System.POINTER_LOCATION), false, this,
752 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800753 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700754 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
755 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500756 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400757 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700758 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500759 resolver.registerContentObserver(Settings.Global.getUriFor(
760 Settings.Global.POLICY_CONTROL), false, this,
761 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800762 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800763 }
764
765 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800766 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700767 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800768 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800769 }
Craig Mautner967212c2013-04-13 21:10:58 -0700770
Jeff Browna20dda42014-05-27 20:57:24 -0700771 class MyWakeGestureListener extends WakeGestureListener {
772 MyWakeGestureListener(Context context, Handler handler) {
773 super(context, handler);
774 }
775
776 @Override
777 public void onWakeUp() {
778 synchronized (mLock) {
779 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700780 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700781 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
782 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700783 }
784 }
785 }
786 }
787
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800788 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700789 private final Runnable mUpdateRotationRunnable = new Runnable() {
790 @Override
791 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700792 // send interaction hint to improve redraw performance
793 mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700794 updateRotation(false);
795 }
796 };
797
Craig Mautnereee29c42013-01-17 14:44:34 -0800798 MyOrientationListener(Context context, Handler handler) {
799 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800800 }
Craig Mautner967212c2013-04-13 21:10:58 -0700801
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800802 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700803 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700804 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700805 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700806 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800807 }
808 MyOrientationListener mOrientationListener;
809
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100810 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400811
John Spurlock27735a42013-08-14 17:57:38 -0400812 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400813 View.NAVIGATION_BAR_TRANSIENT,
814 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400815 View.NAVIGATION_BAR_TRANSLUCENT,
816 StatusBarManager.WINDOW_NAVIGATION_BAR,
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800817 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
818 View.NAVIGATION_BAR_TRANSPARENT);
John Spurlock5b9145b2013-08-20 15:13:47 -0400819
John Spurlockf1a36642013-10-12 17:50:42 -0400820 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400821
Craig Mautner037aa8d2013-06-07 10:35:44 -0700822 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400823
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700824 IStatusBarService getStatusBarService() {
825 synchronized (mServiceAquireLock) {
826 if (mStatusBarService == null) {
827 mStatusBarService = IStatusBarService.Stub.asInterface(
828 ServiceManager.getService("statusbar"));
829 }
830 return mStatusBarService;
831 }
832 }
833
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700834 /*
835 * We always let the sensor be switched on by default except when
836 * the user has explicitly disabled sensor based rotation or when the
837 * screen is switched off.
838 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700839 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800840 if (mSupportAutoRotation) {
841 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
842 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
843 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
844 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
845 // If the application has explicitly requested to follow the
846 // orientation, then we need to turn the sensor on.
847 return true;
848 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800849 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700850 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800851 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
852 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
853 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400854 // enable accelerometer if we are docked in a dock that enables accelerometer
855 // orientation management,
856 return true;
857 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700858 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800859 // If the setting for using the sensor by default is enabled, then
860 // we will always leave it on. Note that the user could go to
861 // a window that forces an orientation that does not use the
862 // sensor and in theory we could turn it off... however, when next
863 // turning it on we won't have a good value for the current
864 // orientation for a little bit, which can cause orientation
865 // changes to lag, so we'd like to keep it always on. (It will
866 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700867 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800868 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800869 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800870 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700871
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800872 /*
873 * Various use cases for invoking this function
874 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700875 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800876 * if not already enabled
877 * screen turned on and current app does not have sensor orientation, disable listeners if
878 * already enabled
879 * screen turning on and current app has sensor based orientation, enable listeners if needed
880 * screen turning on and current app has nosensor based orientation, do nothing
881 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700882 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800883 if (!mOrientationListener.canDetectOrientation()) {
884 // If sensor is turned off or nonexistent for some reason
885 return;
886 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000887 // Could have been invoked due to screen turning on or off or
888 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700889 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
890 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000891 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
892 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
893 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800894 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000895 // Note: We postpone the rotating of the screen until the keyguard as well as the
896 // window manager have reported a draw complete.
897 if (mScreenOnEarly && mAwake &&
898 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700899 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800900 disable = false;
901 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700902 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800903 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700904 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800905 mOrientationSensorEnabled = true;
906 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700907 }
908 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800909 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700910 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800911 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700912 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800913 mOrientationSensorEnabled = false;
914 }
915 }
916
Jeff Brown13f00f02014-10-31 14:45:50 -0700917 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
918 // Hold a wake lock until the power key is released.
919 if (!mPowerKeyWakeLock.isHeld()) {
920 mPowerKeyWakeLock.acquire();
921 }
922
923 // Cancel multi-press detection timeout.
924 if (mPowerKeyPressCounter != 0) {
925 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
926 }
927
928 // Detect user pressing the power button in panic when an application has
929 // taken over the whole screen.
930 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800931 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700932 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700933 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700934 }
935
936 // Latch power key state to detect screenshot chord.
937 if (interactive && !mScreenshotChordPowerKeyTriggered
938 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
939 mScreenshotChordPowerKeyTriggered = true;
940 mScreenshotChordPowerKeyTime = event.getDownTime();
941 interceptScreenshotChord();
942 }
943
944 // Stop ringing or end call if configured to do so when power is pressed.
945 TelecomManager telecomManager = getTelecommService();
946 boolean hungUp = false;
947 if (telecomManager != null) {
948 if (telecomManager.isRinging()) {
949 // Pressing Power while there's a ringing incoming
950 // call should silence the ringer.
951 telecomManager.silenceRinger();
952 } else if ((mIncallPowerBehavior
953 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
954 && telecomManager.isInCall() && interactive) {
955 // Otherwise, if "Power button ends call" is enabled,
956 // the Power button will hang up any current active call.
957 hungUp = telecomManager.endCall();
958 }
959 }
960
Adrian Roos5941c982015-09-03 15:59:49 -0700961 GestureLauncherService gestureService = LocalServices.getService(
962 GestureLauncherService.class);
963 boolean gesturedServiceIntercepted = false;
964 if (gestureService != null) {
965 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive);
966 }
967
Jeff Brown13f00f02014-10-31 14:45:50 -0700968 // If the power key has still not yet been handled, then detect short
969 // press, long press, or multi press and decide what to do.
970 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -0700971 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -0700972 if (!mPowerKeyHandled) {
973 if (interactive) {
974 // When interactive, we're already awake.
975 // Wait for a long press or for the button to be released to decide what to do.
976 if (hasLongPressOnPowerBehavior()) {
977 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
978 msg.setAsynchronous(true);
979 mHandler.sendMessageDelayed(msg,
980 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
981 }
982 } else {
Bryce Leed9268e32014-11-17 17:40:59 -0800983 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -0800984
Bryce Leed3b28402015-03-09 15:49:13 +0000985 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
986 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
987 msg.setAsynchronous(true);
988 mHandler.sendMessageDelayed(msg,
989 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -0800990 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +0000991 } else {
992 final int maxCount = getMaxMultiPressPowerCount();
993
994 if (maxCount <= 1) {
995 mPowerKeyHandled = true;
996 } else {
997 mBeganFromNonInteractive = true;
998 }
Jeff Brown13f00f02014-10-31 14:45:50 -0700999 }
1000 }
Jeff Brown4d396052010-10-29 21:50:21 -07001001 }
1002 }
1003
Jeff Brown13f00f02014-10-31 14:45:50 -07001004 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
1005 final boolean handled = canceled || mPowerKeyHandled;
1006 mScreenshotChordPowerKeyTriggered = false;
1007 cancelPendingScreenshotChordAction();
1008 cancelPendingPowerKeyAction();
1009
1010 if (!handled) {
1011 // Figure out how to handle the key now that it has been released.
1012 mPowerKeyPressCounter += 1;
1013
1014 final int maxCount = getMaxMultiPressPowerCount();
1015 final long eventTime = event.getDownTime();
1016 if (mPowerKeyPressCounter < maxCount) {
1017 // This could be a multi-press. Wait a little bit longer to confirm.
1018 // Continue holding the wake lock.
1019 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1020 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1021 msg.setAsynchronous(true);
1022 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1023 return;
1024 }
1025
1026 // No other actions. Handle it immediately.
1027 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001028 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001029
1030 // Done. Reset our state.
1031 finishPowerKeyPress();
1032 }
1033
1034 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001035 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001036 mPowerKeyPressCounter = 0;
1037 if (mPowerKeyWakeLock.isHeld()) {
1038 mPowerKeyWakeLock.release();
1039 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001040 }
1041
1042 private void cancelPendingPowerKeyAction() {
1043 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001044 mPowerKeyHandled = true;
1045 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001046 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001047 }
1048
1049 private void powerPress(long eventTime, boolean interactive, int count) {
1050 if (mScreenOnEarly && !mScreenOnFully) {
1051 Slog.i(TAG, "Suppressed redundant power key press while "
1052 + "already in the process of turning the screen on.");
1053 return;
Jeff Brownff204712011-10-25 21:27:54 -07001054 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001055
1056 if (count == 2) {
1057 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1058 } else if (count == 3) {
1059 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001060 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001061 switch (mShortPressOnPowerBehavior) {
1062 case SHORT_PRESS_POWER_NOTHING:
1063 break;
1064 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1065 mPowerManager.goToSleep(eventTime,
1066 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1067 break;
1068 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1069 mPowerManager.goToSleep(eventTime,
1070 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1071 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1072 break;
1073 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1074 mPowerManager.goToSleep(eventTime,
1075 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1076 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1077 launchHomeFromHotKey();
1078 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001079 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001080 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001081 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001082 }
1083 }
1084 }
1085
1086 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1087 switch (behavior) {
1088 case MULTI_PRESS_POWER_NOTHING:
1089 break;
1090 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001091 if (!isUserSetupComplete()) {
1092 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1093 break;
1094 }
1095
Jeff Brown13f00f02014-10-31 14:45:50 -07001096 if (isTheaterModeEnabled()) {
1097 Slog.i(TAG, "Toggling theater mode off.");
1098 Settings.Global.putInt(mContext.getContentResolver(),
1099 Settings.Global.THEATER_MODE_ON, 0);
1100 if (!interactive) {
1101 wakeUpFromPowerKey(eventTime);
1102 }
1103 } else {
1104 Slog.i(TAG, "Toggling theater mode on.");
1105 Settings.Global.putInt(mContext.getContentResolver(),
1106 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001107
1108 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001109 mPowerManager.goToSleep(eventTime,
1110 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1111 }
1112 }
1113 break;
1114 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001115 Slog.i(TAG, "Starting brightness boost.");
1116 if (!interactive) {
1117 wakeUpFromPowerKey(eventTime);
1118 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001119 mPowerManager.boostScreenBrightness(eventTime);
1120 break;
1121 }
1122 }
1123
1124 private int getMaxMultiPressPowerCount() {
1125 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1126 return 3;
1127 }
1128 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1129 return 2;
1130 }
1131 return 1;
1132 }
1133
1134 private void powerLongPress() {
1135 final int behavior = getResolvedLongPressOnPowerBehavior();
1136 switch (behavior) {
1137 case LONG_PRESS_POWER_NOTHING:
1138 break;
1139 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1140 mPowerKeyHandled = true;
1141 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1142 performAuditoryFeedbackForAccessibilityIfNeed();
1143 }
1144 showGlobalActionsInternal();
1145 break;
1146 case LONG_PRESS_POWER_SHUT_OFF:
1147 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1148 mPowerKeyHandled = true;
1149 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1150 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1151 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1152 break;
1153 }
1154 }
1155
Nick Vaccarob593a812015-05-15 11:23:05 -07001156 private void sleepPress(long eventTime) {
1157 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1158 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1159 }
1160 }
1161
1162 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001163 switch (mShortPressOnSleepBehavior) {
1164 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001165 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001166 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1167 mPowerManager.goToSleep(eventTime,
1168 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001169 break;
1170 }
1171 }
1172
Jeff Brown13f00f02014-10-31 14:45:50 -07001173 private int getResolvedLongPressOnPowerBehavior() {
1174 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1175 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1176 }
1177 return mLongPressOnPowerBehavior;
1178 }
1179
1180 private boolean hasLongPressOnPowerBehavior() {
1181 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001182 }
1183
1184 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001185 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001186 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1187 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001188 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001189 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1190 && now <= mScreenshotChordPowerKeyTime
1191 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1192 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001193 cancelPendingPowerKeyAction();
1194
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001195 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001196 }
1197 }
1198 }
1199
Winson Chung1cea2f32012-10-08 20:42:01 -07001200 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001201 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001202 // Double the time it takes to take a screenshot from the keyguard
1203 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001204 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001205 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001206 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001207 }
1208
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001209 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001210 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001211 }
1212
Jeff Brown13f00f02014-10-31 14:45:50 -07001213 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001214 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001215 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001216 mEndCallKeyHandled = true;
1217 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1218 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001219 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001220 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001221 }
1222 };
1223
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001224 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001225 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001226 public void run() {
1227 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001228 }
1229 };
1230
Alan Viverettee34560b22014-07-10 14:50:06 -07001231 @Override
1232 public void showGlobalActions() {
1233 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1234 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1235 }
1236
1237 void showGlobalActionsInternal() {
1238 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001239 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001240 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001241 }
Jim Millerab954542014-10-10 18:21:49 -07001242 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001243 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1244 if (keyguardShowing) {
1245 // since it took two seconds of long press to bring this up,
1246 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001247 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001248 }
1249 }
1250
1251 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001252 return Settings.Global.getInt(
1253 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001254 }
1255
Maurice Lam99c6e072014-04-28 18:24:28 -07001256 boolean isUserSetupComplete() {
1257 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1258 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1259 }
1260
Jeff Brown13f00f02014-10-31 14:45:50 -07001261 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001262 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1263 getHdmiControl().turnOnTv();
1264
Jeff Brown13f00f02014-10-31 14:45:50 -07001265 // If there's a dream running then use home to escape the dream
1266 // but don't actually go home.
1267 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1268 mDreamManagerInternal.stopDream(false /*immediate*/);
1269 return;
1270 }
1271
1272 // Go home!
1273 launchHomeFromHotKey();
1274 }
1275
Jinsuk Kime601b712015-07-07 08:01:02 +09001276 /**
1277 * Creates an accessor to HDMI control service that performs the operation of
1278 * turning on TV (optional) and switching input to us. If HDMI control service
1279 * is not available or we're not a HDMI playback device, the operation is no-op.
1280 */
1281 private HdmiControl getHdmiControl() {
1282 if (null == mHdmiControl) {
1283 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1284 Context.HDMI_CONTROL_SERVICE);
1285 HdmiPlaybackClient client = null;
1286 if (manager != null) {
1287 client = manager.getPlaybackClient();
1288 }
1289 mHdmiControl = new HdmiControl(client);
1290 }
1291 return mHdmiControl;
1292 }
1293
1294 private static class HdmiControl {
1295 private final HdmiPlaybackClient mClient;
1296
1297 private HdmiControl(HdmiPlaybackClient client) {
1298 mClient = client;
1299 }
1300
1301 public void turnOnTv() {
1302 if (mClient == null) {
1303 return;
1304 }
1305 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1306 @Override
1307 public void onComplete(int result) {
1308 if (result != HdmiControlManager.RESULT_SUCCESS) {
1309 Log.w(TAG, "One touch play failed: " + result);
1310 }
1311 }
1312 });
1313 }
1314 }
1315
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001316 private void handleLongPressOnHome(int deviceId) {
Joe Onorato46b0d682010-11-22 17:37:27 -08001317 if (mLongPressOnHomeBehavior != LONG_PRESS_HOME_NOTHING) {
Jeff Browncaca8812013-05-09 13:34:33 -07001318 mHomeConsumed = true;
Joe Onorato46b0d682010-11-22 17:37:27 -08001319 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001320
Jeff Browncaca8812013-05-09 13:34:33 -07001321 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI) {
1322 toggleRecentApps();
1323 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_ASSIST) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001324 launchAssistAction(null, deviceId);
Jim Millere6ad1a82010-08-20 19:25:39 -07001325 }
1326 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001327 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001328
Jeff Browncaca8812013-05-09 13:34:33 -07001329 private void handleDoubleTapOnHome() {
1330 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1331 mHomeConsumed = true;
1332 toggleRecentApps();
1333 }
1334 }
1335
1336 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1337 @Override
1338 public void run() {
1339 if (mHomeDoubleTapPending) {
1340 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001341 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001342 }
1343 }
1344 };
1345
Mark Renoufc1256912015-03-11 14:38:23 -04001346 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001347 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001348 }
1349
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001350 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001351 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001352 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001353 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001354 mContext = context;
1355 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001356 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001357 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001358 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001359 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001360 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001361 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001362
1363 // Init display burn-in protection
1364 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1365 com.android.internal.R.bool.config_enableBurnInProtection);
1366 // Allow a system property to override this. Used by developer settings.
1367 boolean burnInProtectionDevMode =
1368 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1369 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1370 final int minHorizontal;
1371 final int maxHorizontal;
1372 final int minVertical;
1373 final int maxVertical;
1374 final int maxRadius;
1375 if (burnInProtectionDevMode) {
1376 minHorizontal = -8;
1377 maxHorizontal = 8;
1378 minVertical = -8;
1379 maxVertical = -4;
1380 maxRadius = (isRoundWindow()) ? 6 : -1;
1381 } else {
1382 Resources resources = context.getResources();
1383 minHorizontal = resources.getInteger(
1384 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1385 maxHorizontal = resources.getInteger(
1386 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1387 minVertical = resources.getInteger(
1388 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1389 maxVertical = resources.getInteger(
1390 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1391 maxRadius = resources.getInteger(
1392 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1393 }
1394 mBurnInProtectionHelper = new BurnInProtectionHelper(
1395 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001396 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001397
Jeff Brown70825162012-03-28 17:27:48 -07001398 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001399 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001400 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001401 try {
1402 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1403 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001404 mSettingsObserver = new SettingsObserver(mHandler);
1405 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001406 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001407 mUiMode = context.getResources().getInteger(
1408 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001409 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1410 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1411 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1412 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001413 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1414 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001415 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1416 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1417 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1418 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1419 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1420 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1421 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1422 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001423
Jeff Brown96307042012-07-27 15:51:34 -07001424 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1425 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001426 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001427 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1428 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001429 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001430 mSupportAutoRotation = mContext.getResources().getBoolean(
1431 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001432 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001433 com.android.internal.R.integer.config_lidOpenRotation);
1434 mCarDockRotation = readRotation(
1435 com.android.internal.R.integer.config_carDockRotation);
1436 mDeskDockRotation = readRotation(
1437 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001438 mUndockedHdmiRotation = readRotation(
1439 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001440 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1441 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1442 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1443 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001444 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1445 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1446 mLidNavigationAccessibility = mContext.getResources().getInteger(
1447 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001448 mLidControlsScreenLock = mContext.getResources().getBoolean(
1449 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001450 mLidControlsSleep = mContext.getResources().getBoolean(
1451 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001452 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1453 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001454
1455 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1456 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1457 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1458 || mContext.getResources().getBoolean(
1459 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1460 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1461 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001462 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1463 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001464 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1465 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1466 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1467 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1468 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1469 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1470
Bryce Lee55e846d2014-11-04 12:43:44 -08001471 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1472 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1473
Bryce Leed3b28402015-03-09 15:49:13 +00001474 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1475 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1476
Jeff Brown13f00f02014-10-31 14:45:50 -07001477 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1478 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1479 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1480 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1481 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1482 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1483 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1484 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001485 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1486 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001487
John Spurlock61560172015-02-06 19:46:04 -05001488 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001489
Jeff Brownf71343d2013-05-31 17:59:11 -07001490 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001491
Svetoslav8e3feb12014-02-24 13:46:47 -08001492 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1493 Context.ACCESSIBILITY_SERVICE);
1494
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001495 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001496 IntentFilter filter = new IntentFilter();
1497 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1498 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1499 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1500 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001501 filter.addAction(Intent.ACTION_DOCK_EVENT);
1502 Intent intent = context.registerReceiver(mDockReceiver, filter);
1503 if (intent != null) {
1504 // Retrieve current sticky dock event broadcast.
1505 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1506 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1507 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001508
Jeff Brown6aaf2952012-10-05 16:01:08 -07001509 // register for dream-related broadcasts
1510 filter = new IntentFilter();
1511 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1512 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1513 context.registerReceiver(mDreamReceiver, filter);
1514
Christopher Tate5e08af02012-09-21 17:17:22 -07001515 // register for multiuser-relevant broadcasts
1516 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1517 context.registerReceiver(mMultiuserReceiver, filter);
1518
John Spurlock57306e62013-04-22 09:48:49 -04001519 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001520 mSystemGestures = new SystemGesturesPointerEventListener(context,
1521 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001522 @Override
1523 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001524 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001525 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001526 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001527 }
1528 @Override
1529 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001530 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001531 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001532 }
1533 }
1534 @Override
1535 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001536 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001537 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001538 }
1539 }
1540 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001541 public void onFling(int duration) {
1542 if (mPowerManagerInternal != null) {
1543 mPowerManagerInternal.powerHint(
1544 PowerManagerInternal.POWER_HINT_INTERACTION, duration);
1545 }
1546 }
1547 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001548 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001549 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001550 }
Adrian Roos3595be42015-03-05 16:31:15 +01001551 @Override
1552 public void onDown() {
1553 mOrientationListener.onTouchStart();
1554 }
1555 @Override
1556 public void onUpOrCancel() {
1557 mOrientationListener.onTouchEnd();
1558 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001559 @Override
1560 public void onMouseHoverAtTop() {
1561 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1562 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1563 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1564 mHandler.sendMessageDelayed(msg, 500);
1565 }
1566 @Override
1567 public void onMouseHoverAtBottom() {
1568 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1569 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1570 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1571 mHandler.sendMessageDelayed(msg, 500);
1572 }
1573 @Override
1574 public void onMouseLeaveFromEdge() {
1575 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1576 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001577 });
John Spurlockf1a36642013-10-12 17:50:42 -04001578 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001579 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001580
Jeff Brownc2346132012-04-13 01:55:38 -07001581 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001582 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1583 com.android.internal.R.array.config_longPressVibePattern);
1584 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1585 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001586 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1587 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001588 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1589 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001590 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1591 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001592 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1593 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1594 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1595 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001596 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1597 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001598
Christopher Tatee90585f2012-03-05 18:56:25 -08001599 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1600 com.android.internal.R.bool.config_enableScreenshotChord);
Jorim Jaggi406585a2015-12-21 10:58:56 +01001601 mForceWindowDrawsStatusBarBackground = mContext.getResources().getBoolean(
1602 R.bool.config_forceWindowDrawsStatusBarBackground);
Christopher Tatee90585f2012-03-05 18:56:25 -08001603
Justin Kohd378ad72013-04-01 12:18:26 -07001604 mGlobalKeyManager = new GlobalKeyManager(mContext);
1605
Joe Onoratoea495d42011-04-06 11:41:11 -07001606 // Controls rotation and the like.
1607 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001608
1609 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001610 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001611 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1612 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001613 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001614
1615 mWindowManagerInternal.registerAppTransitionListener(
1616 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001617 }
1618
Jeff Brownf71343d2013-05-31 17:59:11 -07001619 /**
1620 * Read values from config.xml that may be overridden depending on
1621 * the configuration of the device.
1622 * eg. Disable long press on home goes to recents on sw600dp.
1623 */
1624 private void readConfigurationDependentBehaviors() {
1625 mLongPressOnHomeBehavior = mContext.getResources().getInteger(
1626 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1627 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
1628 mLongPressOnHomeBehavior > LONG_PRESS_HOME_ASSIST) {
1629 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1630 }
1631
1632 mDoubleTapOnHomeBehavior = mContext.getResources().getInteger(
1633 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1634 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1635 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1636 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1637 }
1638 }
1639
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001640 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001641 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001642 // This method might be called before the policy has been fully initialized
1643 // or for other displays we don't care about.
1644 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1645 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001646 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001647 mDisplay = display;
1648
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001649 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001650 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001651 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001652 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001653 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001654 mLandscapeRotation = Surface.ROTATION_0;
1655 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001656 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001657 mPortraitRotation = Surface.ROTATION_90;
1658 mUpsideDownRotation = Surface.ROTATION_270;
1659 } else {
1660 mPortraitRotation = Surface.ROTATION_270;
1661 mUpsideDownRotation = Surface.ROTATION_90;
1662 }
1663 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001664 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001665 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001666 mPortraitRotation = Surface.ROTATION_0;
1667 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001668 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001669 mLandscapeRotation = Surface.ROTATION_270;
1670 mSeascapeRotation = Surface.ROTATION_90;
1671 } else {
1672 mLandscapeRotation = Surface.ROTATION_90;
1673 mSeascapeRotation = Surface.ROTATION_270;
1674 }
1675 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001676
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001677 mStatusBarHeight =
1678 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001679
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001680 // Height of the navigation bar when presented horizontally at bottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001681 mNavigationBarHeightForRotationDefault[mPortraitRotation] =
1682 mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001683 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001684 mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
1685 mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001686 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001687
1688 // Width of the navigation bar when presented vertically along one side
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001689 mNavigationBarWidthForRotationDefault[mPortraitRotation] =
1690 mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
1691 mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
1692 mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001693 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001694
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001695 // Height of the navigation bar when presented horizontally at bottom
1696 mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
1697 mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
1698 res.getDimensionPixelSize(
1699 com.android.internal.R.dimen.navigation_bar_height_car_mode);
1700 mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
1701 mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
1702 com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
1703
1704 // Width of the navigation bar when presented vertically along one side
1705 mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
1706 mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
1707 mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
1708 mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
1709 res.getDimensionPixelSize(
1710 com.android.internal.R.dimen.navigation_bar_width_car_mode);
1711
Daniel Sandler4a066c52012-04-20 14:49:13 -04001712 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001713 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001714 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001715
Devin Kimd7b12b42014-05-05 14:34:58 -07001716 // Allow the navigation bar to move on non-square small devices (phones).
1717 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001718
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001719 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001720 // Allow a system property to override this. Used by the emulator.
1721 // See also hasNavigationBar().
1722 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1723 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001724 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001725 } else if ("0".equals(navBarOverride)) {
1726 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001727 }
1728
Jeff Brown27f1d672012-10-17 18:32:34 -07001729 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1730 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001731 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001732 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001733 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001734 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001735 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001736 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001737
Chong Zhangae6119ff2014-11-11 18:54:39 -08001738 // For demo purposes, allow the rotation of the remote display to be controlled.
1739 // By default, remote display locks rotation to landscape.
1740 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1741 mDemoRotation = mPortraitRotation;
1742 } else {
1743 mDemoRotation = mLandscapeRotation;
1744 }
1745 mDemoRotationLock = SystemProperties.getBoolean(
1746 "persist.demo.rotationlock", false);
1747
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001748 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1749 // http://developer.android.com/guide/practices/screens_support.html#range
1750 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1751 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1752 // For debug purposes the next line turns this feature off with:
1753 // $ adb shell setprop config.override_forced_orient true
1754 // $ adb shell wm size reset
1755 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1756 }
1757
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001758 /**
1759 * @return whether the navigation bar can be hidden, e.g. the device has a
1760 * navigation bar and touch exploration is not enabled
1761 */
1762 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04001763 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001764 }
1765
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001766 @Override
1767 public boolean isDefaultOrientationForced() {
1768 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001769 }
1770
Dianne Hackbornc652de82013-02-15 16:32:56 -08001771 @Override
1772 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1773 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1774 mOverscanLeft = left;
1775 mOverscanTop = top;
1776 mOverscanRight = right;
1777 mOverscanBottom = bottom;
1778 }
1779 }
1780
Dianne Hackbornc777e072010-02-12 13:07:59 -08001781 public void updateSettings() {
1782 ContentResolver resolver = mContext.getContentResolver();
1783 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001784 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001785 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001786 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001787 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1788 UserHandle.USER_CURRENT);
1789 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001790 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001791 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1792 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001793
Jeff Browna20dda42014-05-27 20:57:24 -07001794 // Configure wake gesture.
1795 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1796 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1797 UserHandle.USER_CURRENT) != 0;
1798 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1799 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1800 updateWakeGestureListenerLp();
1801 }
1802
Jeff Brown207673cd2012-06-05 17:47:11 -07001803 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001804 int userRotation = Settings.System.getIntForUser(resolver,
1805 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1806 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001807 if (mUserRotation != userRotation) {
1808 mUserRotation = userRotation;
1809 updateRotation = true;
1810 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001811 int userRotationMode = Settings.System.getIntForUser(resolver,
1812 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001813 WindowManagerPolicy.USER_ROTATION_FREE :
1814 WindowManagerPolicy.USER_ROTATION_LOCKED;
1815 if (mUserRotationMode != userRotationMode) {
1816 mUserRotationMode = userRotationMode;
1817 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001818 updateOrientationListenerLp();
1819 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001820
Dianne Hackbornc777e072010-02-12 13:07:59 -08001821 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001822 int pointerLocation = Settings.System.getIntForUser(resolver,
1823 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001824 if (mPointerLocationMode != pointerLocation) {
1825 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001826 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1827 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001828 }
1829 }
1830 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001831 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1832 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1833 String imId = Settings.Secure.getStringForUser(resolver,
1834 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001835 boolean hasSoftInput = imId != null && imId.length() > 0;
1836 if (mHasSoftInput != hasSoftInput) {
1837 mHasSoftInput = hasSoftInput;
1838 updateRotation = true;
1839 }
John Spurlockf1a36642013-10-12 17:50:42 -04001840 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001841 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001842 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001843 }
1844 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001845 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001846 }
1847 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001848 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001849 }
Jeff Brown70825162012-03-28 17:27:48 -07001850 }
1851
Jeff Browna20dda42014-05-27 20:57:24 -07001852 private void updateWakeGestureListenerLp() {
1853 if (shouldEnableWakeGestureLp()) {
1854 mWakeGestureListener.requestWakeUpTrigger();
1855 } else {
1856 mWakeGestureListener.cancelWakeUpTrigger();
1857 }
1858 }
1859
1860 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001861 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001862 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1863 && mWakeGestureListener.isSupported();
1864 }
1865
Jeff Brown70825162012-03-28 17:27:48 -07001866 private void enablePointerLocation() {
1867 if (mPointerLocationView == null) {
1868 mPointerLocationView = new PointerLocationView(mContext);
1869 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001870 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1871 WindowManager.LayoutParams.MATCH_PARENT,
1872 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001873 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001874 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1875 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1876 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1877 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001878 if (ActivityManager.isHighEndGfx()) {
1879 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1880 lp.privateFlags |=
1881 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1882 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001883 lp.format = PixelFormat.TRANSLUCENT;
1884 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001885 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001886 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001887 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001888 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001889 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001890 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001891 }
Jeff Brown70825162012-03-28 17:27:48 -07001892
1893 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001894 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001895 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1896 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001897 wm.removeView(mPointerLocationView);
1898 mPointerLocationView = null;
1899 }
1900 }
1901
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001902 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001903 try {
1904 int rotation = mContext.getResources().getInteger(resID);
1905 switch (rotation) {
1906 case 0:
1907 return Surface.ROTATION_0;
1908 case 90:
1909 return Surface.ROTATION_90;
1910 case 180:
1911 return Surface.ROTATION_180;
1912 case 270:
1913 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001914 }
1915 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001916 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001917 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001918 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001919 }
1920
1921 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001922 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001923 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001924 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001925
1926 outAppOp[0] = AppOpsManager.OP_NONE;
1927
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001928 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
1929 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
1930 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
1931 return WindowManagerGlobal.ADD_INVALID_TYPE;
1932 }
1933
1934 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
1935 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07001936 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001937 }
1938 String permission = null;
1939 switch (type) {
1940 case TYPE_TOAST:
1941 // XXX right now the app process has complete control over
1942 // this... should introduce a token to let the system
1943 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04001944 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001945 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05001946 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001947 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001948 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07001949 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07001950 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07001951 case TYPE_ACCESSIBILITY_OVERLAY:
Jason Monk8f7f3182015-11-18 16:35:14 -05001952 case TYPE_QS_DIALOG:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07001953 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001954 break;
1955 case TYPE_PHONE:
1956 case TYPE_PRIORITY_PHONE:
1957 case TYPE_SYSTEM_ALERT:
1958 case TYPE_SYSTEM_ERROR:
1959 case TYPE_SYSTEM_OVERLAY:
1960 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001961 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001962 break;
1963 default:
1964 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
1965 }
1966 if (permission != null) {
Billy Laucbe540f2015-06-25 01:51:44 +01001967 if (permission == android.Manifest.permission.SYSTEM_ALERT_WINDOW) {
1968 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01001969 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01001970 if (callingUid == Process.SYSTEM_UID) {
1971 return WindowManagerGlobal.ADD_OKAY;
1972 }
1973
Billy Lau060275f2015-07-15 22:29:19 +01001974 // check if user has enabled this operation. SecurityException will be thrown if
1975 // this app has not been allowed by the user
Billy Laucbe540f2015-06-25 01:51:44 +01001976 final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid,
1977 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01001978 switch (mode) {
1979 case AppOpsManager.MODE_ALLOWED:
1980 case AppOpsManager.MODE_IGNORED:
1981 // although we return ADD_OKAY for MODE_IGNORED, the added window will
1982 // actually be hidden in WindowManagerService
1983 return WindowManagerGlobal.ADD_OKAY;
1984 case AppOpsManager.MODE_ERRORED:
Billy Laucbe540f2015-06-25 01:51:44 +01001985 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01001986 default:
1987 // in the default mode, we will make a decision here based on
1988 // checkCallingPermission()
1989 if (mContext.checkCallingPermission(permission) !=
1990 PackageManager.PERMISSION_GRANTED) {
1991 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
1992 } else {
1993 return WindowManagerGlobal.ADD_OKAY;
1994 }
Billy Laucbe540f2015-06-25 01:51:44 +01001995 }
Billy Laucbe540f2015-06-25 01:51:44 +01001996 }
1997
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001998 if (mContext.checkCallingOrSelfPermission(permission)
1999 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07002000 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002001 }
2002 }
Jeff Brown98365d72012-08-19 20:30:52 -07002003 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002004 }
Craig Mautner88400d32012-09-30 12:35:45 -07002005
2006 @Override
2007 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
2008
2009 // If this switch statement is modified, modify the comment in the declarations of
2010 // the type in {@link WindowManager.LayoutParams} as well.
2011 switch (attrs.type) {
2012 default:
2013 // These are the windows that by default are shown only to the user that created
2014 // them. If this needs to be overridden, set
2015 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
2016 // {@link WindowManager.LayoutParams}. Note that permission
2017 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
2018 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
2019 return true;
2020 }
2021 break;
2022
2023 // These are the windows that by default are shown to all users. However, to
2024 // protect against spoofing, check permissions below.
2025 case TYPE_APPLICATION_STARTING:
2026 case TYPE_BOOT_PROGRESS:
2027 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07002028 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08002029 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07002030 case TYPE_KEYGUARD_DIALOG:
2031 case TYPE_MAGNIFICATION_OVERLAY:
2032 case TYPE_NAVIGATION_BAR:
2033 case TYPE_NAVIGATION_BAR_PANEL:
2034 case TYPE_PHONE:
2035 case TYPE_POINTER:
2036 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002037 case TYPE_SEARCH_BAR:
2038 case TYPE_STATUS_BAR:
2039 case TYPE_STATUS_BAR_PANEL:
2040 case TYPE_STATUS_BAR_SUB_PANEL:
2041 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002042 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07002043 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002044 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002045 break;
2046 }
2047
2048 // Check if third party app has set window to system window type.
2049 return mContext.checkCallingOrSelfPermission(
2050 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
2051 != PackageManager.PERMISSION_GRANTED;
2052 }
2053
Craig Mautner967212c2013-04-13 21:10:58 -07002054 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002055 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2056 switch (attrs.type) {
2057 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002058 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002059 // These types of windows can't receive input events.
2060 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2061 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002062 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002063 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002064 case TYPE_STATUS_BAR:
2065
2066 // If the Keyguard is in a hidden state (occluded by another window), we force to
2067 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2068 // the keyguard as occluded wouldn't set these flags again.
2069 // See {@link #processKeyguardSetHiddenResultLw}.
2070 if (mKeyguardHidden) {
2071 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2072 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2073 }
2074 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002075 }
Adrian Roos38502112014-04-09 21:04:11 +02002076
2077 if (attrs.type != TYPE_STATUS_BAR) {
2078 // The status bar is the only window allowed to exhibit keyguard behavior.
2079 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2080 }
Adrian Roosea562512014-05-05 13:33:03 +02002081
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002082 if (ActivityManager.isHighEndGfx()) {
2083 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
2084 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2085 }
2086 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
Jorim Jaggi406585a2015-12-21 10:58:56 +01002087 || (mForceWindowDrawsStatusBarBackground
2088 && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT)) {
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002089 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
2090 }
Adrian Roosea562512014-05-05 13:33:03 +02002091 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002092 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002093
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002094 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002095 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002096 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002097
Michael Wright3818c922014-09-02 13:59:07 -07002098 private void readCameraLensCoverState() {
2099 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2100 }
2101
Jeff Browndaa37532012-05-01 15:54:03 -07002102 private boolean isHidden(int accessibilityMode) {
2103 switch (accessibilityMode) {
2104 case 1:
2105 return mLidState == LID_CLOSED;
2106 case 2:
2107 return mLidState == LID_OPEN;
2108 default:
2109 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002110 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002111 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002112
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002113 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002114 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002115 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2116 int navigationPresence) {
2117 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2118
Jeff Brownf71343d2013-05-31 17:59:11 -07002119 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002120 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07002121 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002122
Jeff Browndaa37532012-05-01 15:54:03 -07002123 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2124 || (keyboardPresence == PRESENCE_INTERNAL
2125 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002126 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002127 if (!mHasSoftInput) {
2128 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2129 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002130 }
2131
Jeff Browndaa37532012-05-01 15:54:03 -07002132 if (config.navigation == Configuration.NAVIGATION_NONAV
2133 || (navigationPresence == PRESENCE_INTERNAL
2134 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002135 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002136 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002137 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002138
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002139 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002140 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002141 public int windowTypeToLayerLw(int type) {
2142 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002143 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002144 }
2145 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07002146 case TYPE_PRIVATE_PRESENTATION:
2147 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002148 case TYPE_WALLPAPER:
2149 // wallpaper is at the bottom, though the window manager may move it.
2150 return 2;
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002151 case TYPE_DOCK_DIVIDER:
2152 return 2;
Jason Monk8f7f3182015-11-18 16:35:14 -05002153 case TYPE_QS_DIALOG:
2154 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002155 case TYPE_PHONE:
2156 return 3;
2157 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002158 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002159 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002160 case TYPE_VOICE_INTERACTION:
2161 // voice interaction layer is almost immediately above apps.
2162 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002163 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002164 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002165 case TYPE_SYSTEM_DIALOG:
2166 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002167 case TYPE_TOAST:
2168 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002169 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002170 case TYPE_PRIORITY_PHONE:
2171 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002172 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002173 case TYPE_DREAM:
2174 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002175 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002176 case TYPE_SYSTEM_ALERT:
2177 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002178 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002179 case TYPE_INPUT_METHOD:
2180 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002181 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002182 case TYPE_INPUT_METHOD_DIALOG:
2183 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002184 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002185 case TYPE_KEYGUARD_SCRIM:
2186 // the safety window that shows behind keyguard while keyguard is starting
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002187 return 14;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002188 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002189 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002190 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002191 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002192 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002193 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002194 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002195 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002196 case TYPE_VOLUME_OVERLAY:
2197 // the on-screen volume indicator and controller shown when the user
2198 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002199 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002200 case TYPE_SYSTEM_OVERLAY:
2201 // the on-screen volume indicator and controller shown when the user
2202 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002203 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002204 case TYPE_NAVIGATION_BAR:
2205 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002206 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002207 case TYPE_NAVIGATION_BAR_PANEL:
2208 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002209 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002210 case TYPE_SYSTEM_ERROR:
2211 // system-level error dialogs
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002212 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002213 case TYPE_MAGNIFICATION_OVERLAY:
2214 // used to highlight the magnified portion of a display
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002215 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002216 case TYPE_DISPLAY_OVERLAY:
2217 // used to simulate secondary display devices
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002218 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002219 case TYPE_DRAG:
2220 // the drag layer: input for drag-and-drop is associated with this window,
2221 // which sits above all other focusable windows
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002222 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002223 case TYPE_ACCESSIBILITY_OVERLAY:
2224 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002225 return 27;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002226 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002227 return 28;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002228 case TYPE_BOOT_PROGRESS:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002229 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002230 case TYPE_POINTER:
2231 // the (mouse) pointer layer
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002232 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002233 }
2234 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002235 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002236 }
2237
2238 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002239 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002240 public int subWindowTypeToLayerLw(int type) {
2241 switch (type) {
2242 case TYPE_APPLICATION_PANEL:
2243 case TYPE_APPLICATION_ATTACHED_DIALOG:
2244 return APPLICATION_PANEL_SUBLAYER;
2245 case TYPE_APPLICATION_MEDIA:
2246 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002247 case TYPE_APPLICATION_MEDIA_OVERLAY:
2248 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002249 case TYPE_APPLICATION_SUB_PANEL:
2250 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002251 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2252 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002253 }
2254 Log.e(TAG, "Unknown sub-window type: " + type);
2255 return 0;
2256 }
2257
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002258 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002259 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002260 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002261 }
2262
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002263 private int getNavigationBarWidth(int rotation, int uiMode) {
2264 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2265 return mNavigationBarWidthForRotationInCarMode[rotation];
2266 } else {
2267 return mNavigationBarWidthForRotationDefault[rotation];
2268 }
2269 }
2270
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002271 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002272 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
2273 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002274 if (mHasNavigationBar) {
2275 // For a basic navigation bar, when we are in landscape mode we place
2276 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002277 if (mNavigationBarCanMove && fullWidth > fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002278 return fullWidth - getNavigationBarWidth(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002279 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002280 }
2281 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002282 }
2283
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002284 private int getNavigationBarHeight(int rotation, int uiMode) {
2285 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2286 return mNavigationBarHeightForRotationInCarMode[rotation];
2287 } else {
2288 return mNavigationBarHeightForRotationDefault[rotation];
2289 }
2290 }
2291
Jose Lima9546b202014-07-02 17:21:51 -07002292 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002293 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
2294 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002295 if (mHasNavigationBar) {
2296 // For a basic navigation bar, when we are in portrait mode we place
2297 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002298 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002299 return fullHeight - getNavigationBarHeight(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002300 }
2301 }
2302 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002303 }
2304
Jose Lima9546b202014-07-02 17:21:51 -07002305 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002306 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) {
2307 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002308 }
2309
Jose Lima9546b202014-07-02 17:21:51 -07002310 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002311 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
John Spurlock80f00c12013-06-13 11:10:51 -04002312 // There is a separate status bar at the top of the display. We don't count that as part
2313 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002314 // we do want to exclude it since applications can't generally use that part
2315 // of the screen.
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002316 return getNonDecorDisplayHeight(
2317 fullWidth, fullHeight, rotation, uiMode) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002318 }
2319
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002320 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002321 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2322 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002323 (isKeyguardHostWindow(attrs) &&
2324 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002325 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002326 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002327
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002328 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002329 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2330 return attrs.type == TYPE_STATUS_BAR;
2331 }
2332
2333 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002334 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002335 switch (attrs.type) {
2336 case TYPE_STATUS_BAR:
2337 case TYPE_NAVIGATION_BAR:
2338 case TYPE_WALLPAPER:
2339 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002340 case TYPE_KEYGUARD_SCRIM:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002341 case TYPE_DOCK_DIVIDER:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002342 return false;
2343 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002344 // Hide only windows below the keyguard host window.
2345 return windowTypeToLayerLw(win.getBaseType())
2346 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002347 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002348 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002349
Craig Mautner7d7808f2014-09-11 18:02:38 -07002350 @Override
2351 public WindowState getWinShowWhenLockedLw() {
2352 return mWinShowWhenLocked;
2353 }
2354
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002355 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002356 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002357 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2358 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002359 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002360 if (!SHOW_STARTING_ANIMATIONS) {
2361 return null;
2362 }
2363 if (packageName == null) {
2364 return null;
2365 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002366
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002367 WindowManager wm = null;
2368 View view = null;
2369
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002370 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002371 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002372 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2373 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2374 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002375 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002376 try {
2377 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002378 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002379 } catch (PackageManager.NameNotFoundException e) {
2380 // Ignore
2381 }
2382 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002383
Jorim Jaggia16cc152015-06-01 16:55:05 -07002384 PhoneWindow win = new PhoneWindow(context);
2385 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002386
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002387 Resources r = context.getResources();
2388 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002389
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002390 win.setType(
2391 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002392
2393 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2394 // Assumes it's safe to show starting windows of launched apps while
2395 // the keyguard is being hidden. This is okay because starting windows never show
2396 // secret information.
2397 if (mKeyguardHidden) {
2398 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2399 }
2400 }
2401
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002402 // Force the window flags: this is a fake window, so it is not really
2403 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2404 // flag because we do know that the next window will take input
2405 // focus, so we want to get the IME window up on top of us right away.
2406 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002407 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002408 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2409 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2410 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002411 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002412 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2413 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2414 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002415
Adam Powell04fe6eb2013-05-31 14:39:48 -07002416 win.setDefaultIcon(icon);
2417 win.setDefaultLogo(logo);
2418
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002419 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002420 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002421
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002422 final WindowManager.LayoutParams params = win.getAttributes();
2423 params.token = appToken;
2424 params.packageName = packageName;
2425 params.windowAnimations = win.getWindowStyle().getResourceId(
2426 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002427 params.privateFlags |=
2428 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002429 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002430
2431 if (!compatInfo.supportsScreen()) {
2432 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2433 }
2434
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002435 params.setTitle("Starting " + packageName);
2436
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002437 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2438 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002439
Craig Mautner6fbda632012-07-03 09:26:39 -07002440 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002441 TAG, "Adding starting window for " + packageName
2442 + " / " + appToken + ": "
2443 + (view.getParent() != null ? view : null));
2444
2445 wm.addView(view, params);
2446
2447 // Only return the view if it was successfully added to the
2448 // window manager... which we can tell by it having a parent.
2449 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002450 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002451 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002452 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2453 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002454 } catch (RuntimeException e) {
2455 // don't crash if something else bad happens, for example a
2456 // failure loading resources because we are loading from an app
2457 // on external storage that has been unmounted.
2458 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002459 } finally {
2460 if (view != null && view.getParent() == null) {
2461 Log.w(TAG, "view not successfully added to wm, removing view");
2462 wm.removeViewImmediate(view);
2463 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002464 }
2465
2466 return null;
2467 }
2468
2469 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002470 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002471 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002472 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2473 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002474
2475 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002476 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002477 wm.removeView(window);
2478 }
2479 }
2480
2481 /**
2482 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002483 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002484 * Currently enforces that three window types are singletons:
2485 * <ul>
2486 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002487 * <li>KEYGUARD_TYPE</li>
2488 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002489 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002490 * @param win The window to be added
2491 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002492 *
Jeff Brown98365d72012-08-19 20:30:52 -07002493 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2494 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002495 */
Jose Lima9546b202014-07-02 17:21:51 -07002496 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002497 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2498 switch (attrs.type) {
2499 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002500 mContext.enforceCallingOrSelfPermission(
2501 android.Manifest.permission.STATUS_BAR_SERVICE,
2502 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002503 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002504 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002505 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002506 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002507 }
2508 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002509 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002510 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002511 case TYPE_NAVIGATION_BAR:
2512 mContext.enforceCallingOrSelfPermission(
2513 android.Manifest.permission.STATUS_BAR_SERVICE,
2514 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002515 if (mNavigationBar != null) {
2516 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002517 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002518 }
2519 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002520 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002521 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002522 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002523 break;
Jim Millere898ac52012-04-06 17:10:57 -07002524 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002525 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002526 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002527 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002528 mContext.enforceCallingOrSelfPermission(
2529 android.Manifest.permission.STATUS_BAR_SERVICE,
2530 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002531 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002532 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002533 if (mKeyguardScrim != null) {
2534 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2535 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002536 mKeyguardScrim = win;
2537 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002538 }
Jeff Brown98365d72012-08-19 20:30:52 -07002539 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002540 }
2541
2542 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002543 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002544 public void removeWindowLw(WindowState win) {
2545 if (mStatusBar == win) {
2546 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002547 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002548 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002549 } else if (mKeyguardScrim == win) {
2550 Log.v(TAG, "Removing keyguard scrim");
2551 mKeyguardScrim = null;
2552 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002553 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002554 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002555 }
2556 }
2557
2558 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002559
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002560 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002561 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002562 public int selectAnimationLw(WindowState win, int transit) {
2563 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2564 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002565 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002566 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002567 if (transit == TRANSIT_EXIT
2568 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002569 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002570 } else if (transit == TRANSIT_ENTER
2571 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002572 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002573 }
2574 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002575 if (win.getAttrs().windowAnimations != 0) {
2576 return 0;
2577 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002578 // This can be on either the bottom or the right.
2579 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002580 if (transit == TRANSIT_EXIT
2581 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002582 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002583 } else if (transit == TRANSIT_ENTER
2584 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002585 return R.anim.dock_bottom_enter;
2586 }
2587 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002588 if (transit == TRANSIT_EXIT
2589 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002590 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002591 } else if (transit == TRANSIT_ENTER
2592 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002593 return R.anim.dock_right_enter;
2594 }
2595 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002596 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -08002597 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002598 return R.anim.fade_in;
2599 } else if (transit == TRANSIT_EXIT) {
2600 return R.anim.fade_out;
2601 }
Craig Mautner4b71aa12012-12-27 17:20:01 -08002602 }
2603
2604 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002605 if (win.hasAppShownWindows()) {
2606 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2607 return com.android.internal.R.anim.app_starting_exit;
2608 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002609 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002610 && transit == TRANSIT_ENTER) {
2611 // Special case: we are animating in a dream, while the keyguard
2612 // is shown. We don't want an animation on the dream, because
2613 // we need it shown immediately with the keyguard animating away
2614 // to reveal it.
2615 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002616 }
2617
2618 return 0;
2619 }
2620
Craig Mautner3c174372013-02-21 17:54:37 -08002621 @Override
2622 public void selectRotationAnimationLw(int anim[]) {
2623 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2624 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2625 + (mTopFullscreenOpaqueWindowState == null ?
2626 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2627 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2628 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2629 case ROTATION_ANIMATION_CROSSFADE:
2630 anim[0] = R.anim.rotation_animation_xfade_exit;
2631 anim[1] = R.anim.rotation_animation_enter;
2632 break;
2633 case ROTATION_ANIMATION_JUMPCUT:
2634 anim[0] = R.anim.rotation_animation_jump_exit;
2635 anim[1] = R.anim.rotation_animation_enter;
2636 break;
2637 case ROTATION_ANIMATION_ROTATE:
2638 default:
2639 anim[0] = anim[1] = 0;
2640 break;
2641 }
2642 } else {
2643 anim[0] = anim[1] = 0;
2644 }
2645 }
2646
2647 @Override
2648 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2649 boolean forceDefault) {
2650 switch (exitAnimId) {
2651 case R.anim.rotation_animation_xfade_exit:
2652 case R.anim.rotation_animation_jump_exit:
2653 // These are the only cases that matter.
2654 if (forceDefault) {
2655 return false;
2656 }
2657 int anim[] = new int[2];
2658 selectRotationAnimationLw(anim);
2659 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2660 default:
2661 return true;
2662 }
2663 }
2664
2665 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002666 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2667 boolean goingToNotificationShade) {
2668 if (goingToNotificationShade) {
2669 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002670 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002671
2672 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2673 R.anim.lock_screen_behind_enter_wallpaper :
2674 R.anim.lock_screen_behind_enter);
2675
2676 // TODO: Use XML interpolators when we have log interpolators available in XML.
2677 final List<Animation> animations = set.getAnimations();
2678 for (int i = animations.size() - 1; i >= 0; --i) {
2679 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2680 }
2681
2682 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002683 }
2684
2685
2686 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002687 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2688 if (goingToNotificationShade) {
2689 return null;
2690 } else {
2691 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2692 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002693 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002694
2695 private static void awakenDreams() {
2696 IDreamManager dreamManager = getDreamManager();
2697 if (dreamManager != null) {
2698 try {
2699 dreamManager.awaken();
2700 } catch (RemoteException e) {
2701 // fine, stay asleep then
2702 }
2703 }
2704 }
2705
2706 static IDreamManager getDreamManager() {
2707 return IDreamManager.Stub.asInterface(
2708 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2709 }
2710
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002711 TelecomManager getTelecommService() {
2712 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002713 }
2714
Jeff Brown4d396052010-10-29 21:50:21 -07002715 static IAudioService getAudioService() {
2716 IAudioService audioService = IAudioService.Stub.asInterface(
2717 ServiceManager.checkService(Context.AUDIO_SERVICE));
2718 if (audioService == null) {
2719 Log.w(TAG, "Unable to find IAudioService interface.");
2720 }
2721 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002722 }
2723
2724 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002725 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002726 }
2727
2728 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2729 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2730 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2731 };
2732
2733 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002734 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002735 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002736 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002737 final int keyCode = event.getKeyCode();
2738 final int repeatCount = event.getRepeatCount();
2739 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002740 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002741 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2742 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002743
Jeff Brown40013652012-05-16 21:22:36 -07002744 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002745 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002746 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2747 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002748 }
2749
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002750 // If we think we might have a volume down & power key chord on the way
2751 // but we're not sure, then tell the dispatcher to wait a little while and
2752 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002753 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002754 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002755 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002756 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2757 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002758 if (now < timeoutTime) {
2759 return timeoutTime - now;
2760 }
2761 }
2762 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002763 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002764 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002765 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002766 }
2767 return -1;
2768 }
2769 }
2770
Michael Wright6a62e552014-06-03 19:19:48 -07002771 // Cancel any pending meta actions if we see any other keys being pressed between the down
2772 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002773 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002774 mPendingMetaAction = false;
2775 }
2776
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002777 // First we always handle the home key here, so applications
2778 // can never break it, although if keyguard is on, we do let
2779 // it handle it, because that gives us the correct 5 second
2780 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002781 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002782
Jeff Brown49ed71d2010-12-06 17:13:33 -08002783 // If we have released the home key, and didn't do anything else
2784 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002785 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002786 cancelPreloadRecentApps();
2787
Jeff Brown49ed71d2010-12-06 17:13:33 -08002788 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002789 if (mHomeConsumed) {
2790 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002791 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002792 }
Jeff Browncaca8812013-05-09 13:34:33 -07002793
2794 if (canceled) {
2795 Log.i(TAG, "Ignoring HOME; event canceled.");
2796 return -1;
2797 }
2798
Yorke Lee4f803242014-12-15 23:22:06 +00002799 // If an incoming call is ringing, HOME is totally disabled.
2800 // (The user is already on the InCallUI at this point,
2801 // and his ONLY options are to answer or reject the call.)
2802 TelecomManager telecomManager = getTelecommService();
2803 if (telecomManager != null && telecomManager.isRinging()) {
2804 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2805 return -1;
2806 }
2807
Jeff Browncaca8812013-05-09 13:34:33 -07002808 // Delay handling home if a double-tap is possible.
2809 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2810 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2811 mHomeDoubleTapPending = true;
2812 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2813 ViewConfiguration.getDoubleTapTimeout());
2814 return -1;
2815 }
2816
Jeff Brown13f00f02014-10-31 14:45:50 -07002817 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002818 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002819 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002820
2821 // If a system window has focus, then it doesn't make sense
2822 // right now to interact with applications.
2823 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2824 if (attrs != null) {
2825 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002826 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2827 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2828 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002829 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002830 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002831 }
2832 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2833 for (int i=0; i<typeCount; i++) {
2834 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2835 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002836 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002837 }
2838 }
2839 }
Jeff Browncaca8812013-05-09 13:34:33 -07002840
2841 // Remember that home is pressed and handle special actions.
2842 if (repeatCount == 0) {
2843 mHomePressed = true;
2844 if (mHomeDoubleTapPending) {
2845 mHomeDoubleTapPending = false;
2846 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2847 handleDoubleTapOnHome();
2848 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2849 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2850 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002851 }
Jeff Browncaca8812013-05-09 13:34:33 -07002852 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2853 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002854 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002855 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002856 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002857 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002858 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002859 // Hijack modified menu keys for debugging features
2860 final int chordBug = KeyEvent.META_SHIFT_ON;
2861
2862 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002863 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002864 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002865 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2866 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002867 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002868 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002869 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002870 Intent service = new Intent();
2871 service.setClassName(mContext, "com.android.server.LoadAverageService");
2872 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002873 boolean shown = Settings.Global.getInt(
2874 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002875 if (!shown) {
2876 mContext.startService(service);
2877 } else {
2878 mContext.stopService(service);
2879 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002880 Settings.Global.putInt(
2881 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002882 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002883 }
2884 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002885 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002886 if (down) {
2887 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002888 mSearchKeyShortcutPending = true;
2889 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002890 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002891 } else {
2892 mSearchKeyShortcutPending = false;
2893 if (mConsumeSearchKeyUp) {
2894 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002895 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002896 }
2897 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002898 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002899 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002900 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002901 if (down && repeatCount == 0) {
2902 preloadRecentApps();
2903 } else if (!down) {
2904 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002905 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002906 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002907 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002908 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2909 if (down) {
2910 IStatusBarService service = getStatusBarService();
2911 if (service != null) {
2912 try {
2913 service.expandNotificationsPanel();
2914 } catch (RemoteException e) {
2915 // do nothing.
2916 }
2917 }
2918 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01002919 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
2920 if (down) {
2921 if (repeatCount == 0) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00002922 toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01002923 }
2924 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002925 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
2926 if (down) {
2927 if (repeatCount == 0) {
2928 mAssistKeyLongPressed = false;
2929 } else if (repeatCount == 1) {
2930 mAssistKeyLongPressed = true;
2931 if (!keyguardOn) {
2932 launchAssistLongPressAction();
2933 }
2934 }
2935 } else {
2936 if (mAssistKeyLongPressed) {
2937 mAssistKeyLongPressed = false;
2938 } else {
2939 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07002940 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07002941 }
2942 }
2943 }
2944 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002945 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
2946 if (!down) {
2947 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07002948 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002949 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
2950 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07002951 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
2952 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
2953 if (dic != null) {
2954 try {
2955 dic.exitIdle("voice-search");
2956 } catch (RemoteException e) {
2957 }
2958 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002959 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07002960 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002961 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00002962 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07002963 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08002964 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
2965 if (down && repeatCount == 0) {
2966 mHandler.post(mScreenshotRunnable);
2967 }
2968 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08002969 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
2970 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
2971 if (down) {
2972 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
2973
2974 // Disable autobrightness if it's on
2975 int auto = Settings.System.getIntForUser(
2976 mContext.getContentResolver(),
2977 Settings.System.SCREEN_BRIGHTNESS_MODE,
2978 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2979 UserHandle.USER_CURRENT_OR_SELF);
2980 if (auto != 0) {
2981 Settings.System.putIntForUser(mContext.getContentResolver(),
2982 Settings.System.SCREEN_BRIGHTNESS_MODE,
2983 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
2984 UserHandle.USER_CURRENT_OR_SELF);
2985 }
2986
2987 int min = mPowerManager.getMinimumScreenBrightnessSetting();
2988 int max = mPowerManager.getMaximumScreenBrightnessSetting();
2989 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
2990 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
2991 Settings.System.SCREEN_BRIGHTNESS,
2992 mPowerManager.getDefaultScreenBrightnessSetting(),
2993 UserHandle.USER_CURRENT_OR_SELF);
2994 brightness += step;
2995 // Make sure we don't go beyond the limits.
2996 brightness = Math.min(max, brightness);
2997 brightness = Math.max(min, brightness);
2998
2999 Settings.System.putIntForUser(mContext.getContentResolver(),
3000 Settings.System.SCREEN_BRIGHTNESS, brightness,
3001 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003002 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003003 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003004 }
3005 return -1;
Michael Wrightce0c13a2014-07-30 10:49:21 -07003006 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003007 if (down) {
3008 mPendingMetaAction = true;
3009 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003010 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003011 }
3012 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003013 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003014
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003015 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003016 // Any printing key that is chorded with Search should be consumed
3017 // even if no shortcut was invoked. This prevents text from being
3018 // inadvertently inserted when using a keyboard that has built-in macro
3019 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003020 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003021 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3022 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003023 mConsumeSearchKeyUp = true;
3024 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003025 if (down && repeatCount == 0 && !keyguardOn) {
3026 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3027 if (shortcutIntent != null) {
3028 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003029 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003030 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003031 } catch (ActivityNotFoundException ex) {
3032 Slog.w(TAG, "Dropping shortcut key combination because "
3033 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003034 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003035 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003036 } else {
3037 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003038 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003039 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003040 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003041 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003042 }
3043 }
3044
Jeff Brown68b909d2011-12-07 16:36:01 -08003045 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003046 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003047 && (metaState & KeyEvent.META_META_ON) != 0) {
3048 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003049 if (kcm.isPrintingKey(keyCode)) {
3050 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3051 metaState & ~(KeyEvent.META_META_ON
3052 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3053 if (shortcutIntent != null) {
3054 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3055 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003056 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07003057 } catch (ActivityNotFoundException ex) {
3058 Slog.w(TAG, "Dropping shortcut key combination because "
3059 + "the activity to which it is registered was not found: "
3060 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3061 }
3062 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003063 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003064 }
3065 }
3066
Jeff Brown6651a632011-11-28 12:59:11 -08003067 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003068 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003069 String category = sApplicationLaunchKeyCategories.get(keyCode);
3070 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003071 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003072 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3073 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003074 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003075 } catch (ActivityNotFoundException ex) {
3076 Slog.w(TAG, "Dropping application launch key because "
3077 + "the activity to which it is registered was not found: "
3078 + "keyCode=" + keyCode + ", category=" + category, ex);
3079 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003080 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003081 }
3082 }
3083
Michael Wright61c46752014-08-21 16:57:33 -07003084 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003085 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003086 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003087 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003088 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003089 mRecentAppsHeldModifiers = shiftlessModifiers;
3090 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003091 return -1;
3092 }
3093 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003094 } else if (!down && mRecentAppsHeldModifiers != 0
3095 && (metaState & mRecentAppsHeldModifiers) == 0) {
3096 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003097 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003098 }
3099
Yohei Yukawaae61f712015-12-09 13:00:10 -08003100 // Handle keyboard layout switching.
3101 // TODO: Deprecate this behavior when we fully migrate to IME subtype-based layout rotation.
3102 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_SPACE
3103 && ((metaState & KeyEvent.META_CTRL_MASK) != 0)) {
3104 int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
3105 mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
3106 return -1;
3107 }
3108
3109 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003110 if (down && repeatCount == 0
3111 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3112 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003113 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3114 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3115 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003116 return -1;
3117 }
3118 if (mLanguageSwitchKeyPressed && !down
3119 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3120 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3121 mLanguageSwitchKeyPressed = false;
3122 return -1;
3123 }
3124
Jeff Brown13f00f02014-10-31 14:45:50 -07003125 if (isValidGlobalKey(keyCode)
3126 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003127 return -1;
3128 }
3129
Michael Wright6a62e552014-06-03 19:19:48 -07003130 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003131 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003132 return -1;
3133 }
3134
Jeff Brown68b909d2011-12-07 16:36:01 -08003135 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003136 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003137 }
3138
Jeff Brown3915bb82010-11-05 15:02:16 -07003139 /** {@inheritDoc} */
3140 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003141 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003142 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003143 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003144 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3145 + ", flags=" + event.getFlags()
3146 + ", keyCode=" + event.getKeyCode()
3147 + ", scanCode=" + event.getScanCode()
3148 + ", metaState=" + event.getMetaState()
3149 + ", repeatCount=" + event.getRepeatCount()
3150 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003151 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003152
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003153 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003154 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3155 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003156 final int keyCode = event.getKeyCode();
3157 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003158 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3159 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003160
Jeff Brown54875002011-04-06 15:33:01 -07003161 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003162 final FallbackAction fallbackAction;
3163 if (initialDown) {
3164 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3165 } else {
3166 fallbackAction = mFallbackActions.get(keyCode);
3167 }
3168
3169 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003170 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003171 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3172 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003173 }
3174
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003175 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3176 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003177 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003178 event.getAction(), fallbackAction.keyCode,
3179 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003180 event.getDeviceId(), event.getScanCode(),
3181 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003182
3183 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3184 fallbackEvent.recycle();
3185 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003186 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003187
3188 if (initialDown) {
3189 mFallbackActions.put(keyCode, fallbackAction);
3190 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3191 mFallbackActions.remove(keyCode);
3192 fallbackAction.recycle();
3193 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003194 }
3195 }
3196
Jeff Brown40013652012-05-16 21:22:36 -07003197 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003198 if (fallbackEvent == null) {
3199 Slog.d(TAG, "No fallback.");
3200 } else {
3201 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3202 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003203 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003204 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003205 }
3206
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003207 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003208 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003209 if ((actions & ACTION_PASS_TO_USER) != 0) {
3210 long delayMillis = interceptKeyBeforeDispatching(
3211 win, fallbackEvent, policyFlags);
3212 if (delayMillis == 0) {
3213 return true;
3214 }
3215 }
3216 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003217 }
3218
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003219 private void launchAssistLongPressAction() {
3220 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3221 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3222
3223 // launch the search activity
3224 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3225 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3226 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003227 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003228 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003229 SearchManager searchManager = getSearchManager();
3230 if (searchManager != null) {
3231 searchManager.stopSearch();
3232 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003233 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003234 } catch (ActivityNotFoundException e) {
3235 Slog.w(TAG, "No activity to handle assist long press action.", e);
3236 }
3237 }
3238
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003239 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003240 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003241 if (!isUserSetupComplete()) {
3242 // Disable opening assist window during setup
3243 return;
3244 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003245 Bundle args = null;
3246 if (deviceId > Integer.MIN_VALUE) {
3247 args = new Bundle();
3248 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003249 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003250 if ((mContext.getResources().getConfiguration().uiMode
3251 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3252 // On TV, use legacy handling until assistants are implemented in the proper way.
3253 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3254 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3255 } else {
3256 try {
3257 if (hint != null) {
3258 if (args == null) {
3259 args = new Bundle();
3260 }
3261 args.putBoolean(hint, true);
3262 }
3263 IStatusBarService statusbar = getStatusBarService();
3264 if (statusbar != null) {
3265 statusbar.startAssist(args);
3266 }
3267 } catch (RemoteException e) {
3268 Slog.e(TAG, "RemoteException when starting assist", e);
3269 // re-acquire status bar service next time it is needed.
3270 mStatusBarService = null;
3271 }
3272 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003273 }
3274
Bart Sears8b1c27c2015-03-18 23:51:02 +00003275 private void startActivityAsUser(Intent intent, UserHandle handle) {
3276 if (isUserSetupComplete()) {
3277 mContext.startActivityAsUser(intent, handle);
3278 } else {
3279 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3280 }
3281 }
3282
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003283 private SearchManager getSearchManager() {
3284 if (mSearchManager == null) {
3285 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3286 }
3287 return mSearchManager;
3288 }
3289
Jeff Browncaca8812013-05-09 13:34:33 -07003290 private void preloadRecentApps() {
3291 mPreloadedRecentApps = true;
3292 try {
3293 IStatusBarService statusbar = getStatusBarService();
3294 if (statusbar != null) {
3295 statusbar.preloadRecentApps();
3296 }
3297 } catch (RemoteException e) {
3298 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3299 // re-acquire status bar service next time it is needed.
3300 mStatusBarService = null;
3301 }
3302 }
3303
3304 private void cancelPreloadRecentApps() {
3305 if (mPreloadedRecentApps) {
3306 mPreloadedRecentApps = false;
3307 try {
3308 IStatusBarService statusbar = getStatusBarService();
3309 if (statusbar != null) {
3310 statusbar.cancelPreloadRecentApps();
3311 }
3312 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003313 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003314 // re-acquire status bar service next time it is needed.
3315 mStatusBarService = null;
3316 }
3317 }
3318 }
3319
3320 private void toggleRecentApps() {
3321 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003322 try {
3323 IStatusBarService statusbar = getStatusBarService();
3324 if (statusbar != null) {
3325 statusbar.toggleRecentApps();
3326 }
3327 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003328 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3329 // re-acquire status bar service next time it is needed.
3330 mStatusBarService = null;
3331 }
3332 }
3333
Craig Mautner84984fa2014-06-19 11:19:20 -07003334 @Override
3335 public void showRecentApps() {
3336 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3337 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3338 }
3339
Winson Chung1e8d71b2014-05-16 17:05:22 -07003340 private void showRecentApps(boolean triggeredFromAltTab) {
3341 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3342 try {
3343 IStatusBarService statusbar = getStatusBarService();
3344 if (statusbar != null) {
3345 statusbar.showRecentApps(triggeredFromAltTab);
3346 }
3347 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003348 Slog.e(TAG, "RemoteException when showing recent apps", e);
3349 // re-acquire status bar service next time it is needed.
3350 mStatusBarService = null;
3351 }
3352 }
3353
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003354 private void toggleKeyboardShortcutsMenu() {
Clara Bayarrif2debb12015-07-10 14:47:17 +01003355 try {
3356 IStatusBarService statusbar = getStatusBarService();
3357 if (statusbar != null) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003358 statusbar.toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003359 }
3360 } catch (RemoteException e) {
3361 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3362 }
3363 }
3364
Winson Chungcdcd4872014-08-05 18:00:13 -07003365 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003366 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3367 try {
3368 IStatusBarService statusbar = getStatusBarService();
3369 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003370 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003371 }
3372 } catch (RemoteException e) {
3373 Slog.e(TAG, "RemoteException when closing recent apps", e);
3374 // re-acquire status bar service next time it is needed.
3375 mStatusBarService = null;
3376 }
3377 }
3378
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003379 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003380 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003381 }
3382
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003383 /**
3384 * A home key -> launch home action was detected. Take the appropriate action
3385 * given the situation with the keyguard.
3386 */
Bryce Lee662ed802015-04-10 20:11:39 +00003387 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3388 if (respectKeyguard) {
3389 if (isKeyguardShowingAndNotOccluded()) {
3390 // don't launch home if keyguard showing
3391 return;
3392 }
3393
3394 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3395 // when in keyguard restricted mode, must first verify unlock
3396 // before launching home
3397 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3398 @Override
3399 public void onKeyguardExitResult(boolean success) {
3400 if (success) {
3401 try {
3402 ActivityManagerNative.getDefault().stopAppSwitches();
3403 } catch (RemoteException e) {
3404 }
3405 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3406 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003407 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003408 }
Bryce Lee662ed802015-04-10 20:11:39 +00003409 });
3410 return;
3411 }
3412 }
3413
3414 // no keyguard stuff to worry about, just launch home!
3415 try {
3416 ActivityManagerNative.getDefault().stopAppSwitches();
3417 } catch (RemoteException e) {
3418 }
3419 if (mRecentsVisible) {
3420 // Hide Recents and notify it to launch Home
3421 if (awakenFromDreams) {
3422 awakenDreams();
3423 }
Bryce Lee662ed802015-04-10 20:11:39 +00003424 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003425 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003426 // Otherwise, just launch Home
3427 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3428 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003429 }
3430 }
3431
John Spurlock04db1762013-05-13 12:46:41 -04003432 private final Runnable mClearHideNavigationFlag = new Runnable() {
3433 @Override
3434 public void run() {
3435 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3436 // Clear flags.
3437 mForceClearedSystemUiFlags &=
3438 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3439 }
3440 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003441 }
3442 };
3443
3444 /**
3445 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3446 * to determine when the nav bar should be shown and prevent applications from
3447 * receiving those touches.
3448 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003449 final class HideNavInputEventReceiver extends InputEventReceiver {
3450 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3451 super(inputChannel, looper);
3452 }
3453
Dianne Hackborndf89e652011-10-06 22:35:11 -07003454 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003455 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003456 boolean handled = false;
3457 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003458 if (event instanceof MotionEvent
3459 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3460 final MotionEvent motionEvent = (MotionEvent)event;
3461 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003462 // When the user taps down, we re-show the nav bar.
3463 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003464 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003465 // Any user activity always causes us to show the
3466 // navigation controls, if they had been hidden.
3467 // We also clear the low profile and only content
3468 // flags so that tapping on the screen will atomically
3469 // restore all currently hidden screen decorations.
3470 int newVal = mResettingSystemUiFlags |
3471 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3472 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3473 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003474 if (mResettingSystemUiFlags != newVal) {
3475 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003476 changed = true;
3477 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003478 // We don't allow the system's nav bar to be hidden
3479 // again for 1 second, to prevent applications from
3480 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003481 newVal = mForceClearedSystemUiFlags |
3482 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003483 if (mForceClearedSystemUiFlags != newVal) {
3484 mForceClearedSystemUiFlags = newVal;
3485 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003486 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003487 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003488 }
3489 if (changed) {
3490 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3491 }
3492 }
3493 }
3494 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003495 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003496 }
3497 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003498 }
3499 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3500 new InputEventReceiver.Factory() {
3501 @Override
3502 public InputEventReceiver createInputEventReceiver(
3503 InputChannel inputChannel, Looper looper) {
3504 return new HideNavInputEventReceiver(inputChannel, looper);
3505 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003506 };
3507
3508 @Override
3509 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003510 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3511 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003512 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003513
Dianne Hackborndf89e652011-10-06 22:35:11 -07003514 // Reset any bits in mForceClearingStatusBarVisibility that
3515 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003516 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003517 // Clear any bits in the new visibility that are currently being
3518 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003519 return visibility & ~mResettingSystemUiFlags
3520 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003521 }
3522
Craig Mautner69b08182012-09-05 13:07:13 -07003523 @Override
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003524 public void getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
3525 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003526 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003527 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3528 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003529
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003530 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3531 if (useOutsets) {
3532 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3533 if (outset > 0) {
3534 if (displayRotation == Surface.ROTATION_0) {
3535 outOutsets.bottom += outset;
3536 } else if (displayRotation == Surface.ROTATION_90) {
3537 outOutsets.right += outset;
3538 } else if (displayRotation == Surface.ROTATION_180) {
3539 outOutsets.top += outset;
3540 } else if (displayRotation == Surface.ROTATION_270) {
3541 outOutsets.left += outset;
3542 }
3543 }
3544 }
3545
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003546 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003547 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003548 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003549 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003550 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003551 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3552 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3553 } else {
3554 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3555 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3556 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003557 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3558 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003559 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003560 availRight - mStableFullscreenRight,
3561 availBottom - mStableFullscreenBottom);
3562 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003563 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003564 availRight - mStableRight, availBottom - mStableBottom);
3565 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003566 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003567 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003568 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003569 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003570 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003571 availRight - mCurRight, availBottom - mCurBottom);
3572 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003573 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003574 availRight - mCurRight, availBottom - mCurBottom);
3575 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003576
3577 outStableInsets.set(mStableLeft, mStableTop,
3578 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003579 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003580 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003581 outContentInsets.setEmpty();
3582 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003583 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003584
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003585 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3586 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3587 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3588 }
3589
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003590 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003591 @Override
3592 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003593 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003594 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003595 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3596 if (isDefaultDisplay) {
3597 switch (displayRotation) {
3598 case Surface.ROTATION_90:
3599 overscanLeft = mOverscanTop;
3600 overscanTop = mOverscanRight;
3601 overscanRight = mOverscanBottom;
3602 overscanBottom = mOverscanLeft;
3603 break;
3604 case Surface.ROTATION_180:
3605 overscanLeft = mOverscanRight;
3606 overscanTop = mOverscanBottom;
3607 overscanRight = mOverscanLeft;
3608 overscanBottom = mOverscanTop;
3609 break;
3610 case Surface.ROTATION_270:
3611 overscanLeft = mOverscanBottom;
3612 overscanTop = mOverscanLeft;
3613 overscanRight = mOverscanTop;
3614 overscanBottom = mOverscanRight;
3615 break;
3616 default:
3617 overscanLeft = mOverscanLeft;
3618 overscanTop = mOverscanTop;
3619 overscanRight = mOverscanRight;
3620 overscanBottom = mOverscanBottom;
3621 break;
3622 }
3623 } else {
3624 overscanLeft = 0;
3625 overscanTop = 0;
3626 overscanRight = 0;
3627 overscanBottom = 0;
3628 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003629 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3630 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3631 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3632 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003633 mSystemLeft = 0;
3634 mSystemTop = 0;
3635 mSystemRight = displayWidth;
3636 mSystemBottom = displayHeight;
3637 mUnrestrictedScreenLeft = overscanLeft;
3638 mUnrestrictedScreenTop = overscanTop;
3639 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3640 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3641 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3642 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003643 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3644 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003645 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003646 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003647 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003648 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003649 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003650 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003651 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003652 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003653 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003654 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003655
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003656 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3657 final Rect pf = mTmpParentFrame;
3658 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003659 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003660 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003661 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003662 pf.left = df.left = of.left = vf.left = mDockLeft;
3663 pf.top = df.top = of.top = vf.top = mDockTop;
3664 pf.right = df.right = of.right = vf.right = mDockRight;
3665 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003666 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003667
Craig Mautner69b08182012-09-05 13:07:13 -07003668 if (isDefaultDisplay) {
3669 // For purposes of putting out fake window up to steal focus, we will
3670 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003671 final int sysui = mLastSystemUiFlags;
3672 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003673 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003674 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003675 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3676 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3677 boolean navAllowedHidden = immersive || immersiveSticky;
3678 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003679 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3680 if (!isKeyguardShowing) {
3681 navTranslucent &= areTranslucentBarsAllowed();
3682 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003683
Craig Mautner69b08182012-09-05 13:07:13 -07003684 // When the navigation bar isn't visible, we put up a fake
3685 // input window to catch all touch events. This way we can
3686 // detect when the user presses anywhere to bring back the nav
3687 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003688 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003689 if (mInputConsumer != null) {
3690 mInputConsumer.dismiss();
3691 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003692 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003693 } else if (mInputConsumer == null) {
3694 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3695 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003696 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003697
Craig Mautner69b08182012-09-05 13:07:13 -07003698 // For purposes of positioning and showing the nav bar, if we have
3699 // decided that it can't be hidden (because of the screen aspect ratio),
3700 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003701 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003702
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003703 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003704 displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003705 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003706 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003707 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003708 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003709 if (updateSysUiVisibility) {
3710 updateSystemUiVisibilityLw();
3711 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003712 }
3713 }
3714
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003715 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3716 boolean isKeyguardShowing) {
3717 // decide where the status bar goes ahead of time
3718 if (mStatusBar != null) {
3719 // apply any navigation bar insets
3720 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3721 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3722 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3723 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3724 + mUnrestrictedScreenTop;
3725 vf.left = mStableLeft;
3726 vf.top = mStableTop;
3727 vf.right = mStableRight;
3728 vf.bottom = mStableBottom;
3729
3730 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3731
3732 // Let the status bar determine its size.
3733 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3734 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3735 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3736
3737 // For layout, the status bar is always at the top with our fixed height.
3738 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3739
3740 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3741 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003742 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003743 if (!isKeyguardShowing) {
3744 statusBarTranslucent &= areTranslucentBarsAllowed();
3745 }
3746
3747 // If the status bar is hidden, we don't want to cause
3748 // windows behind it to scroll.
3749 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3750 // Status bar may go away, so the screen area it occupies
3751 // is available to apps but just covering them when the
3752 // status bar is visible.
3753 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3754
3755 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3756 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3757 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3758 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3759
3760 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3761 String.format(
3762 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3763 mDockLeft, mDockTop, mDockRight, mDockBottom,
3764 mContentLeft, mContentTop, mContentRight, mContentBottom,
3765 mCurLeft, mCurTop, mCurRight, mCurBottom));
3766 }
3767 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
3768 && !statusBarTransient && !statusBarTranslucent
3769 && !mStatusBarController.wasRecentlyTranslucent()) {
3770 // If the opaque status bar is currently requested to be visible,
3771 // and not in the process of animating on or off, then
3772 // we can tell the app that it is covered by it.
3773 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3774 }
3775 if (mStatusBarController.checkHiddenLw()) {
3776 return true;
3777 }
3778 }
3779 return false;
3780 }
3781
3782 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003783 int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003784 boolean navTranslucent, boolean navAllowedHidden) {
3785 if (mNavigationBar != null) {
3786 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
3787 // Force the navigation bar to its appropriate place and
3788 // size. We need to do this directly, instead of relying on
3789 // it to bubble up from the nav bar, because this needs to
3790 // change atomically with screen rotations.
Jorim Jaggi737af722015-12-31 10:42:27 +01003791 mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003792 if (mNavigationBarOnBottom) {
3793 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
3794 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003795 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003796 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
3797 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
3798 if (transientNavBarShowing) {
3799 mNavigationBarController.setBarShowingLw(true);
3800 } else if (navVisible) {
3801 mNavigationBarController.setBarShowingLw(true);
3802 mDockBottom = mTmpNavigationFrame.top;
3803 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3804 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
3805 } else {
3806 // We currently want to hide the navigation UI.
3807 mNavigationBarController.setBarShowingLw(false);
3808 }
3809 if (navVisible && !navTranslucent && !navAllowedHidden
3810 && !mNavigationBar.isAnimatingLw()
3811 && !mNavigationBarController.wasRecentlyTranslucent()) {
3812 // If the opaque nav bar is currently requested to be visible,
3813 // and not in the process of animating on or off, then
3814 // we can tell the app that it is covered by it.
3815 mSystemBottom = mTmpNavigationFrame.top;
3816 }
3817 } else {
3818 // Landscape screen; nav bar goes to the right.
3819 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003820 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003821 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
3822 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
3823 if (transientNavBarShowing) {
3824 mNavigationBarController.setBarShowingLw(true);
3825 } else if (navVisible) {
3826 mNavigationBarController.setBarShowingLw(true);
3827 mDockRight = mTmpNavigationFrame.left;
3828 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3829 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
3830 } else {
3831 // We currently want to hide the navigation UI.
3832 mNavigationBarController.setBarShowingLw(false);
3833 }
3834 if (navVisible && !navTranslucent && !navAllowedHidden
3835 && !mNavigationBar.isAnimatingLw()
3836 && !mNavigationBarController.wasRecentlyTranslucent()) {
3837 // If the nav bar is currently requested to be visible,
3838 // and not in the process of animating on or off, then
3839 // we can tell the app that it is covered by it.
3840 mSystemRight = mTmpNavigationFrame.left;
3841 }
3842 }
3843 // Make sure the content and current rectangles are updated to
3844 // account for the restrictions from the navigation bar.
3845 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3846 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3847 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3848 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3849 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3850 // And compute the final frame.
3851 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
3852 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3853 mTmpNavigationFrame, mTmpNavigationFrame);
3854 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
3855 if (mNavigationBarController.checkHiddenLw()) {
3856 return true;
3857 }
3858 }
3859 return false;
3860 }
3861
Jorim Jaggi737af722015-12-31 10:42:27 +01003862 private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) {
3863 return !mNavigationBarCanMove || displayWidth < displayHeight;
3864 }
3865
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003866 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003867 @Override
John Spurlock46646232013-09-30 22:32:42 -04003868 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003869 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3870 return mStatusBar.getSurfaceLayer();
3871 }
3872
3873 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3874 return mNavigationBar.getSurfaceLayer();
3875 }
3876
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003877 return 0;
3878 }
3879
Craig Mautner967212c2013-04-13 21:10:58 -07003880 @Override
3881 public void getContentRectLw(Rect r) {
3882 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3883 }
3884
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003885 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3886 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003887 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3888 // Here's a special case: if this attached window is a panel that is
3889 // above the dock window, and the window it is attached to is below
3890 // the dock window, then the frames we computed for the window it is
3891 // attached to can not be used because the dock is effectively part
3892 // of the underlying window and the attached window is floating on top
3893 // of the whole thing. So, we ignore the attached window and explicitly
3894 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003895 df.left = of.left = cf.left = vf.left = mDockLeft;
3896 df.top = of.top = cf.top = vf.top = mDockTop;
3897 df.right = of.right = cf.right = vf.right = mDockRight;
3898 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003899 } else {
3900 // The effective display frame of the attached window depends on
3901 // whether it is taking care of insetting its content. If not,
3902 // we need to use the parent's content frame so that the entire
3903 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003904 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003905 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003906 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003907 // Set the content frame of the attached window to the parent's decor frame
3908 // (same as content frame when IME isn't present) if specifically requested by
3909 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3910 // Otherwise, use the overscan frame.
3911 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3912 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003913 } else {
3914 // If the window is resizing, then we want to base the content
3915 // frame on our attached content frame to resize... however,
3916 // things can be tricky if the attached window is NOT in resize
3917 // mode, in which case its content frame will be larger.
3918 // Ungh. So to deal with that, make sure the content frame
3919 // we end up using is not covering the IM dock.
3920 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003921 if (attached.isVoiceInteraction()) {
3922 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
3923 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
3924 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
3925 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
3926 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003927 if (cf.left < mContentLeft) cf.left = mContentLeft;
3928 if (cf.top < mContentTop) cf.top = mContentTop;
3929 if (cf.right > mContentRight) cf.right = mContentRight;
3930 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
3931 }
3932 }
3933 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003934 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003935 vf.set(attached.getVisibleFrameLw());
3936 }
3937 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
3938 // window should be positioned relative to its parent or the entire
3939 // screen.
3940 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
3941 ? attached.getFrameLw() : df);
3942 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003943
3944 private void applyStableConstraints(int sysui, int fl, Rect r) {
3945 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3946 // If app is requesting a stable layout, don't let the
3947 // content insets go below the stable values.
3948 if ((fl & FLAG_FULLSCREEN) != 0) {
3949 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
3950 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
3951 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
3952 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
3953 } else {
3954 if (r.left < mStableLeft) r.left = mStableLeft;
3955 if (r.top < mStableTop) r.top = mStableTop;
3956 if (r.right > mStableRight) r.right = mStableRight;
3957 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
3958 }
3959 }
3960 }
3961
Jorim Jaggiaa806142015-05-20 18:04:16 -07003962 private boolean canReceiveInput(WindowState win) {
3963 boolean notFocusable =
3964 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
3965 boolean altFocusableIm =
3966 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
3967 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
3968 return !notFocusableForIm;
3969 }
3970
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003971 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003972 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07003973 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07003974 // We've already done the navigation bar and status bar. If the status bar can receive
3975 // input, we need to layout it again to accomodate for the IME window.
3976 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003977 return;
3978 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07003979 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07003980 final boolean isDefaultDisplay = win.isDefaultDisplay();
3981 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09003982 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
3983 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07003984 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09003985 offsetInputMethodWindowLw(mLastInputMethodWindow);
3986 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003987
John Spurlockc6d1c602014-01-17 15:22:06 -05003988 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003989 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05003990 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003991
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003992 final Rect pf = mTmpParentFrame;
3993 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003994 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003995 final Rect cf = mTmpContentFrame;
3996 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003997 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07003998 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07003999 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004000 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004001
4002 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004003 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004004
Craig Mautnerf683b562012-10-02 11:10:57 -07004005 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4006
Adrian Roosfa104232014-06-20 16:10:14 -07004007 if (isDefaultDisplay) {
4008 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4009 } else {
4010 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4011 }
4012
Craig Mautner69b08182012-09-05 13:07:13 -07004013 if (!isDefaultDisplay) {
4014 if (attached != null) {
4015 // If this window is attached to another, our display
4016 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004017 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004018 } else {
4019 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004020 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4021 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4022 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004023 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004024 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004025 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004026 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004027 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004028 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4029 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4030 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004031 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004032 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004033 // ...with content insets above the nav bar
4034 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004035 // IM dock windows always go to the bottom of the screen.
4036 attrs.gravity = Gravity.BOTTOM;
4037 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004038 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004039 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004040 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004041 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4042 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004043 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004044 // Note: In Phone landscape mode, the button bar should also be excluded.
4045 cf.right = vf.right = mStableRight;
4046 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004047 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07004048 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004049 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4050 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4051 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4052 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4053 cf.left = vf.left = mStableLeft;
4054 cf.top = vf.top = mStableTop;
4055 cf.right = vf.right = mStableRight;
4056 vf.bottom = mStableBottom;
4057 cf.bottom = mContentBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004058 } else {
John Spurlock46646232013-09-30 22:32:42 -04004059
4060 // Default policy decor for the default display
4061 dcf.left = mSystemLeft;
4062 dcf.top = mSystemTop;
4063 dcf.right = mSystemRight;
4064 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004065 final boolean inheritTranslucentDecor = (attrs.privateFlags
4066 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004067 final boolean isAppWindow =
4068 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4069 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4070 final boolean topAtRest =
4071 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4072 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004073 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4074 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004075 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4076 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004077 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
4078 && !mForceWindowDrawsStatusBarBackground) {
John Spurlock46646232013-09-30 22:32:42 -04004079 // Ensure policy decor includes status bar
4080 dcf.top = mStableTop;
4081 }
John Spurlockbd957402013-10-03 11:38:39 -04004082 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004083 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4084 && (fl & WindowManager.LayoutParams.
4085 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004086 // Ensure policy decor includes navigation bar
4087 dcf.bottom = mStableBottom;
4088 dcf.right = mStableRight;
4089 }
4090 }
4091
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004092 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4093 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004094 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004095 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004096 // This is the case for a normal activity window: we want it
4097 // to cover all of the screen space, and it can take care of
4098 // moving its contents to account for screen decorations that
4099 // intrude into that space.
4100 if (attached != null) {
4101 // If this window is attached to another, our display
4102 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004103 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004104 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004105 if (attrs.type == TYPE_STATUS_BAR_PANEL
4106 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004107 // Status bar panels are the only windows who can go on top of
4108 // the status bar. They are protected by the STATUS_BAR_SERVICE
4109 // permission, so they have the same privileges as the status
4110 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004111 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004112 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004113
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004114 pf.left = df.left = of.left = hasNavBar
4115 ? mDockLeft : mUnrestrictedScreenLeft;
4116 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4117 pf.right = df.right = of.right = hasNavBar
4118 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4119 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4120 pf.bottom = df.bottom = of.bottom = hasNavBar
4121 ? mRestrictedScreenTop+mRestrictedScreenHeight
4122 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004123
Craig Mautnereda67292013-04-28 13:50:14 -07004124 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004125 "Laying out status bar window: (%d,%d - %d,%d)",
4126 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004127 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004128 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4129 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4130 // Asking to layout into the overscan region, so give it that pure
4131 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004132 pf.left = df.left = of.left = mOverscanScreenLeft;
4133 pf.top = df.top = of.top = mOverscanScreenTop;
4134 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4135 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4136 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004137 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004138 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004139 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4140 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004141 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004142 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004143 // only do this for application windows to ensure no window that
4144 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004145 pf.left = df.left = mOverscanScreenLeft;
4146 pf.top = df.top = mOverscanScreenTop;
4147 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4148 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004149 // We need to tell the app about where the frame inside the overscan
4150 // is, so it can inset its content by that amount -- it didn't ask
4151 // to actually extend itself into the overscan region.
4152 of.left = mUnrestrictedScreenLeft;
4153 of.top = mUnrestrictedScreenTop;
4154 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4155 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004156 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004157 pf.left = df.left = mRestrictedOverscanScreenLeft;
4158 pf.top = df.top = mRestrictedOverscanScreenTop;
4159 pf.right = df.right = mRestrictedOverscanScreenLeft
4160 + mRestrictedOverscanScreenWidth;
4161 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4162 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004163 // We need to tell the app about where the frame inside the overscan
4164 // is, so it can inset its content by that amount -- it didn't ask
4165 // to actually extend itself into the overscan region.
4166 of.left = mUnrestrictedScreenLeft;
4167 of.top = mUnrestrictedScreenTop;
4168 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4169 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004170 }
Craig Mautner69b08182012-09-05 13:07:13 -07004171
John Spurlock46646232013-09-30 22:32:42 -04004172 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004173 if (win.isVoiceInteraction()) {
4174 cf.left = mVoiceContentLeft;
4175 cf.top = mVoiceContentTop;
4176 cf.right = mVoiceContentRight;
4177 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004178 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004179 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4180 cf.left = mDockLeft;
4181 cf.top = mDockTop;
4182 cf.right = mDockRight;
4183 cf.bottom = mDockBottom;
4184 } else {
4185 cf.left = mContentLeft;
4186 cf.top = mContentTop;
4187 cf.right = mContentRight;
4188 cf.bottom = mContentBottom;
4189 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004190 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004191 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004192 // Full screen windows are always given a layout that is as if the
4193 // status bar and other transient decors are gone. This is to avoid
4194 // bad states when moving from a window that is not hding the
4195 // status bar to one that is.
4196 cf.left = mRestrictedScreenLeft;
4197 cf.top = mRestrictedScreenTop;
4198 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4199 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004200 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004201 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004202 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4203 vf.left = mCurLeft;
4204 vf.top = mCurTop;
4205 vf.right = mCurRight;
4206 vf.bottom = mCurBottom;
4207 } else {
4208 vf.set(cf);
4209 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004210 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004211 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4212 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4213 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004214 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4215 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004216 // A window that has requested to fill the entire screen just
4217 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004218 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004219 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4220 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004221 pf.left = df.left = of.left = cf.left = hasNavBar
4222 ? mDockLeft : mUnrestrictedScreenLeft;
4223 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4224 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004225 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004226 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004227 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004228 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004229 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004230 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004231 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4232 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004233 } else if (attrs.type == TYPE_NAVIGATION_BAR
4234 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004235 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004236 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4237 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4238 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4239 + mUnrestrictedScreenWidth;
4240 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4241 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004242 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004243 "Laying out navigation bar window: (%d,%d - %d,%d)",
4244 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004245 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4246 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004247 && ((fl & FLAG_FULLSCREEN) != 0)) {
4248 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004249 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4250 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4251 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4252 + mOverscanScreenWidth;
4253 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4254 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004255 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004256 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004257 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4258 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4259 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4260 + mOverscanScreenWidth;
4261 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4262 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004263 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004264 // The wallpaper also has Real Ultimate Power, but we want to tell
4265 // it about the overscan area.
4266 pf.left = df.left = mOverscanScreenLeft;
4267 pf.top = df.top = mOverscanScreenTop;
4268 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4269 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4270 of.left = cf.left = mUnrestrictedScreenLeft;
4271 of.top = cf.top = mUnrestrictedScreenTop;
4272 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4273 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004274 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004275 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4276 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4277 // Asking to layout into the overscan region, so give it that pure
4278 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004279 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4280 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4281 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004282 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004283 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004284 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004285 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004286 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004287 && (attrs.type == TYPE_STATUS_BAR
4288 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01004289 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004290 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004291 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4292 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004293 // Asking for layout as if the nav bar is hidden, lets the
4294 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004295 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004296 // can be above the nav bar can do this.
4297 // XXX This assumes that an app asking for this will also
4298 // ask for layout in only content. We can't currently figure out
4299 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004300 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4301 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4302 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4303 + mUnrestrictedScreenWidth;
4304 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4305 + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004306 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004307 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4308 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4309 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4310 + mRestrictedScreenWidth;
4311 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4312 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004313 }
Craig Mautner69b08182012-09-05 13:07:13 -07004314
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004315 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004316
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004317 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4318 vf.left = mCurLeft;
4319 vf.top = mCurTop;
4320 vf.right = mCurRight;
4321 vf.bottom = mCurBottom;
4322 } else {
4323 vf.set(cf);
4324 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004325 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004326 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4327 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004328 // A child window should be placed inside of the same visible
4329 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004330 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004331 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004332 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4333 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004334 // Otherwise, a normal window must be placed inside the content
4335 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004336 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4337 // Status bar panels and the volume dialog are the only windows who can go on
4338 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004339 // permission, so they have the same privileges as the status
4340 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004341 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4342 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4343 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4344 + mRestrictedScreenWidth;
4345 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4346 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004347 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004348 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004349 pf.left = df.left = of.left = cf.left = mStableLeft;
4350 pf.top = df.top = of.top = cf.top = mStableTop;
4351 pf.right = df.right = of.right = cf.right = mStableRight;
4352 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004353 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004354 pf.left = mContentLeft;
4355 pf.top = mContentTop;
4356 pf.right = mContentRight;
4357 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004358 if (win.isVoiceInteraction()) {
4359 df.left = of.left = cf.left = mVoiceContentLeft;
4360 df.top = of.top = cf.top = mVoiceContentTop;
4361 df.right = of.right = cf.right = mVoiceContentRight;
4362 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4363 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004364 df.left = of.left = cf.left = mDockLeft;
4365 df.top = of.top = cf.top = mDockTop;
4366 df.right = of.right = cf.right = mDockRight;
4367 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004368 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004369 df.left = of.left = cf.left = mContentLeft;
4370 df.top = of.top = cf.top = mContentTop;
4371 df.right = of.right = cf.right = mContentRight;
4372 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004373 }
4374 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4375 vf.left = mCurLeft;
4376 vf.top = mCurTop;
4377 vf.right = mCurRight;
4378 vf.bottom = mCurBottom;
4379 } else {
4380 vf.set(cf);
4381 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004382 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004383 }
4384 }
Craig Mautner69b08182012-09-05 13:07:13 -07004385
Craig Mautnerb816bed2013-07-23 10:26:17 -07004386 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4387 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004388 df.left = df.top = -10000;
4389 df.right = df.bottom = 10000;
4390 if (attrs.type != TYPE_WALLPAPER) {
4391 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4392 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4393 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004394 }
4395
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004396 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4397 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004398 // We only want to apply outsets to certain types of windows. For example, we never want to
4399 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004400 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004401 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004402 osf = mTmpOutsetFrame;
4403 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4404 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4405 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004406 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004407 if (rotation == Surface.ROTATION_0) {
4408 osf.bottom += outset;
4409 } else if (rotation == Surface.ROTATION_90) {
4410 osf.right += outset;
4411 } else if (rotation == Surface.ROTATION_180) {
4412 osf.top -= outset;
4413 } else if (rotation == Surface.ROTATION_270) {
4414 osf.left -= outset;
4415 }
4416 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4417 + " with rotation " + rotation + ", result: " + osf);
4418 }
4419 }
4420
Craig Mautnereda67292013-04-28 13:50:14 -07004421 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004422 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004423 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004424 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004425 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004426 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004427 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004428 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004429 + " sf=" + sf.toShortString()
4430 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004431
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004432 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004433
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004434 // Dock windows carve out the bottom of the screen, so normal windows
4435 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004436 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4437 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004438 setLastInputMethodWindowLw(null, null);
4439 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004440 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004441 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4442 && !win.getGivenInsetsPendingLw()) {
4443 offsetVoiceInputWindowLw(win);
4444 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004445 }
4446
satok1bc0a492012-04-25 22:47:12 +09004447 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004448 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004449 top += win.getGivenContentInsetsLw().top;
4450 if (mContentBottom > top) {
4451 mContentBottom = top;
4452 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004453 if (mVoiceContentBottom > top) {
4454 mVoiceContentBottom = top;
4455 }
satok1bc0a492012-04-25 22:47:12 +09004456 top = win.getVisibleFrameLw().top;
4457 top += win.getGivenVisibleInsetsLw().top;
4458 if (mCurBottom > top) {
4459 mCurBottom = top;
4460 }
Craig Mautnereda67292013-04-28 13:50:14 -07004461 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004462 + mDockBottom + " mContentBottom="
4463 + mContentBottom + " mCurBottom=" + mCurBottom);
4464 }
4465
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004466 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004467 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004468 top += win.getGivenContentInsetsLw().top;
4469 if (mVoiceContentBottom > top) {
4470 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004471 }
4472 }
4473
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004474 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004475 @Override
4476 public void finishLayoutLw() {
4477 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004478 }
4479
4480 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004481 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004482 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004483 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004484 mTopFullscreenOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004485 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004486 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004487 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004488 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004489 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004490 mForcingShowNavBar = false;
4491 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004492
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004493 mHideLockScreen = false;
4494 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004495 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004496 mShowingLockscreen = false;
4497 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004498 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004499 mKeyguardSecure = isKeyguardSecure();
4500 mKeyguardSecureIncludingHidden = mKeyguardSecure
4501 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004502 }
4503
4504 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004505 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004506 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4507 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004508 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4509 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004510 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004511 if (mTopFullscreenOpaqueWindowState == null
4512 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4513 mForcingShowNavBar = true;
4514 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004515 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004516 if (attrs.type == TYPE_STATUS_BAR) {
4517 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4518 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004519 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004520 }
4521 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4522 mForceStatusBarTransparent = true;
4523 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004524 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004525
4526 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4527 && attrs.type < FIRST_SYSTEM_WINDOW;
4528 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4529 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
4530
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004531 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004532 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004533 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004534 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004535 mForceStatusBarFromKeyguard = true;
4536 } else {
4537 mForceStatusBar = true;
4538 }
4539 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004540 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004541 // If the lockscreen was showing when the dream started then wait
4542 // for the dream to draw before hiding the lockscreen.
4543 if (!mDreamingLockscreen
4544 || (win.isVisibleLw() && win.hasDrawnLw())) {
4545 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004546 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004547 }
4548 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004549
Yohei Yukawad1a09222015-06-30 16:22:05 -07004550 final IApplicationToken appToken = win.getAppToken();
4551
4552 // For app windows that are not attached, we decide if all windows in the app they
4553 // represent should be hidden or if we should hide the lockscreen. For attached app
4554 // windows we defer the decision to the window it is attached to.
4555 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004556 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004557 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004558 mAppsToBeHidden.remove(appToken);
4559 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004560 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004561 if (dismissKeyguard && !mKeyguardSecure) {
4562 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004563 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004564 mWinShowWhenLocked = win;
4565 mHideLockScreen = true;
4566 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004567 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004568 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004569 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004570 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004571 mAppsToBeHidden.add(appToken);
4572 } else {
4573 mAppsToBeHidden.remove(appToken);
4574 }
4575 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004576 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004577 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004578 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004579 if (attrs.x == 0 && attrs.y == 0
4580 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4581 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT) {
4582 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4583 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004584 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4585 mTopFullscreenOpaqueOrDimmingWindowState = win;
4586 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004587 if (!mAppsThatDismissKeyguard.isEmpty() &&
4588 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4589 if (DEBUG_LAYOUT) Slog.v(TAG,
4590 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004591 mDismissKeyguard = (mWinDismissingKeyguard == win
4592 && mSecureDismissingKeyguard == mKeyguardSecure)
4593 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004594 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004595 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004596 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004597 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4598 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004599 if (DEBUG_LAYOUT) Slog.v(TAG,
4600 "Setting mHideLockScreen to true by win " + win);
4601 mHideLockScreen = true;
4602 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004603 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004604 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004605 mAllowLockscreenWhenOn = true;
4606 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004607 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004608
4609 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004610 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4611 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004612 win.hideLw(false);
4613 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004614 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004615 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4616 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4617 // that is being hidden in an animation - keep the
4618 // keyguard hidden until the new window shows up and
4619 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004620 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004621 mHideLockScreen = true;
4622 mWinShowWhenLocked = win;
4623 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004624 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01004625 if (mTopFullscreenOpaqueOrDimmingWindowState == null
4626 && win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()
4627 && win.isDimming()) {
4628 mTopFullscreenOpaqueOrDimmingWindowState = win;
4629 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004630 }
4631
4632 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004633 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004634 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004635 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4636 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4637 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004638 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4639 // fullscreen window.
4640 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4641 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4642 mTopFullscreenOpaqueWindowState.hideLw(false);
4643 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4644 }
4645
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004646 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004647 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004648
4649 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4650 ? mTopFullscreenOpaqueWindowState.getAttrs()
4651 : null;
4652
Jeff Brownc8018eb2012-10-29 21:33:27 -07004653 // If we are not currently showing a dream then remember the current
4654 // lockscreen state. We will use this to determine whether the dream
4655 // started while the lockscreen was showing and remember this state
4656 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004657 if (!mShowingDream) {
4658 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004659 if (mDreamingSleepTokenNeeded) {
4660 mDreamingSleepTokenNeeded = false;
4661 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4662 }
4663 } else {
4664 if (!mDreamingSleepTokenNeeded) {
4665 mDreamingSleepTokenNeeded = true;
4666 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4667 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004668 }
4669
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004670 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004671 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004672 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004673 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004674 boolean shouldBeTransparent = mForceStatusBarTransparent
4675 && !mForceStatusBar
4676 && !mForceStatusBarFromKeyguard;
4677 if (!shouldBeTransparent) {
4678 mStatusBarController.setShowTransparent(false /* transparent */);
4679 } else if (!mStatusBar.isVisibleLw()) {
4680 mStatusBarController.setShowTransparent(true /* transparent */);
4681 }
4682 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004683 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004684 if (mStatusBarController.setBarShowingLw(true)) {
4685 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4686 }
Craig Mautner81defc72013-10-29 11:10:42 -07004687 // Maintain fullscreen layout until incoming animation is complete.
4688 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004689 // Transient status bar on the lockscreen is not allowed
4690 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4691 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4692 mLastSystemUiFlags, mLastSystemUiFlags);
4693 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004694 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004695 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004696 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004697 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004698 + " shown position: "
4699 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004700 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004701 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004702 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004703 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004704 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004705 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004706 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004707 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4708 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004709 if (mStatusBarController.isTransientShowing()) {
4710 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004711 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4712 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07004713 } else if (topIsFullscreen
4714 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
4715 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07004716 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004717 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004718 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004719 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004720 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004721 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004722 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004723 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004724 if (mStatusBarController.setBarShowingLw(true)) {
4725 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4726 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004727 }
4728 }
4729 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004730
Craig Mautner81defc72013-10-29 11:10:42 -07004731 if (mTopIsFullscreen != topIsFullscreen) {
4732 if (!topIsFullscreen) {
4733 // Force another layout when status bar becomes fully shown.
4734 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4735 }
4736 mTopIsFullscreen = topIsFullscreen;
4737 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004738
Craig Mautner39834192012-09-02 07:47:24 -07004739 // Hide the key guard if a visible window explicitly specifies that it wants to be
4740 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004741 if (mKeyguardDelegate != null && mStatusBar != null) {
4742 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4743 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004744 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004745 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004746 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004747 changes |= FINISH_LAYOUT_REDO_LAYOUT
4748 | FINISH_LAYOUT_REDO_CONFIG
4749 | FINISH_LAYOUT_REDO_WALLPAPER;
4750 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004751 if (mKeyguardDelegate.isShowing()) {
4752 mHandler.post(new Runnable() {
4753 @Override
4754 public void run() {
4755 mKeyguardDelegate.keyguardDone(false, false);
4756 }
4757 });
4758 }
4759 } else if (mHideLockScreen) {
4760 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004761 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004762 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004763 changes |= FINISH_LAYOUT_REDO_LAYOUT
4764 | FINISH_LAYOUT_REDO_CONFIG
4765 | FINISH_LAYOUT_REDO_WALLPAPER;
4766 }
4767 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004768 mKeyguardHidden = false;
4769 if (setKeyguardOccludedLw(false)) {
4770 changes |= FINISH_LAYOUT_REDO_LAYOUT
4771 | FINISH_LAYOUT_REDO_CONFIG
4772 | FINISH_LAYOUT_REDO_WALLPAPER;
4773 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004774 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4775 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004776 mHandler.post(new Runnable() {
4777 @Override
4778 public void run() {
4779 mKeyguardDelegate.dismiss();
4780 }
4781 });
4782 }
4783 } else {
4784 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004785 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004786 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004787 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004788 changes |= FINISH_LAYOUT_REDO_LAYOUT
4789 | FINISH_LAYOUT_REDO_CONFIG
4790 | FINISH_LAYOUT_REDO_WALLPAPER;
4791 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004792 }
4793 }
Joe Onorato664644d2011-01-23 17:53:23 -08004794
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004795 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004796 // If the navigation bar has been hidden or shown, we need to do another
4797 // layout pass to update that window.
4798 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4799 }
Joe Onorato664644d2011-01-23 17:53:23 -08004800
Mike Lockwood28569302010-01-28 11:54:40 -05004801 // update since mAllowLockscreenWhenOn might have changed
4802 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004803 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004804 }
4805
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004806 /**
Jim Millerab954542014-10-10 18:21:49 -07004807 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004808 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004809 * @return Whether the flags have changed and we have to redo the layout.
4810 */
Jim Millerab954542014-10-10 18:21:49 -07004811 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4812 boolean wasOccluded = mKeyguardOccluded;
4813 boolean showing = mKeyguardDelegate.isShowing();
4814 if (wasOccluded && !isOccluded && showing) {
4815 mKeyguardOccluded = false;
4816 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004817 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4818 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4819 return true;
Jim Millerab954542014-10-10 18:21:49 -07004820 } else if (!wasOccluded && isOccluded && showing) {
4821 mKeyguardOccluded = true;
4822 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004823 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4824 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4825 return true;
4826 } else {
4827 return false;
4828 }
4829 }
4830
4831 private boolean isStatusBarKeyguard() {
4832 return mStatusBar != null
4833 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4834 }
4835
Jose Lima9546b202014-07-02 17:21:51 -07004836 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004837 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004838 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004839 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004840 return false;
4841 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004842 return true;
4843 }
4844
Jose Lima9546b202014-07-02 17:21:51 -07004845 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004846 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004847 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004848 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004849 // If the navigation bar has been hidden or shown, we need to do another
4850 // layout pass to update that window.
4851 return FINISH_LAYOUT_REDO_LAYOUT;
4852 }
4853 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004854 }
4855
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004856 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004857 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004858 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4859 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004860 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4861 if (newLidState == mLidState) {
4862 return;
4863 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004864
Jeff Brownc458ce92012-04-30 14:58:40 -07004865 mLidState = newLidState;
4866 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004867 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07004868
4869 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004870 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
4871 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07004872 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07004873 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07004874 }
4875 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004876
Michael Wright3818c922014-09-02 13:59:07 -07004877 @Override
4878 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
4879 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
4880 if (mCameraLensCoverState == lensCoverState) {
4881 return;
4882 }
4883 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
4884 lensCoverState == CAMERA_LENS_UNCOVERED) {
4885 Intent intent;
4886 final boolean keyguardActive = mKeyguardDelegate == null ? false :
4887 mKeyguardDelegate.isShowing();
4888 if (keyguardActive) {
4889 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
4890 } else {
4891 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
4892 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07004893 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
4894 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00004895 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07004896 }
4897 mCameraLensCoverState = lensCoverState;
4898 }
4899
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004900 void setHdmiPlugged(boolean plugged) {
4901 if (mHdmiPlugged != plugged) {
4902 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004903 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004904 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08004905 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004906 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07004907 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08004908 }
4909 }
4910
Joe Onoratoea495d42011-04-06 11:41:11 -07004911 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07004912 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07004913 // watch for HDMI plug messages if the hdmi switch exists
4914 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
4915 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
4916
Joe Onoratoea495d42011-04-06 11:41:11 -07004917 final String filename = "/sys/class/switch/hdmi/state";
4918 FileReader reader = null;
4919 try {
4920 reader = new FileReader(filename);
4921 char[] buf = new char[15];
4922 int n = reader.read(buf);
4923 if (n > 1) {
4924 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
4925 }
4926 } catch (IOException ex) {
4927 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4928 } catch (NumberFormatException ex) {
4929 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
4930 } finally {
4931 if (reader != null) {
4932 try {
4933 reader.close();
4934 } catch (IOException ex) {
4935 }
Joe Onoratodc100302011-01-11 17:07:41 -08004936 }
4937 }
4938 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07004939 // This dance forces the code in setHdmiPlugged to run.
4940 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
4941 mHdmiPlugged = !plugged;
4942 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08004943 }
4944
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07004945 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004946 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004947
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004948 final Runnable mScreenshotTimeout = new Runnable() {
4949 @Override public void run() {
4950 synchronized (mScreenshotLock) {
4951 if (mScreenshotConnection != null) {
4952 mContext.unbindService(mScreenshotConnection);
4953 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07004954 }
Winson Chung9112ec32011-06-27 13:15:32 -07004955 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004956 }
4957 };
4958
4959 // Assume this is called from the Handler thread.
4960 private void takeScreenshot() {
4961 synchronized (mScreenshotLock) {
4962 if (mScreenshotConnection != null) {
4963 return;
4964 }
4965 ComponentName cn = new ComponentName("com.android.systemui",
4966 "com.android.systemui.screenshot.TakeScreenshotService");
4967 Intent intent = new Intent();
4968 intent.setComponent(cn);
4969 ServiceConnection conn = new ServiceConnection() {
4970 @Override
4971 public void onServiceConnected(ComponentName name, IBinder service) {
4972 synchronized (mScreenshotLock) {
4973 if (mScreenshotConnection != this) {
4974 return;
4975 }
4976 Messenger messenger = new Messenger(service);
4977 Message msg = Message.obtain(null, 1);
4978 final ServiceConnection myConn = this;
4979 Handler h = new Handler(mHandler.getLooper()) {
4980 @Override
4981 public void handleMessage(Message msg) {
4982 synchronized (mScreenshotLock) {
4983 if (mScreenshotConnection == myConn) {
4984 mContext.unbindService(mScreenshotConnection);
4985 mScreenshotConnection = null;
4986 mHandler.removeCallbacks(mScreenshotTimeout);
4987 }
4988 }
4989 }
4990 };
4991 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07004992 msg.arg1 = msg.arg2 = 0;
4993 if (mStatusBar != null && mStatusBar.isVisibleLw())
4994 msg.arg1 = 1;
4995 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
4996 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07004997 try {
4998 messenger.send(msg);
4999 } catch (RemoteException e) {
5000 }
5001 }
5002 }
5003 @Override
5004 public void onServiceDisconnected(ComponentName name) {}
5005 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08005006 if (mContext.bindServiceAsUser(
5007 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005008 mScreenshotConnection = conn;
5009 mHandler.postDelayed(mScreenshotTimeout, 10000);
5010 }
5011 }
Winson Chung9112ec32011-06-27 13:15:32 -07005012 }
5013
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005014 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005015 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005016 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005017 if (!mSystemBooted) {
5018 // If we have not yet booted, don't let key events do anything.
5019 return 0;
5020 }
5021
Jeff Brown037c33e2014-04-09 00:31:55 -07005022 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005023 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5024 final boolean canceled = event.isCanceled();
5025 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005026
Jeff Brown3122e442010-10-11 23:32:49 -07005027 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005028
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005029 // If screen is off then we treat the case where the keyguard is open but hidden
5030 // the same as if it were open and in front.
5031 // This will prevent any keys other than the power button from waking the screen
5032 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005033 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005034 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005035 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005036 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005037
Jeff Brown40013652012-05-16 21:22:36 -07005038 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005039 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005040 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005041 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005042 }
5043
Jeff Brown037c33e2014-04-09 00:31:55 -07005044 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005045 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005046 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5047 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005048 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005049 // When the device is interactive or the key is injected pass the
5050 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005051 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005052 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07005053 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
5054 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5055 // to the application but preserve its wake key status to make sure we still move
5056 // from dozing to fully interactive if we would normally go from off to fully
5057 // interactive.
5058 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07005059 } else {
5060 // When the screen is off and the key is not injected, determine whether
5061 // to wake the device but don't pass the key to the application.
5062 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005063 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5064 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005065 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005066 }
5067
Justin Kohd378ad72013-04-01 12:18:26 -07005068 // If the key would be handled globally, just return the result, don't worry about special
5069 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005070 if (isValidGlobalKey(keyCode)
5071 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005072 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005073 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005074 }
Justin Kohd378ad72013-04-01 12:18:26 -07005075 return result;
5076 }
5077
Jeff Brownbae8e772014-06-12 19:59:45 -07005078 boolean useHapticFeedback = down
5079 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5080 && event.getRepeatCount() == 0;
5081
Jeff Brown4d396052010-10-29 21:50:21 -07005082 // Handle special keys.
5083 switch (keyCode) {
5084 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005085 case KeyEvent.KEYCODE_VOLUME_UP:
5086 case KeyEvent.KEYCODE_VOLUME_MUTE: {
RoboErik001c59c2015-01-26 15:53:51 -08005087 if (mUseTvRouting) {
5088 // On TVs volume keys never go to the foreground app
5089 result &= ~ACTION_PASS_TO_USER;
5090 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005091 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5092 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005093 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005094 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005095 mScreenshotChordVolumeDownKeyTriggered = true;
5096 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5097 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005098 cancelPendingPowerKeyAction();
5099 interceptScreenshotChord();
5100 }
5101 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005102 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005103 cancelPendingScreenshotChordAction();
5104 }
5105 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5106 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005107 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005108 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005109 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005110 cancelPendingPowerKeyAction();
5111 cancelPendingScreenshotChordAction();
5112 }
5113 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005114 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005115 cancelPendingScreenshotChordAction();
5116 }
5117 }
Jeff Brown4d396052010-10-29 21:50:21 -07005118 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005119 TelecomManager telecomManager = getTelecommService();
5120 if (telecomManager != null) {
5121 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005122 // If an incoming call is ringing, either VOLUME key means
5123 // "silence ringer". We handle these keys here, rather than
5124 // in the InCallScreen, to make sure we'll respond to them
5125 // even if the InCallScreen hasn't come to the foreground yet.
5126 // Look for the DOWN event here, to agree with the "fallback"
5127 // behavior in the InCallScreen.
5128 Log.i(TAG, "interceptKeyBeforeQueueing:"
5129 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005130
Santos Cordon6848f722014-05-21 15:22:12 -07005131 // Silence the ringer. (It's safe to call this
5132 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005133 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005134
Santos Cordon6848f722014-05-21 15:22:12 -07005135 // And *don't* pass this key thru to the current activity
5136 // (which is probably the InCallScreen.)
5137 result &= ~ACTION_PASS_TO_USER;
5138 break;
5139 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005140 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005141 && (result & ACTION_PASS_TO_USER) == 0) {
5142 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005143 // the application, just pass it to the session service.
5144
5145 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005146 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005147 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005148 }
5149 }
5150
RoboErik430fc482014-06-12 15:49:20 -07005151 if ((result & ACTION_PASS_TO_USER) == 0) {
RoboErik001c59c2015-01-26 15:53:51 -08005152 if (mUseTvRouting) {
5153 dispatchDirectAudioEvent(event);
5154 } else {
5155 // If we aren't passing to the user and no one else
5156 // handled it send it to the session manager to
5157 // figure out.
5158 MediaSessionLegacyHelper.getHelper(mContext)
5159 .sendVolumeKeyEvent(event, true);
5160 }
Jeff Brown4d396052010-10-29 21:50:21 -07005161 break;
5162 }
5163 }
5164 break;
5165 }
5166
5167 case KeyEvent.KEYCODE_ENDCALL: {
5168 result &= ~ACTION_PASS_TO_USER;
5169 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005170 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005171 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005172 if (telecomManager != null) {
5173 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005174 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005175 if (interactive && !hungUp) {
5176 mEndCallKeyHandled = false;
5177 mHandler.postDelayed(mEndCallLongPress,
5178 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5179 } else {
5180 mEndCallKeyHandled = true;
5181 }
Jeff Brown4d396052010-10-29 21:50:21 -07005182 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005183 if (!mEndCallKeyHandled) {
5184 mHandler.removeCallbacks(mEndCallLongPress);
5185 if (!canceled) {
5186 if ((mEndcallBehavior
5187 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5188 if (goHome()) {
5189 break;
5190 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005191 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005192 if ((mEndcallBehavior
5193 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5194 mPowerManager.goToSleep(event.getEventTime(),
5195 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5196 isWakeKey = false;
5197 }
Jeff Brown4d396052010-10-29 21:50:21 -07005198 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005199 }
Jeff Brown4d396052010-10-29 21:50:21 -07005200 }
5201 break;
5202 }
5203
5204 case KeyEvent.KEYCODE_POWER: {
5205 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005206 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005207 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005208 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005209 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005210 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005211 }
5212 break;
5213 }
5214
Jeff Brown6212a492014-03-07 13:58:47 -08005215 case KeyEvent.KEYCODE_SLEEP: {
5216 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005217 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005218 if (!mPowerManager.isInteractive()) {
5219 useHapticFeedback = false; // suppress feedback if already non-interactive
5220 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005221 if (down) {
5222 sleepPress(event.getEventTime());
5223 } else {
5224 sleepRelease(event.getEventTime());
5225 }
Jeff Brown6212a492014-03-07 13:58:47 -08005226 break;
5227 }
5228
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005229 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5230 result &= ~ACTION_PASS_TO_USER;
5231 isWakeKey = false;
5232 if (!down) {
5233 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5234 }
5235 break;
5236 }
5237
Jeff Brown6212a492014-03-07 13:58:47 -08005238 case KeyEvent.KEYCODE_WAKEUP: {
5239 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005240 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005241 break;
5242 }
5243
Jeff Brown4d396052010-10-29 21:50:21 -07005244 case KeyEvent.KEYCODE_MEDIA_PLAY:
5245 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5246 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005247 case KeyEvent.KEYCODE_HEADSETHOOK:
5248 case KeyEvent.KEYCODE_MUTE:
5249 case KeyEvent.KEYCODE_MEDIA_STOP:
5250 case KeyEvent.KEYCODE_MEDIA_NEXT:
5251 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5252 case KeyEvent.KEYCODE_MEDIA_REWIND:
5253 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005254 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5255 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005256 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5257 // If the global session is active pass all media keys to it
5258 // instead of the active window.
5259 result &= ~ACTION_PASS_TO_USER;
5260 }
Jeff Brown4d396052010-10-29 21:50:21 -07005261 if ((result & ACTION_PASS_TO_USER) == 0) {
5262 // Only do this if we would otherwise not pass it to the user. In that
5263 // case, the PhoneWindow class will do the same thing, except it will
5264 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005265 // Note that we need to make a copy of the key event here because the
5266 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005267 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005268 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5269 new KeyEvent(event));
5270 msg.setAsynchronous(true);
5271 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005272 }
5273 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005274 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005275
Jeff Brown4d396052010-10-29 21:50:21 -07005276 case KeyEvent.KEYCODE_CALL: {
5277 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005278 TelecomManager telecomManager = getTelecommService();
5279 if (telecomManager != null) {
5280 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005281 Log.i(TAG, "interceptKeyBeforeQueueing:"
5282 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005283 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005284
Santos Cordon6848f722014-05-21 15:22:12 -07005285 // And *don't* pass this key thru to the current activity
5286 // (which is presumably the InCallScreen.)
5287 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005288 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005289 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005290 }
Jeff Brown4d396052010-10-29 21:50:21 -07005291 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005292 }
Michael Wright869a67c2014-08-26 19:33:06 -07005293 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5294 // Only do this if we would otherwise not pass it to the user. In that case,
5295 // interceptKeyBeforeDispatching would apply a similar but different policy in
5296 // order to invoke voice assist actions. Note that we need to make a copy of the
5297 // key event here because the original key event will be recycled when we return.
5298 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5299 mBroadcastWakeLock.acquire();
5300 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5301 keyguardActive ? 1 : 0, 0);
5302 msg.setAsynchronous(true);
5303 msg.sendToTarget();
5304 }
5305 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005306 }
Jeff Brown26875502014-01-30 21:47:47 -08005307
Jeff Brownbae8e772014-06-12 19:59:45 -07005308 if (useHapticFeedback) {
5309 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5310 }
5311
Jeff Brown26875502014-01-30 21:47:47 -08005312 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005313 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005314 }
Bryce Lee584a4452014-10-21 15:55:55 -07005315
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005316 return result;
5317 }
5318
Jeff Brown1c2e4942012-11-06 16:32:01 -08005319 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005320 * Returns true if the key can have global actions attached to it.
5321 * We reserve all power management keys for the system since they require
5322 * very careful handling.
5323 */
5324 private static boolean isValidGlobalKey(int keyCode) {
5325 switch (keyCode) {
5326 case KeyEvent.KEYCODE_POWER:
5327 case KeyEvent.KEYCODE_WAKEUP:
5328 case KeyEvent.KEYCODE_SLEEP:
5329 return false;
5330 default:
5331 return true;
5332 }
5333 }
5334
5335 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005336 * When the screen is off we ignore some keys that might otherwise typically
5337 * be considered wake keys. We filter them out here.
5338 *
5339 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5340 * is always considered a wake key.
5341 */
5342 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5343 switch (keyCode) {
5344 // ignore volume keys unless docked
5345 case KeyEvent.KEYCODE_VOLUME_UP:
5346 case KeyEvent.KEYCODE_VOLUME_DOWN:
5347 case KeyEvent.KEYCODE_VOLUME_MUTE:
5348 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5349
5350 // ignore media and camera keys
5351 case KeyEvent.KEYCODE_MUTE:
5352 case KeyEvent.KEYCODE_HEADSETHOOK:
5353 case KeyEvent.KEYCODE_MEDIA_PLAY:
5354 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5355 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5356 case KeyEvent.KEYCODE_MEDIA_STOP:
5357 case KeyEvent.KEYCODE_MEDIA_NEXT:
5358 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5359 case KeyEvent.KEYCODE_MEDIA_REWIND:
5360 case KeyEvent.KEYCODE_MEDIA_RECORD:
5361 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005362 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005363 case KeyEvent.KEYCODE_CAMERA:
5364 return false;
5365 }
5366 return true;
5367 }
5368
5369
Jeff Brown56194eb2011-03-02 19:23:13 -08005370 /** {@inheritDoc} */
5371 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005372 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5373 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005374 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5375 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005376 return 0;
5377 }
Michael Wright70af00a2014-09-03 19:30:20 -07005378 }
Bryce Lee5c138322014-11-03 08:26:09 -08005379
Michael Wright70af00a2014-09-03 19:30:20 -07005380 if (shouldDispatchInputWhenNonInteractive()) {
5381 return ACTION_PASS_TO_USER;
5382 }
Bryce Lee5c138322014-11-03 08:26:09 -08005383
Bryce Lee812d7022014-11-10 13:33:28 -08005384 // If we have not passed the action up and we are in theater mode without dreaming,
5385 // there will be no dream to intercept the touch and wake into ambient. The device should
5386 // wake up in this case.
5387 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005388 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5389 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005390 }
5391
Jeff Brown037c33e2014-04-09 00:31:55 -07005392 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005393 }
5394
Michael Wright70af00a2014-09-03 19:30:20 -07005395 private boolean shouldDispatchInputWhenNonInteractive() {
Joe LaPennaf2b9b2d2015-11-17 22:22:37 +00005396 // Send events to keyguard while the screen is on.
5397 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5398 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005399 return true;
5400 }
5401
5402 // Send events to a dozing dream even if the screen is off since the dream
5403 // is in control of the state of the screen.
5404 IDreamManager dreamManager = getDreamManager();
5405
5406 try {
5407 if (dreamManager != null && dreamManager.isDreaming()) {
5408 return true;
5409 }
5410 } catch (RemoteException e) {
5411 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5412 }
5413
5414 // Otherwise, consume events since the user can't see what is being
5415 // interacted with.
5416 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005417 }
5418
RoboErik001c59c2015-01-26 15:53:51 -08005419 private void dispatchDirectAudioEvent(KeyEvent event) {
5420 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5421 return;
5422 }
5423 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005424 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5425 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005426 String pkgName = mContext.getOpPackageName();
5427 switch (keyCode) {
5428 case KeyEvent.KEYCODE_VOLUME_UP:
5429 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005430 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005431 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005432 } catch (RemoteException e) {
5433 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5434 }
5435 break;
5436 case KeyEvent.KEYCODE_VOLUME_DOWN:
5437 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005438 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005439 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005440 } catch (RemoteException e) {
5441 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5442 }
5443 break;
5444 case KeyEvent.KEYCODE_VOLUME_MUTE:
5445 try {
5446 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005447 getAudioService().adjustSuggestedStreamVolume(
5448 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005449 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005450 }
5451 } catch (RemoteException e) {
5452 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5453 }
5454 break;
5455 }
5456 }
5457
Jeff Brown40013652012-05-16 21:22:36 -07005458 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5459 if (DEBUG_INPUT) {
5460 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005461 }
5462
Jeff Brown40013652012-05-16 21:22:36 -07005463 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5464 if (DEBUG_INPUT) {
5465 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5466 }
5467
5468 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5469 mHavePendingMediaKeyRepeatWithWakeLock = false;
5470 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5471 }
5472
5473 dispatchMediaKeyWithWakeLockToAudioService(event);
5474
5475 if (event.getAction() == KeyEvent.ACTION_DOWN
5476 && event.getRepeatCount() == 0) {
5477 mHavePendingMediaKeyRepeatWithWakeLock = true;
5478
5479 Message msg = mHandler.obtainMessage(
5480 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5481 msg.setAsynchronous(true);
5482 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5483 } else {
5484 mBroadcastWakeLock.release();
5485 }
5486 }
5487
5488 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5489 mHavePendingMediaKeyRepeatWithWakeLock = false;
5490
5491 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5492 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5493 if (DEBUG_INPUT) {
5494 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5495 }
5496
5497 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5498 mBroadcastWakeLock.release();
5499 }
5500
5501 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5502 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005503 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005504 }
5505 }
5506
Michael Wright869a67c2014-08-26 19:33:06 -07005507 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005508 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5509 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5510 if (dic != null) {
5511 try {
5512 dic.exitIdle("voice-search");
5513 } catch (RemoteException e) {
5514 }
5515 }
Michael Wright869a67c2014-08-26 19:33:06 -07005516 Intent voiceIntent =
5517 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5518 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005519 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005520 mBroadcastWakeLock.release();
5521 }
5522
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005523 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005524 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005525 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005526 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5527 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5528 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005529 } else {
5530 try {
5531 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5532 ServiceManager.getService(Context.UI_MODE_SERVICE));
5533 mUiMode = uiModeService.getCurrentModeType();
5534 } catch (RemoteException e) {
5535 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005536 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005537 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005538 synchronized (mLock) {
5539 updateOrientationListenerLp();
5540 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005541 }
5542 };
5543
Jeff Brown6aaf2952012-10-05 16:01:08 -07005544 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5545 @Override
5546 public void onReceive(Context context, Intent intent) {
5547 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005548 if (mKeyguardDelegate != null) {
5549 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005550 }
5551 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005552 if (mKeyguardDelegate != null) {
5553 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005554 }
5555 }
5556 }
5557 };
5558
Christopher Tate5e08af02012-09-21 17:17:22 -07005559 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5560 @Override
5561 public void onReceive(Context context, Intent intent) {
5562 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5563 // tickle the settings observer: this first ensures that we're
5564 // observing the relevant settings for the newly-active user,
5565 // and then updates our own bookkeeping based on the now-
5566 // current user.
5567 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005568
5569 // force a re-application of focused window sysui visibility.
5570 // the window may never have been shown for this user
5571 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005572 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005573 mLastSystemUiFlags = 0;
5574 updateSystemUiVisibilityLw();
5575 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005576 }
5577 }
5578 };
5579
Adrian Roosddc8b272015-05-21 16:28:27 -07005580 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005581 @Override
5582 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005583 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5584 if (!isUserSetupComplete()) {
5585 // Swipe-up for navigation bar is disabled during setup
5586 return;
5587 }
5588 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5589 mNavigationBarController.showTransient();
5590 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005591 }
5592 };
5593
John Spurlocke1f366f2013-08-05 12:22:40 -04005594 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005595 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005596 if (!isUserSetupComplete()) {
5597 // Swipe-up for navigation bar is disabled during setup
5598 return;
5599 }
John Spurlock27735a42013-08-14 17:57:38 -04005600 boolean sb = mStatusBarController.checkShowTransientBarLw();
5601 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005602 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005603 // Don't show status bar when swiping on already visible navigation bar
5604 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005605 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005606 return;
5607 }
John Spurlock27735a42013-08-14 17:57:38 -04005608 if (sb) mStatusBarController.showTransient();
5609 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005610 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005611 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005612 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005613 }
5614 }
5615
Jeff Brown3ee549c2014-09-22 20:14:39 -07005616 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005617 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005618 public void startedGoingToSleep(int why) {
5619 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005620 if (mKeyguardDelegate != null) {
5621 mKeyguardDelegate.onStartedGoingToSleep(why);
5622 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005623 }
5624
5625 // Called on the PowerManager's Notifier thread.
5626 @Override
5627 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005628 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005629 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005630 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005631
5632 // We must get this work done here because the power manager will drop
5633 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005634 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005635 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005636 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005637 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005638 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005639 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005640 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005641 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005642 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005643 }
5644
Jeff Brown3ee549c2014-09-22 20:14:39 -07005645 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005646 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005647 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005648 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005649 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005650
Jeff Brown3ee549c2014-09-22 20:14:39 -07005651 // Since goToSleep performs these functions synchronously, we must
5652 // do the same here. We cannot post this work to a handler because
5653 // that might cause it to become reordered with respect to what
5654 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005655 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005656 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005657
Jeff Browna20dda42014-05-27 20:57:24 -07005658 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005659 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005660 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005661 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005662
Jim Miller5ecd8112013-01-09 18:50:26 -08005663 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005664 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005665 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005666 }
5667
Jeff Brown416c49c2015-05-26 19:50:18 -07005668 // Called on the PowerManager's Notifier thread.
5669 @Override
5670 public void finishedWakingUp() {
5671 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5672 }
5673
5674 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005675 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07005676 }
5677
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005678 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07005679 final boolean theaterModeEnabled = isTheaterModeEnabled();
5680 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005681 return false;
5682 }
5683
Bryce Leed3896842015-06-23 17:06:51 -07005684 if (theaterModeEnabled) {
5685 Settings.Global.putInt(mContext.getContentResolver(),
5686 Settings.Global.THEATER_MODE_ON, 0);
5687 }
5688
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005689 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07005690 return true;
5691 }
5692
Jeff Brown36c4db82014-09-19 12:05:31 -07005693 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005694 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07005695 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005696 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005697 }
5698
Jeff Brown36c4db82014-09-19 12:05:31 -07005699 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005700 if (mKeyguardDelegate != null) {
5701 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5702 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005703 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005704 }
5705
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005706 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5707 // as well as enabling the orientation change logic/sensor.
5708 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5709 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005710 }
5711
5712 // Called on the DisplayManager's DisplayPowerController thread.
5713 @Override
5714 public void screenTurnedOff() {
5715 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5716
Jeff Brown48d1b142015-06-10 16:36:03 -07005717 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005718 synchronized (mLock) {
5719 mScreenOnEarly = false;
5720 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005721 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005722 mWindowManagerDrawComplete = false;
5723 mScreenOnListener = null;
5724 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005725
5726 if (mKeyguardDelegate != null) {
5727 mKeyguardDelegate.onScreenTurnedOff();
5728 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005729 }
5730 }
5731
Jeff Brown3ee549c2014-09-22 20:14:39 -07005732 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005733 @Override
5734 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005735 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005736
Jeff Brown48d1b142015-06-10 16:36:03 -07005737 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005738 synchronized (mLock) {
5739 mScreenOnEarly = true;
5740 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005741 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005742 mWindowManagerDrawComplete = false;
5743 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07005744
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005745 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07005746 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5747 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005748 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
5749 } else {
5750 if (DEBUG_WAKEUP) Slog.d(TAG,
5751 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
5752 finishKeyguardDrawn();
5753 }
5754 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005755 }
5756
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005757 // Called on the DisplayManager's DisplayPowerController thread.
5758 @Override
5759 public void screenTurnedOn() {
5760 synchronized (mLock) {
5761 if (mKeyguardDelegate != null) {
5762 mKeyguardDelegate.onScreenTurnedOn();
5763 }
5764 }
5765 }
5766
Jeff Brown36c4db82014-09-19 12:05:31 -07005767 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005768 synchronized (mLock) {
5769 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005770 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005771 }
5772
Jeff Brown36c4db82014-09-19 12:05:31 -07005773 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005774 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005775
5776 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005777 }
5778
Craig Mautner8a0da012014-05-31 15:13:37 -07005779 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005780 synchronized (mLock) {
5781 // We have just finished drawing screen content. Since the orientation listener
5782 // gets only installed when all windows are drawn, we try to install it again.
5783 updateOrientationListenerLp();
5784 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005785 final ScreenOnListener listener;
5786 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005787 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005788 if (DEBUG_WAKEUP) Slog.d(TAG,
5789 "finishScreenTurningOn: mAwake=" + mAwake
5790 + ", mScreenOnEarly=" + mScreenOnEarly
5791 + ", mScreenOnFully=" + mScreenOnFully
5792 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5793 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5794
5795 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5796 || (mAwake && !mKeyguardDrawComplete)) {
5797 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005798 }
5799
Jeff Brown3ee549c2014-09-22 20:14:39 -07005800 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5801 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005802 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005803 mScreenOnFully = true;
5804
5805 // Remember the first time we draw the keyguard so we know when we're done with
5806 // the main part of booting and can enable the screen and hide boot messages.
5807 if (!mKeyguardDrawnOnce && mAwake) {
5808 mKeyguardDrawnOnce = true;
5809 enableScreen = true;
5810 if (mBootMessageNeedsHiding) {
5811 mBootMessageNeedsHiding = false;
5812 hideBootMessages();
5813 }
5814 } else {
5815 enableScreen = false;
5816 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005817 }
5818
Jeff Brown3ee549c2014-09-22 20:14:39 -07005819 if (listener != null) {
5820 listener.onScreenOn();
5821 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005822
Jeff Brown3ee549c2014-09-22 20:14:39 -07005823 if (enableScreen) {
5824 try {
5825 mWindowManager.enableScreenIfNeeded();
5826 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005827 }
Craig Mautnera631d492014-08-05 15:16:01 -07005828 }
5829 }
5830
5831 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005832 synchronized (mLock) {
5833 if (!mKeyguardDrawnOnce) {
5834 mBootMessageNeedsHiding = true;
5835 return; // keyguard hasn't drawn the first time yet, not done booting
5836 }
Craig Mautnera631d492014-08-05 15:16:01 -07005837 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005838
5839 if (mBootMsgDialog != null) {
5840 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5841 mBootMsgDialog.dismiss();
5842 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005843 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005844 }
5845
5846 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005847 public boolean isScreenOn() {
5848 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005849 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005850
Dianne Hackborn08743722009-12-21 12:16:51 -08005851 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005852 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005853 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005854 if (mKeyguardDelegate != null) {
5855 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005856 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005857 }
5858
5859 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005860 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005861 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005862 if (mKeyguardDelegate != null) {
5863 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005864 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005865 }
5866
Jim Millerab954542014-10-10 18:21:49 -07005867 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005868 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07005869 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005870 }
5871
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005872 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005873 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005874 public boolean isKeyguardLocked() {
5875 return keyguardOn();
5876 }
5877
5878 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005879 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005880 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005881 if (mKeyguardDelegate == null) return false;
5882 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05005883 }
5884
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005885 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005886 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07005887 public boolean isKeyguardShowingOrOccluded() {
5888 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
5889 }
5890
5891 /** {@inheritDoc} */
5892 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005893 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08005894 if (mKeyguardDelegate == null) return false;
5895 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005896 }
5897
Jose Lima9546b202014-07-02 17:21:51 -07005898 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005899 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07005900 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005901 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05005902 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07005903 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05005904 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02005905 // ask the keyguard to prompt the user to authenticate if necessary
5906 mKeyguardDelegate.dismiss();
5907 }
5908 });
5909 }
5910 }
5911
5912 public void notifyActivityDrawnForKeyguardLw() {
5913 if (mKeyguardDelegate != null) {
5914 mHandler.post(new Runnable() {
5915 @Override
5916 public void run() {
5917 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05005918 }
5919 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07005920 }
5921 }
5922
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005923 @Override
5924 public boolean isKeyguardDrawnLw() {
5925 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005926 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02005927 }
5928 }
5929
Jorim Jaggi0d674622014-05-21 01:34:15 +02005930 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005931 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02005932 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07005933 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02005934 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02005935 }
5936 }
5937
Jorim Jaggi737af722015-12-31 10:42:27 +01005938 @Override
5939 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
5940 Rect outInsets) {
5941 outInsets.setEmpty();
5942 if (mStatusBar != null) {
5943 outInsets.top = mStatusBarHeight;
5944 }
5945 if (mNavigationBar != null) {
5946 if (isNavigationBarOnBottom(displayWidth, displayHeight)) {
5947 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
5948 } else {
5949 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
5950 }
5951 }
5952 }
5953
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005954 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005955 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005956 }
5957
5958 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01005959 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005960 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07005961
Jeff Brown01a98dd2011-09-20 15:08:29 -07005962 @Override
5963 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05005964 if (false) {
5965 Slog.v(TAG, "rotationForOrientationLw(orient="
5966 + orientation + ", last=" + lastRotation
5967 + "); user=" + mUserRotation + " "
5968 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
5969 ? "USER_ROTATION_LOCKED" : "")
5970 );
5971 }
5972
Craig Mautner46ac6fa2013-08-01 10:06:34 -07005973 if (mForceDefaultOrientation) {
5974 return Surface.ROTATION_0;
5975 }
5976
The Android Open Source Project0727d222009-03-11 12:11:58 -07005977 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07005978 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
5979 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07005980 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07005981 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005982
Jeff Browndec6cf42011-11-15 14:08:20 -08005983 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07005984 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005985 // Ignore sensor when lid switch is open and rotation is forced.
5986 preferredRotation = mLidOpenRotation;
5987 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07005988 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005989 // Ignore sensor when in car dock unless explicitly enabled.
5990 // This case can override the behavior of NOSENSOR, and can also
5991 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07005992 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07005993 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08005994 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
5995 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
5996 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07005997 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07005998 // Ignore sensor when in desk dock unless explicitly enabled.
5999 // This case can override the behavior of NOSENSOR, and can also
6000 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006001 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006002 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006003 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
6004 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08006005 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006006 preferredRotation = mDemoHdmiRotation;
6007 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
6008 && mUndockedHdmiRotation >= 0) {
6009 // Ignore sensor when plugged into HDMI and an undocked orientation has
6010 // been specified in the configuration (only for legacy devices without
6011 // full multi-display support).
6012 // Note that the dock orientation overrides the HDMI orientation.
6013 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08006014 } else if (mDemoRotationLock) {
6015 // Ignore sensor when demo rotation lock is enabled.
6016 // Note that the dock orientation and HDMI rotation lock override this.
6017 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006018 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
6019 // Application just wants to remain locked in the last rotation.
6020 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08006021 } else if (!mSupportAutoRotation) {
6022 // If we don't support auto-rotation then bail out here and ignore
6023 // the sensor and any rotation lock settings.
6024 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07006025 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07006026 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006027 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6028 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
6029 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
6030 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07006031 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
6032 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6033 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
6034 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
6035 // Otherwise, use sensor only if requested by the application or enabled
6036 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07006037 if (mAllowAllRotations < 0) {
6038 // Can't read this during init() because the context doesn't
6039 // have display metrics at that time so we cannot determine
6040 // tablet vs. phone then.
6041 mAllowAllRotations = mContext.getResources().getBoolean(
6042 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
6043 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006044 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07006045 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006046 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6047 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006048 preferredRotation = sensorRotation;
6049 } else {
6050 preferredRotation = lastRotation;
6051 }
Jeff Brown207673cd2012-06-05 17:47:11 -07006052 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
6053 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
6054 // Apply rotation lock. Does not apply to NOSENSOR.
6055 // The idea is that the user rotation expresses a weak preference for the direction
6056 // of gravity and as NOSENSOR is never affected by gravity, then neither should
6057 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07006058 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08006059 } else {
6060 // No overriding preference.
6061 // We will do exactly what the application asked us to do.
6062 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07006063 }
6064
Dianne Hackborne5439f22010-10-02 16:53:50 -07006065 switch (orientation) {
6066 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006067 // Return portrait unless overridden.
6068 if (isAnyPortrait(preferredRotation)) {
6069 return preferredRotation;
6070 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07006071 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006072
Jeff Brown01a98dd2011-09-20 15:08:29 -07006073 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006074 // Return landscape unless overridden.
6075 if (isLandscapeOrSeascape(preferredRotation)) {
6076 return preferredRotation;
6077 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006078 return mLandscapeRotation;
6079
6080 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006081 // Return reverse portrait unless overridden.
6082 if (isAnyPortrait(preferredRotation)) {
6083 return preferredRotation;
6084 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006085 return mUpsideDownRotation;
6086
6087 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006088 // Return seascape unless overridden.
6089 if (isLandscapeOrSeascape(preferredRotation)) {
6090 return preferredRotation;
6091 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006092 return mSeascapeRotation;
6093
6094 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006095 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006096 // Return either landscape rotation.
6097 if (isLandscapeOrSeascape(preferredRotation)) {
6098 return preferredRotation;
6099 }
6100 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006101 return lastRotation;
6102 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006103 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006104
Jeff Brown01a98dd2011-09-20 15:08:29 -07006105 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006106 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006107 // Return either portrait rotation.
6108 if (isAnyPortrait(preferredRotation)) {
6109 return preferredRotation;
6110 }
6111 if (isAnyPortrait(lastRotation)) {
6112 return lastRotation;
6113 }
6114 return mPortraitRotation;
6115
6116 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006117 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6118 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006119 if (preferredRotation >= 0) {
6120 return preferredRotation;
6121 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006122 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006123 }
6124 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006125 }
6126
Jeff Brown01a98dd2011-09-20 15:08:29 -07006127 @Override
6128 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6129 switch (orientation) {
6130 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6131 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6132 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6133 return isAnyPortrait(rotation);
6134
6135 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6136 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6137 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6138 return isLandscapeOrSeascape(rotation);
6139
6140 default:
6141 return true;
6142 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006143 }
6144
Jeff Brownc0347aa2011-09-23 17:26:09 -07006145 @Override
6146 public void setRotationLw(int rotation) {
6147 mOrientationListener.setCurrentRotation(rotation);
6148 }
6149
Jeff Brown01a98dd2011-09-20 15:08:29 -07006150 private boolean isLandscapeOrSeascape(int rotation) {
6151 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006152 }
6153
Jeff Brown01a98dd2011-09-20 15:08:29 -07006154 private boolean isAnyPortrait(int rotation) {
6155 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006156 }
6157
Jose Lima9546b202014-07-02 17:21:51 -07006158 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006159 public int getUserRotationMode() {
6160 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006161 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6162 WindowManagerPolicy.USER_ROTATION_FREE :
6163 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006164 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006165
6166 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006167 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006168 public void setUserRotationMode(int mode, int rot) {
6169 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006170
6171 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006172 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006173 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006174 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006175 rot,
6176 UserHandle.USER_CURRENT);
6177 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006178 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006179 0,
6180 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006181 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006182 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006183 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006184 1,
6185 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006186 }
6187 }
6188
Jose Lima9546b202014-07-02 17:21:51 -07006189 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006190 public void setSafeMode(boolean safeMode) {
6191 mSafeMode = safeMode;
6192 performHapticFeedbackLw(null, safeMode
6193 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6194 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006195 }
Craig Mautnereda67292013-04-28 13:50:14 -07006196
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006197 static long[] getLongIntArray(Resources r, int resid) {
6198 int[] ar = r.getIntArray(resid);
6199 if (ar == null) {
6200 return null;
6201 }
6202 long[] out = new long[ar.length];
6203 for (int i=0; i<ar.length; i++) {
6204 out[i] = ar[i];
6205 }
6206 return out;
6207 }
Craig Mautnereda67292013-04-28 13:50:14 -07006208
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006209 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006210 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006211 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006212 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006213 mKeyguardDelegate.onSystemReady();
6214
Michael Wright3818c922014-09-02 13:59:07 -07006215 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006216 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006217 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006218 synchronized (mLock) {
6219 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006220 mSystemReady = true;
6221 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006222 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006223 public void run() {
6224 updateSettings();
6225 }
6226 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006227
6228 bindKeyguardNow = mDeferBindKeyguard;
6229 if (bindKeyguardNow) {
6230 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6231 mDeferBindKeyguard = false;
6232 }
6233 }
6234
6235 if (bindKeyguardNow) {
6236 mKeyguardDelegate.bindService(mContext);
6237 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006238 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006239 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006240 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006241
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006242 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006243 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006244 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006245 boolean bindKeyguardNow = false;
6246 synchronized (mLock) {
6247 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6248 // in systemReady if not.
6249 if (mKeyguardDelegate != null) {
6250 bindKeyguardNow = true;
6251 } else {
6252 // Because mKeyguardDelegate is null, we know that the synchronized block in
6253 // systemReady didn't run yet and setting this will actually have an effect.
6254 mDeferBindKeyguard = true;
6255 }
6256 }
6257 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006258 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006259 mKeyguardDelegate.onBootCompleted();
6260 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006261 synchronized (mLock) {
6262 mSystemBooted = true;
6263 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006264 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006265 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006266 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006267 }
6268
Dianne Hackborn661cd522011-08-22 00:26:20 -07006269 ProgressDialog mBootMsgDialog = null;
6270
6271 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006272 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006273 public void showBootMessage(final CharSequence msg, final boolean always) {
6274 mHandler.post(new Runnable() {
6275 @Override public void run() {
6276 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006277 int theme;
6278 if (mContext.getPackageManager().hasSystemFeature(
6279 PackageManager.FEATURE_WATCH)) {
6280 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
6281 } else if (mContext.getPackageManager().hasSystemFeature(
6282 PackageManager.FEATURE_TELEVISION)) {
6283 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6284 } else {
6285 theme = 0;
6286 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006287
6288 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006289 // This dialog will consume all events coming in to
6290 // it, to avoid it trying to do things too early in boot.
6291 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6292 return true;
6293 }
6294 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6295 return true;
6296 }
6297 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6298 return true;
6299 }
6300 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6301 return true;
6302 }
6303 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6304 return true;
6305 }
6306 @Override public boolean dispatchPopulateAccessibilityEvent(
6307 AccessibilityEvent event) {
6308 return true;
6309 }
6310 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006311 if (mContext.getPackageManager().isUpgrade()) {
6312 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6313 } else {
6314 mBootMsgDialog.setTitle(R.string.android_start_title);
6315 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006316 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6317 mBootMsgDialog.setIndeterminate(true);
6318 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006319 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006320 mBootMsgDialog.getWindow().addFlags(
6321 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6322 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6323 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006324 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6325 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6326 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006327 mBootMsgDialog.setCancelable(false);
6328 mBootMsgDialog.show();
6329 }
6330 mBootMsgDialog.setMessage(msg);
6331 }
6332 });
6333 }
6334
6335 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006336 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006337 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006338 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006339 }
6340
Mike Lockwood28569302010-01-28 11:54:40 -05006341 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006342 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006343 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006344 // ***************************************
6345 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6346 // ***************************************
6347 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6348 // WITH ITS LOCKS HELD.
6349 //
6350 // This code must be VERY careful about the locks
6351 // it acquires.
6352 // In fact, the current code acquires way too many,
6353 // and probably has lurking deadlocks.
6354
Mike Lockwood28569302010-01-28 11:54:40 -05006355 synchronized (mScreenLockTimeout) {
6356 if (mLockScreenTimerActive) {
6357 // reset the timer
6358 mHandler.removeCallbacks(mScreenLockTimeout);
6359 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6360 }
6361 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006362 }
6363
Adam Cohenf7522022012-10-03 20:03:18 -07006364 class ScreenLockTimeout implements Runnable {
6365 Bundle options;
6366
6367 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006368 public void run() {
6369 synchronized (this) {
6370 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006371 if (mKeyguardDelegate != null) {
6372 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006373 }
Mike Lockwood28569302010-01-28 11:54:40 -05006374 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006375 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006376 }
6377 }
Mike Lockwood28569302010-01-28 11:54:40 -05006378
Adam Cohenf7522022012-10-03 20:03:18 -07006379 public void setLockOptions(Bundle options) {
6380 this.options = options;
6381 }
6382 }
6383
6384 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6385
Jose Lima9546b202014-07-02 17:21:51 -07006386 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006387 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006388 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6389 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006390 if (options != null) {
6391 // In case multiple calls are made to lockNow, we don't wipe out the options
6392 // until the runnable actually executes.
6393 mScreenLockTimeout.setLockOptions(options);
6394 }
Jim Miller93c518e2012-01-17 15:55:31 -08006395 mHandler.post(mScreenLockTimeout);
6396 }
6397
Mike Lockwood28569302010-01-28 11:54:40 -05006398 private void updateLockScreenTimeout() {
6399 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006400 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006401 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006402 if (mLockScreenTimerActive != enable) {
6403 if (enable) {
6404 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
6405 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6406 } else {
6407 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6408 mHandler.removeCallbacks(mScreenLockTimeout);
6409 }
6410 mLockScreenTimerActive = enable;
6411 }
6412 }
6413 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006414
Jeff Brown061ea992015-04-17 19:55:47 -07006415 private void updateDreamingSleepToken(boolean acquire) {
6416 if (acquire) {
6417 if (mDreamingSleepToken == null) {
6418 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6419 }
6420 } else {
6421 if (mDreamingSleepToken != null) {
6422 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006423 mDreamingSleepToken = null;
6424 }
6425 }
6426 }
6427
6428 private void updateScreenOffSleepToken(boolean acquire) {
6429 if (acquire) {
6430 if (mScreenOffSleepToken == null) {
6431 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6432 }
6433 } else {
6434 if (mScreenOffSleepToken != null) {
6435 mScreenOffSleepToken.release();
6436 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006437 }
6438 }
6439 }
6440
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006441 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006442 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006443 public void enableScreenAfterBoot() {
6444 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006445 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006446 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006447 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006448
Jeff Brownc458ce92012-04-30 14:58:40 -07006449 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006450 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006451 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006452 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006453 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01006454 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
6455 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07006456 }
Jeff Browna20dda42014-05-27 20:57:24 -07006457
6458 synchronized (mLock) {
6459 updateWakeGestureListenerLp();
6460 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006461 }
6462
Jeff Brown4f5fa282014-06-12 19:19:15 -07006463 void updateUiMode() {
6464 if (mUiModeManager == null) {
6465 mUiModeManager = IUiModeManager.Stub.asInterface(
6466 ServiceManager.getService(Context.UI_MODE_SERVICE));
6467 }
6468 try {
6469 mUiMode = mUiModeManager.getCurrentModeType();
6470 } catch (RemoteException e) {
6471 }
6472 }
6473
Jeff Brown01a98dd2011-09-20 15:08:29 -07006474 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006475 try {
6476 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006477 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6478 } catch (RemoteException e) {
6479 // Ignore
6480 }
6481 }
6482
6483 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6484 try {
6485 //set orientation on WindowManager
6486 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006487 } catch (RemoteException e) {
6488 // Ignore
6489 }
6490 }
6491
Daniel Sandler6396c722013-04-16 20:19:09 -04006492 /**
6493 * Return an Intent to launch the currently active dock app as home. Returns
6494 * null if the standard home should be launched, which is the case if any of the following is
6495 * true:
6496 * <ul>
6497 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07006498 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04006499 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6500 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6501 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6502 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006503 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006504 */
6505 Intent createHomeDockIntent() {
6506 Intent intent = null;
6507
6508 // What home does is based on the mode, not the dock state. That
6509 // is, when in car mode you should be taken to car home regardless
6510 // of whether we are actually in a car dock.
6511 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07006512 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04006513 intent = mCarDockIntent;
6514 }
6515 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6516 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6517 intent = mDeskDockIntent;
6518 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006519 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6520 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6521 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6522 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6523 // Always launch dock home from home when watch is docked, if it exists.
6524 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006525 }
6526
6527 if (intent == null) {
6528 return null;
6529 }
6530
6531 ActivityInfo ai = null;
6532 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6533 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006534 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006535 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006536 if (info != null) {
6537 ai = info.activityInfo;
6538 }
6539 if (ai != null
6540 && ai.metaData != null
6541 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6542 intent = new Intent(intent);
6543 intent.setClassName(ai.packageName, ai.name);
6544 return intent;
6545 }
6546
6547 return null;
6548 }
6549
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006550 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6551 if (awakenFromDreams) {
6552 awakenDreams();
6553 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006554
6555 Intent dock = createHomeDockIntent();
6556 if (dock != null) {
6557 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006558 if (fromHomeKey) {
6559 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6560 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006561 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006562 return;
6563 } catch (ActivityNotFoundException e) {
6564 }
6565 }
6566
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006567 Intent intent;
6568
6569 if (fromHomeKey) {
6570 intent = new Intent(mHomeIntent);
6571 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6572 } else {
6573 intent = mHomeIntent;
6574 }
6575
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006576 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006577 }
Craig Mautnereda67292013-04-28 13:50:14 -07006578
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006579 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006580 * goes to the home screen
6581 * @return whether it did anything
6582 */
6583 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006584 if (!isUserSetupComplete()) {
6585 Slog.i(TAG, "Not going home because user setup is in progress.");
6586 return false;
6587 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006588 if (false) {
6589 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006590 try {
6591 ActivityManagerNative.getDefault().stopAppSwitches();
6592 } catch (RemoteException e) {
6593 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006594 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006595 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006596 } else {
6597 // This code brings home to the front or, if it is already
6598 // at the front, puts the device to sleep.
6599 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006600 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6601 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6602 Log.d(TAG, "UTS-TEST-MODE");
6603 } else {
6604 ActivityManagerNative.getDefault().stopAppSwitches();
6605 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006606 Intent dock = createHomeDockIntent();
6607 if (dock != null) {
6608 int result = ActivityManagerNative.getDefault()
6609 .startActivityAsUser(null, null, dock,
6610 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6611 null, null, 0,
6612 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006613 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006614 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6615 return false;
6616 }
6617 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006618 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006619 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006620 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006621 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006622 null, null, 0,
6623 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006624 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006625 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006626 return false;
6627 }
6628 } catch (RemoteException ex) {
6629 // bummer, the activity manager, which is in this process, is dead
6630 }
6631 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006632 return true;
6633 }
Craig Mautnereda67292013-04-28 13:50:14 -07006634
6635 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006636 public void setCurrentOrientationLw(int newOrientation) {
6637 synchronized (mLock) {
6638 if (newOrientation != mCurrentAppOrientation) {
6639 mCurrentAppOrientation = newOrientation;
6640 updateOrientationListenerLp();
6641 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006642 }
6643 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006644
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006645 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6646 if (!isGlobalAccessibilityGestureEnabled()) {
6647 return;
6648 }
6649 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6650 Context.AUDIO_SERVICE);
6651 if (audioManager.isSilentMode()) {
6652 return;
6653 }
6654 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6655 Settings.System.DEFAULT_NOTIFICATION_URI);
6656 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6657 ringTone.play();
6658 }
Craig Mautnereda67292013-04-28 13:50:14 -07006659
Bryce Lee584a4452014-10-21 15:55:55 -07006660 private boolean isTheaterModeEnabled() {
6661 return Settings.Global.getInt(mContext.getContentResolver(),
6662 Settings.Global.THEATER_MODE_ON, 0) == 1;
6663 }
6664
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006665 private boolean isGlobalAccessibilityGestureEnabled() {
6666 return Settings.Global.getInt(mContext.getContentResolver(),
6667 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6668 }
6669
Craig Mautnereda67292013-04-28 13:50:14 -07006670 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006671 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006672 if (!mVibrator.hasVibrator()) {
6673 return false;
6674 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006675 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6676 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006677 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006678 return false;
6679 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006680 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006681 switch (effectId) {
6682 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006683 pattern = mLongPressVibePattern;
6684 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006685 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006686 pattern = mVirtualKeyVibePattern;
6687 break;
6688 case HapticFeedbackConstants.KEYBOARD_TAP:
6689 pattern = mKeyboardTapVibePattern;
6690 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006691 case HapticFeedbackConstants.CLOCK_TICK:
6692 pattern = mClockTickVibePattern;
6693 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006694 case HapticFeedbackConstants.CALENDAR_DATE:
6695 pattern = mCalendarDateVibePattern;
6696 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006697 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006698 pattern = mSafeModeDisabledVibePattern;
6699 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006700 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006701 pattern = mSafeModeEnabledVibePattern;
6702 break;
Mady Mellore8608912015-06-05 09:02:55 -07006703 case HapticFeedbackConstants.CONTEXT_CLICK:
6704 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006705 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006706 default:
6707 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006708 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006709 int owningUid;
6710 String owningPackage;
6711 if (win != null) {
6712 owningUid = win.getOwningUid();
6713 owningPackage = win.getOwningPackage();
6714 } else {
6715 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006716 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006717 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006718 if (pattern.length == 1) {
6719 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006720 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006721 } else {
6722 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006723 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006724 }
6725 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006726 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006727
6728 @Override
6729 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006730 }
6731
Jeff Brownc38c9be2012-10-04 13:16:19 -07006732 @Override
6733 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006734 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006735 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006736 }
6737 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006738
Dianne Hackborndf89e652011-10-06 22:35:11 -07006739 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006740 // If there is no window focused, there will be nobody to handle the events
6741 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006742 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6743 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006744 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006745 return 0;
6746 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006747 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006748 // We are updating at a point where the keyguard has gotten
6749 // focus, but we were last in a state where the top window is
6750 // hiding it. This is probably because the keyguard as been
6751 // shown while the top window was displayed, so we want to ignore
6752 // it here because this is just a very transient change and it
6753 // will quickly lose focus once it correctly gets hidden.
6754 return 0;
6755 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006756
John Spurlock1db8b682014-02-18 11:18:59 -05006757 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006758 & ~mResettingSystemUiFlags
6759 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006760 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006761 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006762 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07006763
6764 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6765 tmpVisibility |= StatusBarManager.DISABLE_RECENT;
6766 }
6767
Adrian Rooscd3884d2015-02-18 17:25:23 +01006768 tmpVisibility = updateLightStatusBarLw(tmpVisibility);
John Spurlock79da8332013-09-20 12:04:47 -04006769 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006770 final int diff = visibility ^ mLastSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006771 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Dianne Hackborne0f085d2011-11-30 18:41:15 -08006772 if (diff == 0 && mLastFocusNeedsMenu == needsMenu
John Spurlock79da8332013-09-20 12:04:47 -04006773 && mFocusedApp == win.getAppToken()) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006774 return 0;
6775 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006776 mLastSystemUiFlags = visibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006777 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006778 mFocusedApp = win.getAppToken();
Dianne Hackborndf89e652011-10-06 22:35:11 -07006779 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006780 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006781 public void run() {
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006782 try {
6783 IStatusBarService statusbar = getStatusBarService();
6784 if (statusbar != null) {
Adrian Roos53f28ec2014-10-29 17:26:12 +01006785 statusbar.setSystemUiVisibility(visibility, 0xffffffff, win.toString());
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006786 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006787 }
Dianne Hackborn42e620c2012-06-24 13:20:51 -07006788 } catch (RemoteException e) {
6789 // re-acquire status bar service next time it is needed.
6790 mStatusBarService = null;
Joe Onorato664644d2011-01-23 17:53:23 -08006791 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006792 }
6793 });
6794 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006795 }
6796
Adrian Rooscd3884d2015-02-18 17:25:23 +01006797 private int updateLightStatusBarLw(int vis) {
6798 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6799 ? mStatusBar
6800 : mTopFullscreenOpaqueOrDimmingWindowState;
6801
6802 if (statusColorWin != null) {
6803 if (statusColorWin == mTopFullscreenOpaqueWindowState) {
6804 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6805 // its light flag.
6806 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6807 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6808 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6809 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6810 // Otherwise if it's dimming, clear the light flag.
6811 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6812 }
6813 }
6814 return vis;
6815 }
6816
John Spurlock79da8332013-09-20 12:04:47 -04006817 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006818 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
6819 final boolean freeformStackVisible =
6820 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
6821 final boolean forceShowSystemBars = dockedStackVisible || freeformStackVisible;
Jorim Jaggi4fa78922015-11-30 17:13:56 -08006822 final boolean forceOpaqueSystemBars = forceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006823
John Spurlockbd957402013-10-03 11:38:39 -04006824 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006825 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6826 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006827 : mTopFullscreenOpaqueWindowState;
6828 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6829 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6830
John Spurlock27735a42013-08-14 17:57:38 -04006831 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006832 int type = win.getAttrs().type;
6833 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006834 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006835 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6836 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006837 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006838 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
6839 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006840 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01006841 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
6842 }
John Spurlockbd957402013-10-03 11:38:39 -04006843 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006844 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04006845
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006846 if ((!areTranslucentBarsAllowed() && transWin != mStatusBar)
6847 || forceOpaqueSystemBars) {
Adrian Roosea562512014-05-05 13:33:03 +02006848 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
6849 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006850 }
6851
Jorim Jaggi4fa78922015-11-30 17:13:56 -08006852 if (mForceWindowDrawsStatusBarBackground) {
6853 vis |= View.STATUS_BAR_TRANSPARENT;
6854 vis &= ~View.STATUS_BAR_TRANSLUCENT;
6855 }
6856
John Spurlock27735a42013-08-14 17:57:38 -04006857 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04006858 boolean immersiveSticky =
6859 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006860 final boolean hideStatusBarWM =
6861 mTopFullscreenOpaqueWindowState != null
6862 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04006863 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006864 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04006865 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006866 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04006867 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006868
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006869 final boolean transientStatusBarAllowed = mStatusBar != null
6870 && (statusBarHasFocus || (!forceShowSystemBars
6871 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04006872
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006873 final boolean transientNavBarAllowed = mNavigationBar != null
6874 && !forceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04006875
Adrian Roosddc8b272015-05-21 16:28:27 -07006876 final long now = SystemClock.uptimeMillis();
6877 final boolean pendingPanic = mPendingPanicGestureUptime != 0
6878 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
6879 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
6880 // The user performed the panic gesture recently, we're about to hide the bars,
6881 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
6882 mPendingPanicGestureUptime = 0;
6883 mStatusBarController.showTransient();
6884 mNavigationBarController.showTransient();
6885 }
6886
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006887 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006888 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006889 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04006890 && !transientNavBarAllowed;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006891 if (denyTransientStatus || denyTransientNav || forceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04006892 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04006893 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08006894 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006895 }
John Spurlock27735a42013-08-14 17:57:38 -04006896
Selim Cinekf98702e2015-05-20 22:48:40 -07006897 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
6898 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
6899 final boolean navAllowedHidden = immersive || immersiveSticky;
6900
Selim Cinekd6623612015-05-22 18:56:22 -07006901 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
6902 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07006903 // We can't hide the navbar from this window otherwise the input consumer would not get
6904 // the input events.
6905 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
6906 }
6907
John Spurlock27735a42013-08-14 17:57:38 -04006908 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
6909
6910 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04006911 boolean oldImmersiveMode = isImmersiveMode(oldVis);
6912 boolean newImmersiveMode = isImmersiveMode(vis);
6913 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04006914 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07006915 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
6916 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04006917 }
John Spurlock27735a42013-08-14 17:57:38 -04006918
John Spurlockf1a36642013-10-12 17:50:42 -04006919 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
6920
John Spurlocke1f366f2013-08-05 12:22:40 -04006921 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04006922 }
6923
John Spurlockf1a36642013-10-12 17:50:42 -04006924 private void clearClearableFlagsLw() {
6925 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
6926 if (newVal != mResettingSystemUiFlags) {
6927 mResettingSystemUiFlags = newVal;
6928 mWindowManagerFuncs.reevaluateStatusBarVisibility();
6929 }
6930 }
6931
6932 private boolean isImmersiveMode(int vis) {
6933 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04006934 return mNavigationBar != null
6935 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04006936 && (vis & flags) != 0
6937 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04006938 }
6939
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006940 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006941 * @return whether the navigation or status bar can be made translucent
6942 *
6943 * This should return true unless touch exploration is not enabled or
6944 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006945 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04006946 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04006947 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07006948 }
6949
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006950 // Use this instead of checking config_showNavigationBar so that it can be consistently
6951 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07006952 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04006953 public boolean hasNavigationBar() {
6954 return mHasNavigationBar;
6955 }
6956
satok1bc0a492012-04-25 22:47:12 +09006957 @Override
6958 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
6959 mLastInputMethodWindow = ime;
6960 mLastInputMethodTargetWindow = target;
6961 }
6962
Craig Mautnerf1b67412012-09-19 13:18:29 -07006963 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09006964 public int getInputMethodWindowVisibleHeightLw() {
6965 return mDockBottom - mCurBottom;
6966 }
6967
6968 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07006969 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07006970 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08006971 if (mKeyguardDelegate != null) {
6972 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006973 }
John Spurlock13451a22012-09-28 14:40:41 -04006974 if (mStatusBarService != null) {
6975 try {
6976 mStatusBarService.setCurrentUser(newUserId);
6977 } catch (RemoteException e) {
6978 // oh well
6979 }
6980 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07006981 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07006982 }
6983
6984 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08006985 public boolean canMagnifyWindow(int windowType) {
6986 switch (windowType) {
6987 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
6988 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
6989 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
6990 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
6991 return false;
6992 }
6993 }
6994 return true;
6995 }
6996
6997 @Override
6998 public boolean isTopLevelWindow(int windowType) {
6999 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
7000 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
7001 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
7002 }
7003 return true;
7004 }
7005
Jim Miller4eeb4f62012-11-08 00:04:29 -08007006 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07007007 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007008 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007009 pw.print(" mSystemReady="); pw.print(mSystemReady);
7010 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07007011 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007012 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07007013 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007014 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07007015 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
7016 || mForceClearedSystemUiFlags != 0) {
7017 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
7018 pw.print(Integer.toHexString(mLastSystemUiFlags));
7019 pw.print(" mResettingSystemUiFlags=0x");
7020 pw.print(Integer.toHexString(mResettingSystemUiFlags));
7021 pw.print(" mForceClearedSystemUiFlags=0x");
7022 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07007023 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007024 if (mLastFocusNeedsMenu) {
7025 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
7026 pw.println(mLastFocusNeedsMenu);
7027 }
Jeff Browna20dda42014-05-27 20:57:24 -07007028 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
7029 pw.println(mWakeGestureEnabledSetting);
7030
Jeff Brownbcdfc622014-03-06 19:13:04 -08007031 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04007032 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
7033 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07007034 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007035 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
7036 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
7037 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
7038 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007039 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007040 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007041 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
7042 pw.print(mCarDockEnablesAccelerometer);
7043 pw.print(" mDeskDockEnablesAccelerometer=");
7044 pw.println(mDeskDockEnablesAccelerometer);
7045 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
7046 pw.print(mLidKeyboardAccessibility);
7047 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007048 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007049 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007050 pw.print(prefix);
7051 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
7052 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07007053 pw.print(prefix);
7054 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
7055 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007056 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07007057 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
7058 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
7059 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
7060 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
7061 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
7062 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
7063 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08007064 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
7065 pw.print(","); pw.print(mOverscanScreenTop);
7066 pw.print(") "); pw.print(mOverscanScreenWidth);
7067 pw.print("x"); pw.println(mOverscanScreenHeight);
7068 if (mOverscanLeft != 0 || mOverscanTop != 0
7069 || mOverscanRight != 0 || mOverscanBottom != 0) {
7070 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
7071 pw.print(" top="); pw.print(mOverscanTop);
7072 pw.print(" right="); pw.print(mOverscanRight);
7073 pw.print(" bottom="); pw.println(mOverscanBottom);
7074 }
Dianne Hackborn313440842013-02-19 19:22:59 -08007075 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
7076 pw.print(mRestrictedOverscanScreenLeft);
7077 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
7078 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
7079 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007080 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
7081 pw.print(","); pw.print(mUnrestrictedScreenTop);
7082 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
7083 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
7084 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
7085 pw.print(","); pw.print(mRestrictedScreenTop);
7086 pw.print(") "); pw.print(mRestrictedScreenWidth);
7087 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07007088 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
7089 pw.print(","); pw.print(mStableFullscreenTop);
7090 pw.print(")-("); pw.print(mStableFullscreenRight);
7091 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07007092 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
7093 pw.print(","); pw.print(mStableTop);
7094 pw.print(")-("); pw.print(mStableRight);
7095 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007096 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7097 pw.print(","); pw.print(mSystemTop);
7098 pw.print(")-("); pw.print(mSystemRight);
7099 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007100 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
7101 pw.print(","); pw.print(mCurTop);
7102 pw.print(")-("); pw.print(mCurRight);
7103 pw.print(","); pw.print(mCurBottom); pw.println(")");
7104 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
7105 pw.print(","); pw.print(mContentTop);
7106 pw.print(")-("); pw.print(mContentRight);
7107 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07007108 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
7109 pw.print(","); pw.print(mVoiceContentTop);
7110 pw.print(")-("); pw.print(mVoiceContentRight);
7111 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007112 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
7113 pw.print(","); pw.print(mDockTop);
7114 pw.print(")-("); pw.print(mDockRight);
7115 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007116 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
7117 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007118 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
7119 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07007120 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
7121 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007122 if (mLastInputMethodWindow != null) {
7123 pw.print(prefix); pw.print("mLastInputMethodWindow=");
7124 pw.println(mLastInputMethodWindow);
7125 }
7126 if (mLastInputMethodTargetWindow != null) {
7127 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
7128 pw.println(mLastInputMethodTargetWindow);
7129 }
7130 if (mStatusBar != null) {
7131 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08007132 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
7133 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007134 }
7135 if (mNavigationBar != null) {
7136 pw.print(prefix); pw.print("mNavigationBar=");
7137 pw.println(mNavigationBar);
7138 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007139 if (mFocusedWindow != null) {
7140 pw.print(prefix); pw.print("mFocusedWindow=");
7141 pw.println(mFocusedWindow);
7142 }
7143 if (mFocusedApp != null) {
7144 pw.print(prefix); pw.print("mFocusedApp=");
7145 pw.println(mFocusedApp);
7146 }
7147 if (mWinDismissingKeyguard != null) {
7148 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
7149 pw.println(mWinDismissingKeyguard);
7150 }
7151 if (mTopFullscreenOpaqueWindowState != null) {
7152 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7153 pw.println(mTopFullscreenOpaqueWindowState);
7154 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007155 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7156 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7157 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7158 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007159 if (mForcingShowNavBar) {
7160 pw.print(prefix); pw.print("mForcingShowNavBar=");
7161 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7162 pw.println(mForcingShowNavBarLayer);
7163 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007164 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007165 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007166 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7167 pw.print(" mForceStatusBarFromKeyguard=");
7168 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007169 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007170 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007171 pw.print(" mHomePressed="); pw.println(mHomePressed);
7172 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7173 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7174 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7175 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7176 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7177 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7178 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7179 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7180 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7181 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007182 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7183 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7184 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007185
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007186 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007187 mStatusBarController.dump(pw, prefix);
7188 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007189 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007190
Jeff Browna20dda42014-05-27 20:57:24 -07007191 if (mWakeGestureListener != null) {
7192 mWakeGestureListener.dump(pw, prefix);
7193 }
Jeff Brown600f0032014-05-22 17:06:00 -07007194 if (mOrientationListener != null) {
7195 mOrientationListener.dump(pw, prefix);
7196 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007197 if (mBurnInProtectionHelper != null) {
7198 mBurnInProtectionHelper.dump(prefix, pw);
7199 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007200 if (mKeyguardDelegate != null) {
7201 mKeyguardDelegate.dump(prefix, pw);
7202 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007203 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007204}