blob: c207aea0c70f2061bc97bf22a8662111492a8647 [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;
Jorim Jaggi86905582016-02-09 21:36:09 -080021import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
22import static android.app.ActivityManager.StackId.HOME_STACK_ID;
Jaewan Kim49117872016-01-19 17:24:08 +090023import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
24import static android.content.pm.PackageManager.FEATURE_TELEVISION;
25import static android.content.pm.PackageManager.FEATURE_WATCH;
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -080026import static android.content.res.Configuration.UI_MODE_TYPE_CAR;
27import static android.content.res.Configuration.UI_MODE_TYPE_MASK;
Jorim Jaggi5060bd82016-02-19 17:12:19 -080028import static android.view.WindowManager.DOCKED_TOP;
29import static android.view.WindowManager.DOCKED_LEFT;
30import static android.view.WindowManager.DOCKED_RIGHT;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070031import static android.view.WindowManager.LayoutParams.*;
Jaewan Kim49117872016-01-19 17:24:08 +090032import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070033import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
34import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
Jaewan Kim49117872016-01-19 17:24:08 +090035import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
36import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
37import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070038
Dianne Hackborna4972e92012-03-14 10:38:05 -070039import android.app.ActivityManager;
Jorim Jaggi86905582016-02-09 21:36:09 -080040import android.app.ActivityManager.StackId;
Jeff Brown061ea992015-04-17 19:55:47 -070041import android.app.ActivityManagerInternal;
42import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080043import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080044import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040045import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070046import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070047import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040048import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080049import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070050import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080051import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040052import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080053import android.content.ContentResolver;
54import android.content.Context;
55import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070056import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070057import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080058import android.content.pm.ActivityInfo;
59import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040060import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070061import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080062import android.content.res.Configuration;
63import android.content.res.Resources;
64import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080065import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080066import android.graphics.Rect;
Jinsuk Kime601b712015-07-07 08:01:02 +090067import android.hardware.hdmi.HdmiControlManager;
68import android.hardware.hdmi.HdmiPlaybackClient;
69import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
John Spurlock7b414672014-07-18 13:02:39 -040070import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080071import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050072import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080073import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070074import android.media.Ringtone;
75import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070076import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +010077import android.os.Binder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070078import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080079import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070080import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080081import android.os.Handler;
82import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070083import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080084import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070085import android.os.Message;
86import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080087import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -070088import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +010089import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080090import android.os.RemoteException;
91import android.os.ServiceManager;
92import android.os.SystemClock;
93import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080094import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070095import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080096import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070097import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080098import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070099import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -0400100import android.service.dreams.DreamService;
101import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -0700102import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700103import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700104import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800105import android.util.EventLog;
106import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -0700107import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -0800108import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700109import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800110import android.view.Gravity;
111import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800112import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800113import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -0700114import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -0700115import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -0800116import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800117import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800118import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -0800119import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800120import android.view.KeyEvent;
121import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800122import android.view.Surface;
123import android.view.View;
124import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800125import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800126import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700127import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800128import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800129import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800130import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800131import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200132import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800133import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800134import com.android.internal.R;
Jason Monk8f7f3182015-11-18 16:35:14 -0500135import com.android.internal.logging.MetricsLogger;
136import com.android.internal.policy.PhoneWindow;
Craig Mautnerae446592012-12-06 19:05:05 -0800137import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700138import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800139import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700140import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700141import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100142import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700143import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Jorim Jaggi86905582016-02-09 21:36:09 -0800144import com.android.server.statusbar.StatusBarManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800145
146import java.io.File;
147import java.io.FileReader;
148import java.io.IOException;
149import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700150import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800151import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800152
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800153/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700154 * WindowManagerPolicy implementation for the Android phone UI. This
155 * introduces a new method suffix, Lp, for an internal lock of the
156 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400157 * 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 -0700158 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800159 */
160public class PhoneWindowManager implements WindowManagerPolicy {
161 static final String TAG = "WindowManager";
162 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700163 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700164 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700165 static final boolean DEBUG_KEYGUARD = false;
166 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700167 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700168 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800169 static final boolean SHOW_STARTING_ANIMATIONS = true;
170 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400171
Daniel Sandler6396c722013-04-16 20:19:09 -0400172 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
keunyounga7710492015-09-23 11:33:58 -0700173 // No longer recommended for desk docks;
Daniel Sandler6396c722013-04-16 20:19:09 -0400174 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
175
Jeff Brown6d8fd272014-05-20 21:24:38 -0700176 static final int SHORT_PRESS_POWER_NOTHING = 0;
177 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
178 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
179 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800180 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700181
Joe Onoratod208e702010-10-08 16:22:43 -0400182 static final int LONG_PRESS_POWER_NOTHING = 0;
183 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
184 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700185 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700186
Jeff Brown13f00f02014-10-31 14:45:50 -0700187 static final int MULTI_PRESS_POWER_NOTHING = 0;
188 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
189 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
190
Michael Jurka3b1fc472011-06-13 10:54:40 -0700191 // These need to match the documentation/constant in
192 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800193 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800194 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700195 static final int LONG_PRESS_HOME_ASSIST = 2;
Jaewan Kim76b7d0d2016-02-12 19:01:02 +0900196 static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST;
Jeff Browncaca8812013-05-09 13:34:33 -0700197
198 static final int DOUBLE_TAP_HOME_NOTHING = 0;
199 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800200
Jaewan Kim49117872016-01-19 17:24:08 +0900201 static final int SHORT_PRESS_WINDOW_NOTHING = 0;
202 static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1;
203
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000204 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
205 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
206
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700207 static final int APPLICATION_MEDIA_SUBLAYER = -2;
208 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800209 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800210 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700211 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700212
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800213 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
214 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
215 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500216 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700217 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800218
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700219 /**
220 * These are the system UI flags that, when changing, can cause the layout
221 * of the screen to change.
222 */
223 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400224 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400225 | View.SYSTEM_UI_FLAG_FULLSCREEN
226 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200227 | View.NAVIGATION_BAR_TRANSLUCENT
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800228 | View.STATUS_BAR_TRANSPARENT
229 | View.NAVIGATION_BAR_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700230
John Spurlock7b414672014-07-18 13:02:39 -0400231 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
232 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
233 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
234 .build();
235
Adrian Roosddc8b272015-05-21 16:28:27 -0700236 // The panic gesture may become active only after the keyguard is dismissed and the immersive
237 // app shows again. If that doesn't happen for 30s we drop the gesture.
238 private static final long PANIC_GESTURE_EXPIRATION = 30000;
239
Jim Miller5ecd8112013-01-09 18:50:26 -0800240 /**
241 * Keyguard stuff
242 */
243 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100244 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700245 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800246
Jeff Brown6651a632011-11-28 12:59:11 -0800247 /* Table of Application Launch keys. Maps from key codes to intent categories.
248 *
249 * These are special keys that are used to launch particular kinds of applications,
250 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
251 * usage page. We don't support quite that many yet...
252 */
253 static SparseArray<String> sApplicationLaunchKeyCategories;
254 static {
255 sApplicationLaunchKeyCategories = new SparseArray<String>();
256 sApplicationLaunchKeyCategories.append(
257 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
258 sApplicationLaunchKeyCategories.append(
259 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
260 sApplicationLaunchKeyCategories.append(
261 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
262 sApplicationLaunchKeyCategories.append(
263 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
264 sApplicationLaunchKeyCategories.append(
265 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
266 sApplicationLaunchKeyCategories.append(
267 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
268 }
269
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700270 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700271 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700272
Dianne Hackborndf89e652011-10-06 22:35:11 -0700273 /**
274 * Lock protecting internal state. Must not call out into window
275 * manager with lock held. (This lock will be acquired in places
276 * where the window manager is calling in with its own lock held.)
277 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800278 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700279
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800280 Context mContext;
281 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700282 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700283 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700284 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700285 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700286 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100287 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400288 IStatusBarService mStatusBarService;
Jorim Jaggi86905582016-02-09 21:36:09 -0800289 StatusBarManagerInternal mStatusBarManagerInternal;
Jeff Browncaca8812013-05-09 13:34:33 -0700290 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700291 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800292 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700293 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800294 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000295 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100296 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800297
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700298 // Vibrator pattern for haptic feedback of a long press.
299 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700300
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700301 // Vibrator pattern for haptic feedback of virtual key press.
302 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700303
Amith Yamasanic33cb712010-02-10 15:21:49 -0800304 // Vibrator pattern for a short vibration.
305 long[] mKeyboardTapVibePattern;
306
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700307 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
308 long[] mClockTickVibePattern;
309
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700310 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
311 long[] mCalendarDateVibePattern;
312
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700313 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
314 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700315
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700316 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
317 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700318
Mady Mellore8608912015-06-05 09:02:55 -0700319 // Vibrator pattern for haptic feedback of a context click.
320 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700321
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800322 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
323 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400324
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800325 boolean mSafeMode;
326 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700327 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400328 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400329 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700330 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400331 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
332 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -0800333 int[] mNavigationBarHeightForRotationDefault = new int[4];
334 int[] mNavigationBarWidthForRotationDefault = new int[4];
335 int[] mNavigationBarHeightForRotationInCarMode = new int[4];
336 int[] mNavigationBarWidthForRotationInCarMode = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400337
keunyounga7710492015-09-23 11:33:58 -0700338 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
339 // This is for car dock and this is updated from resource.
340 private boolean mEnableCarDockHomeCapture = true;
341
Craig Mautnera631d492014-08-05 15:16:01 -0700342 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800343 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700344 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700345 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700346 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700347 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
348 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
349 }
350 };
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700351 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700352 @Override
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700353 public void onDrawn() {
354 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700355 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
356 }
357 };
358
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800359 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800360 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900361 WindowState mLastInputMethodWindow = null;
362 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800363
Jeff Brown13f00f02014-10-31 14:45:50 -0700364 // FIXME This state is shared between the input reader and handler thread.
365 // Technically it's broken and buggy but it has been like this for many years
366 // and we have not yet seen any problems. Someday we'll rewrite this logic
367 // so that only one thread is involved in handling input policy. Unfortunately
368 // it's on a critical path for power management so we can't just post the work to the
369 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
370 // to hold wakelocks during dispatch and eliminating the critical path.
371 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800372 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700373 volatile int mPowerKeyPressCounter;
374 volatile boolean mEndCallKeyHandled;
375
Winson Chungd42a6cf2014-06-03 16:24:04 -0700376 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700377 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700378 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800379
Jeff Brown2e7760e2012-04-11 15:14:55 -0700380 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700381 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700382 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800383
Dianne Hackbornc777e072010-02-12 13:07:59 -0800384 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700385 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700386 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800387 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900388 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700389 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400390 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700391 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700392 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400393 int mCarDockRotation;
394 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700395 int mUndockedHdmiRotation;
396 int mDemoHdmiRotation;
397 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800398 int mDemoRotation;
399 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400400
Jeff Browna20dda42014-05-27 20:57:24 -0700401 boolean mWakeGestureEnabledSetting;
402 MyWakeGestureListener mWakeGestureListener;
403
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700404 // Default display does not rotate, apps that require non-default orientation will have to
405 // have the orientation emulated.
406 private boolean mForceDefaultOrientation = false;
407
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400408 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
409 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700410 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400411
Jeff Brownbcdfc622014-03-06 19:13:04 -0800412 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700413 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400414 boolean mCarDockEnablesAccelerometer;
415 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700416 int mLidKeyboardAccessibility;
417 int mLidNavigationAccessibility;
Edward Savage-Jones7def60d2015-11-13 13:27:03 +0100418 boolean mLidControlsScreenLock;
Jeff Brownc458ce92012-04-30 14:58:40 -0700419 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700420 int mShortPressOnPowerBehavior;
421 int mLongPressOnPowerBehavior;
422 int mDoublePressOnPowerBehavior;
423 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000424 int mShortPressOnSleepBehavior;
Jaewan Kim49117872016-01-19 17:24:08 +0900425 int mShortPressWindowBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700426 boolean mAwake;
427 boolean mScreenOnEarly;
428 boolean mScreenOnFully;
429 ScreenOnListener mScreenOnListener;
430 boolean mKeyguardDrawComplete;
431 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800432 boolean mOrientationSensorEnabled = false;
433 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800434 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400435 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800436 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700437
Jeff Brown70825162012-03-28 17:27:48 -0700438 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800439
440 // The last window we were told about in focusChanged.
441 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800442 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800443
Jeff Brown70825162012-03-28 17:27:48 -0700444 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800445
Dianne Hackbornc652de82013-02-15 16:32:56 -0800446 // The current size of the screen; really; extends into the overscan area of
447 // the screen and doesn't account for any system elements like the status bar.
448 int mOverscanScreenLeft, mOverscanScreenTop;
449 int mOverscanScreenWidth, mOverscanScreenHeight;
450 // The current visible size of the screen; really; (ir)regardless of whether the status
451 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800452 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
453 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800454 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
455 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
456 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700457 // The current size of the screen; these may be different than (0,0)-(dw,dh)
458 // if the status bar can't be hidden; in that case it effectively carves out
459 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800460 int mRestrictedScreenLeft, mRestrictedScreenTop;
461 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700462 // During layout, the current screen borders accounting for any currently
463 // visible system UI elements.
464 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700465 // For applications requesting stable content insets, these are them.
466 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700467 // For applications requesting stable content insets but have also set the
468 // fullscreen window flag, these are the stable dimensions without the status bar.
469 int mStableFullscreenLeft, mStableFullscreenTop;
470 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800471 // During layout, the current screen borders with all outer decoration
472 // (status bar, input method dock) accounted for.
473 int mCurLeft, mCurTop, mCurRight, mCurBottom;
474 // During layout, the frame in which content should be displayed
475 // to the user, accounting for all screen decoration except for any
476 // space they deem as available for other content. This is usually
477 // the same as mCur*, but may be larger if the screen decor has supplied
478 // content insets.
479 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700480 // During layout, the frame in which voice content should be displayed
481 // to the user, accounting for all screen decoration except for any
482 // space they deem as available for other content.
483 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800484 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800485 // windows are placed.
486 int mDockLeft, mDockTop, mDockRight, mDockBottom;
487 // During layout, the layer at which the doc window is placed.
488 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700489 // During layout, this is the layer of the status bar.
490 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700491 int mLastSystemUiFlags;
492 // Bits that we are in the process of clearing, so we want to prevent
493 // them from being set by applications until everything has been updated
494 // to have them clear.
495 int mResettingSystemUiFlags = 0;
496 // Bits that we are currently always keeping cleared.
497 int mForceClearedSystemUiFlags = 0;
Jorim Jaggi86905582016-02-09 21:36:09 -0800498 int mLastFullscreenStackSysUiFlags;
499 int mLastDockedStackSysUiFlags;
500 final Rect mNonDockedStackBounds = new Rect();
501 final Rect mDockedStackBounds = new Rect();
502 final Rect mLastNonDockedStackBounds = new Rect();
503 final Rect mLastDockedStackBounds = new Rect();
504
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800505 // What we last reported to system UI about whether the compatibility
506 // menu needs to be displayed.
507 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700508 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
509 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700510
Selim Cinekf83e8242015-05-19 18:08:14 -0700511 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700512
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800513 static final Rect mTmpParentFrame = new Rect();
514 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800515 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800516 static final Rect mTmpContentFrame = new Rect();
517 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400518 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700519 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700520 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700521 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700522
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800523 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100524 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Jorim Jaggi86905582016-02-09 21:36:09 -0800525 WindowState mTopDockedOpaqueWindowState;
526 WindowState mTopDockedOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700527 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200528 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400529 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800530 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700531 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700532 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700533 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800534 boolean mForcingShowNavBar;
535 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700536
537 // States of keyguard dismiss.
538 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
539 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
540 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
541 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
542
543 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
544 * be done once per window. */
545 private WindowState mWinDismissingKeyguard;
546
tingna_sunge785ffa2015-05-12 13:23:15 +0800547 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
548 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
549 * lock SIM card. This variable is used to record the previous keyguard secure state for
550 * monitoring secure state change on window dismissing keyguard. */
551 private boolean mSecureDismissingKeyguard;
552
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700553 /** The window that is currently showing "over" the keyguard. If there is an app window
554 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
555 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
556 * the wallpaper. */
557 private WindowState mWinShowWhenLocked;
558
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700559 boolean mShowingLockscreen;
560 boolean mShowingDream;
561 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700562 boolean mDreamingSleepTokenNeeded;
563 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700564 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700565 boolean mKeyguardSecure;
566 boolean mKeyguardSecureIncludingHidden;
567 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800568 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700569 boolean mHomeConsumed;
570 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800571 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700572 Intent mCarDockIntent;
573 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700574 boolean mSearchKeyShortcutPending;
575 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700576 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700577 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800578
Mike Lockwood28569302010-01-28 11:54:40 -0500579 // support for activating the lock screen while the screen is on
580 boolean mAllowLockscreenWhenOn;
581 int mLockScreenTimeout;
582 boolean mLockScreenTimerActive;
583
David Brownbaf8d092010-03-08 21:52:59 -0800584 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800585 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800586
587 // Behavior of POWER button while in-call and screen on.
588 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
589 int mIncallPowerBehavior;
590
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700591 Display mDisplay;
592
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700593 private int mDisplayRotation;
594
Dianne Hackborn9d132642011-04-21 17:26:39 -0700595 int mLandscapeRotation = 0; // default landscape rotation
596 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
597 int mPortraitRotation = 0; // default portrait rotation
598 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700599
Dianne Hackbornc652de82013-02-15 16:32:56 -0800600 int mOverscanLeft = 0;
601 int mOverscanTop = 0;
602 int mOverscanRight = 0;
603 int mOverscanBottom = 0;
604
Joe Onorato46b0d682010-11-22 17:37:27 -0800605 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700606 private int mLongPressOnHomeBehavior;
607
608 // What we do when the user double-taps on home
609 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800610
Bryce Lee584a4452014-10-21 15:55:55 -0700611 // Allowed theater mode wake actions
612 private boolean mAllowTheaterModeWakeFromKey;
613 private boolean mAllowTheaterModeWakeFromPowerKey;
614 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800615 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700616 private boolean mAllowTheaterModeWakeFromCameraLens;
617 private boolean mAllowTheaterModeWakeFromLidSwitch;
618 private boolean mAllowTheaterModeWakeFromWakeGesture;
619
Bryce Leed3b28402015-03-09 15:49:13 +0000620 // Whether to support long press from power button in non-interactive mode
621 private boolean mSupportLongPressPowerWhenNonInteractive;
622
Bryce Lee55e846d2014-11-04 12:43:44 -0800623 // Whether to go to sleep entering theater mode from power button
624 private boolean mGoToSleepOnButtonPressTheaterMode;
625
Winson Chung9112ec32011-06-27 13:15:32 -0700626 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700627 // Time to volume and power must be pressed within this interval of each other.
628 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700629 // Increase the chord delay when taking a screenshot from the keyguard
630 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800631 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700632 private boolean mScreenshotChordVolumeDownKeyTriggered;
633 private long mScreenshotChordVolumeDownKeyTime;
634 private boolean mScreenshotChordVolumeDownKeyConsumed;
635 private boolean mScreenshotChordVolumeUpKeyTriggered;
636 private boolean mScreenshotChordPowerKeyTriggered;
637 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700638
Michael Wrightb854e242013-02-05 17:54:02 -0800639 /* The number of steps between min and max brightness */
640 private static final int BRIGHTNESS_STEPS = 10;
641
Christopher Tate5e08af02012-09-21 17:17:22 -0700642 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800643 ShortcutManager mShortcutManager;
644 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700645 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700646 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800647
Craig Mautnerd625ab22013-09-06 13:40:31 -0700648 private int mCurrentUserId;
649
Justin Kohd378ad72013-04-01 12:18:26 -0700650 // Maps global key codes to the components that will handle them.
651 private GlobalKeyManager mGlobalKeyManager;
652
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700653 // Fallback actions by key code.
654 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
655 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800656
Jorim Jaggi76a16232014-08-08 17:00:47 +0200657 private final LogDecelerateInterpolator mLogDecelerateInterpolator
658 = new LogDecelerateInterpolator(100, 0);
659
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800660 private boolean mForceWindowDrawsStatusBarBackground;
661
Jeff Brown70825162012-03-28 17:27:48 -0700662 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
663 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700664 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
665 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700666 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
667 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
668 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700669 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700670 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700671 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700672 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700673 private static final int MSG_POWER_DELAYED_PRESS = 13;
674 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700675 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700676 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
Jaewan Kimc552b042016-01-18 16:08:45 +0900677 private static final int MSG_REQUEST_TV_PICTURE_IN_PICTURE = 17;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700678
679 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
680 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700681
682 private class PolicyHandler extends Handler {
683 @Override
684 public void handleMessage(Message msg) {
685 switch (msg.what) {
686 case MSG_ENABLE_POINTER_LOCATION:
687 enablePointerLocation();
688 break;
689 case MSG_DISABLE_POINTER_LOCATION:
690 disablePointerLocation();
691 break;
Jeff Brown40013652012-05-16 21:22:36 -0700692 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
693 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
694 break;
695 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
696 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
697 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700698 case MSG_DISPATCH_SHOW_RECENTS:
699 showRecentApps(false);
700 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700701 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
702 showGlobalActionsInternal();
703 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700704 case MSG_KEYGUARD_DRAWN_COMPLETE:
705 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700706 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700707 break;
708 case MSG_KEYGUARD_DRAWN_TIMEOUT:
709 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700710 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700711 break;
712 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
713 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700714 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700715 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700716 case MSG_HIDE_BOOT_MESSAGE:
717 handleHideBootMessage();
718 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700719 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
720 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
721 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700722 case MSG_POWER_DELAYED_PRESS:
723 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
724 finishPowerKeyPress();
725 break;
726 case MSG_POWER_LONG_PRESS:
727 powerLongPress();
728 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700729 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
730 updateDreamingSleepToken(msg.arg1 != 0);
731 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700732 case MSG_REQUEST_TRANSIENT_BARS:
733 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
734 mStatusBar : mNavigationBar;
735 if (targetBar != null) {
736 requestTransientBars(targetBar);
737 }
738 break;
Jaewan Kimc552b042016-01-18 16:08:45 +0900739 case MSG_REQUEST_TV_PICTURE_IN_PICTURE:
740 requestTvPictureInPictureInternal();
741 break;
Jeff Brown70825162012-03-28 17:27:48 -0700742 }
743 }
744 }
745
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800746 private UEventObserver mHDMIObserver = new UEventObserver() {
747 @Override
748 public void onUEvent(UEventObserver.UEvent event) {
749 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
750 }
751 };
752
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800753 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800754 SettingsObserver(Handler handler) {
755 super(handler);
756 }
David Brownbaf8d092010-03-08 21:52:59 -0800757
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800758 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700759 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800760 ContentResolver resolver = mContext.getContentResolver();
761 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700762 Settings.System.END_BUTTON_BEHAVIOR), false, this,
763 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800764 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700765 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
766 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700767 resolver.registerContentObserver(Settings.Secure.getUriFor(
768 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
769 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800770 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700771 Settings.System.ACCELEROMETER_ROTATION), false, this,
772 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500773 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700774 Settings.System.USER_ROTATION), false, this,
775 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400776 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700777 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
778 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800779 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700780 Settings.System.POINTER_LOCATION), false, this,
781 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800782 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700783 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
784 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500785 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400786 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700787 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500788 resolver.registerContentObserver(Settings.Global.getUriFor(
789 Settings.Global.POLICY_CONTROL), false, this,
790 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800791 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800792 }
793
794 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800795 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700796 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800797 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800798 }
Craig Mautner967212c2013-04-13 21:10:58 -0700799
Jeff Browna20dda42014-05-27 20:57:24 -0700800 class MyWakeGestureListener extends WakeGestureListener {
801 MyWakeGestureListener(Context context, Handler handler) {
802 super(context, handler);
803 }
804
805 @Override
806 public void onWakeUp() {
807 synchronized (mLock) {
808 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700809 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700810 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
811 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700812 }
813 }
814 }
815 }
816
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800817 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700818 private final Runnable mUpdateRotationRunnable = new Runnable() {
819 @Override
820 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700821 // send interaction hint to improve redraw performance
822 mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700823 updateRotation(false);
824 }
825 };
826
Craig Mautnereee29c42013-01-17 14:44:34 -0800827 MyOrientationListener(Context context, Handler handler) {
828 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800829 }
Craig Mautner967212c2013-04-13 21:10:58 -0700830
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800831 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700832 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700833 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700834 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700835 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800836 }
837 MyOrientationListener mOrientationListener;
838
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100839 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400840
John Spurlock27735a42013-08-14 17:57:38 -0400841 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400842 View.NAVIGATION_BAR_TRANSIENT,
843 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400844 View.NAVIGATION_BAR_TRANSLUCENT,
845 StatusBarManager.WINDOW_NAVIGATION_BAR,
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800846 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
847 View.NAVIGATION_BAR_TRANSPARENT);
John Spurlock5b9145b2013-08-20 15:13:47 -0400848
John Spurlockf1a36642013-10-12 17:50:42 -0400849 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400850
Craig Mautner037aa8d2013-06-07 10:35:44 -0700851 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400852
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700853 IStatusBarService getStatusBarService() {
854 synchronized (mServiceAquireLock) {
855 if (mStatusBarService == null) {
856 mStatusBarService = IStatusBarService.Stub.asInterface(
857 ServiceManager.getService("statusbar"));
858 }
859 return mStatusBarService;
860 }
861 }
862
Jorim Jaggi86905582016-02-09 21:36:09 -0800863 StatusBarManagerInternal getStatusBarManagerInternal() {
864 synchronized (mServiceAquireLock) {
865 if (mStatusBarManagerInternal == null) {
866 mStatusBarManagerInternal =
867 LocalServices.getService(StatusBarManagerInternal.class);
868 }
869 return mStatusBarManagerInternal;
870 }
871 }
872
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700873 /*
874 * We always let the sensor be switched on by default except when
875 * the user has explicitly disabled sensor based rotation or when the
876 * screen is switched off.
877 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700878 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800879 if (mSupportAutoRotation) {
880 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
881 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
882 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
883 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
884 // If the application has explicitly requested to follow the
885 // orientation, then we need to turn the sensor on.
886 return true;
887 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800888 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700889 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800890 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
891 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
892 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400893 // enable accelerometer if we are docked in a dock that enables accelerometer
894 // orientation management,
895 return true;
896 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700897 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800898 // If the setting for using the sensor by default is enabled, then
899 // we will always leave it on. Note that the user could go to
900 // a window that forces an orientation that does not use the
901 // sensor and in theory we could turn it off... however, when next
902 // turning it on we won't have a good value for the current
903 // orientation for a little bit, which can cause orientation
904 // changes to lag, so we'd like to keep it always on. (It will
905 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700906 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800907 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800908 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800909 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700910
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800911 /*
912 * Various use cases for invoking this function
913 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700914 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800915 * if not already enabled
916 * screen turned on and current app does not have sensor orientation, disable listeners if
917 * already enabled
918 * screen turning on and current app has sensor based orientation, enable listeners if needed
919 * screen turning on and current app has nosensor based orientation, do nothing
920 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700921 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800922 if (!mOrientationListener.canDetectOrientation()) {
923 // If sensor is turned off or nonexistent for some reason
924 return;
925 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000926 // Could have been invoked due to screen turning on or off or
927 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700928 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
929 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000930 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
931 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
932 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800933 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000934 // Note: We postpone the rotating of the screen until the keyguard as well as the
935 // window manager have reported a draw complete.
936 if (mScreenOnEarly && mAwake &&
937 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700938 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800939 disable = false;
940 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700941 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800942 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700943 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800944 mOrientationSensorEnabled = true;
945 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700946 }
947 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800948 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700949 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800950 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700951 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800952 mOrientationSensorEnabled = false;
953 }
954 }
955
Jeff Brown13f00f02014-10-31 14:45:50 -0700956 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
957 // Hold a wake lock until the power key is released.
958 if (!mPowerKeyWakeLock.isHeld()) {
959 mPowerKeyWakeLock.acquire();
960 }
961
962 // Cancel multi-press detection timeout.
963 if (mPowerKeyPressCounter != 0) {
964 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
965 }
966
967 // Detect user pressing the power button in panic when an application has
968 // taken over the whole screen.
969 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800970 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700971 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700972 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700973 }
974
975 // Latch power key state to detect screenshot chord.
976 if (interactive && !mScreenshotChordPowerKeyTriggered
977 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
978 mScreenshotChordPowerKeyTriggered = true;
979 mScreenshotChordPowerKeyTime = event.getDownTime();
980 interceptScreenshotChord();
981 }
982
983 // Stop ringing or end call if configured to do so when power is pressed.
984 TelecomManager telecomManager = getTelecommService();
985 boolean hungUp = false;
986 if (telecomManager != null) {
987 if (telecomManager.isRinging()) {
988 // Pressing Power while there's a ringing incoming
989 // call should silence the ringer.
990 telecomManager.silenceRinger();
991 } else if ((mIncallPowerBehavior
992 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
993 && telecomManager.isInCall() && interactive) {
994 // Otherwise, if "Power button ends call" is enabled,
995 // the Power button will hang up any current active call.
996 hungUp = telecomManager.endCall();
997 }
998 }
999
Adrian Roos5941c982015-09-03 15:59:49 -07001000 GestureLauncherService gestureService = LocalServices.getService(
1001 GestureLauncherService.class);
1002 boolean gesturedServiceIntercepted = false;
1003 if (gestureService != null) {
1004 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive);
1005 }
1006
Jeff Brown13f00f02014-10-31 14:45:50 -07001007 // If the power key has still not yet been handled, then detect short
1008 // press, long press, or multi press and decide what to do.
1009 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -07001010 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -07001011 if (!mPowerKeyHandled) {
1012 if (interactive) {
1013 // When interactive, we're already awake.
1014 // Wait for a long press or for the button to be released to decide what to do.
1015 if (hasLongPressOnPowerBehavior()) {
1016 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1017 msg.setAsynchronous(true);
1018 mHandler.sendMessageDelayed(msg,
1019 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1020 }
1021 } else {
Bryce Leed9268e32014-11-17 17:40:59 -08001022 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -08001023
Bryce Leed3b28402015-03-09 15:49:13 +00001024 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
1025 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1026 msg.setAsynchronous(true);
1027 mHandler.sendMessageDelayed(msg,
1028 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -08001029 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +00001030 } else {
1031 final int maxCount = getMaxMultiPressPowerCount();
1032
1033 if (maxCount <= 1) {
1034 mPowerKeyHandled = true;
1035 } else {
1036 mBeganFromNonInteractive = true;
1037 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001038 }
1039 }
Jeff Brown4d396052010-10-29 21:50:21 -07001040 }
1041 }
1042
Jeff Brown13f00f02014-10-31 14:45:50 -07001043 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
1044 final boolean handled = canceled || mPowerKeyHandled;
1045 mScreenshotChordPowerKeyTriggered = false;
1046 cancelPendingScreenshotChordAction();
1047 cancelPendingPowerKeyAction();
1048
1049 if (!handled) {
1050 // Figure out how to handle the key now that it has been released.
1051 mPowerKeyPressCounter += 1;
1052
1053 final int maxCount = getMaxMultiPressPowerCount();
1054 final long eventTime = event.getDownTime();
1055 if (mPowerKeyPressCounter < maxCount) {
1056 // This could be a multi-press. Wait a little bit longer to confirm.
1057 // Continue holding the wake lock.
1058 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1059 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1060 msg.setAsynchronous(true);
1061 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1062 return;
1063 }
1064
1065 // No other actions. Handle it immediately.
1066 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001067 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001068
1069 // Done. Reset our state.
1070 finishPowerKeyPress();
1071 }
1072
1073 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001074 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001075 mPowerKeyPressCounter = 0;
1076 if (mPowerKeyWakeLock.isHeld()) {
1077 mPowerKeyWakeLock.release();
1078 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001079 }
1080
1081 private void cancelPendingPowerKeyAction() {
1082 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001083 mPowerKeyHandled = true;
1084 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001085 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001086 }
1087
1088 private void powerPress(long eventTime, boolean interactive, int count) {
1089 if (mScreenOnEarly && !mScreenOnFully) {
1090 Slog.i(TAG, "Suppressed redundant power key press while "
1091 + "already in the process of turning the screen on.");
1092 return;
Jeff Brownff204712011-10-25 21:27:54 -07001093 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001094
1095 if (count == 2) {
1096 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1097 } else if (count == 3) {
1098 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001099 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001100 switch (mShortPressOnPowerBehavior) {
1101 case SHORT_PRESS_POWER_NOTHING:
1102 break;
1103 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1104 mPowerManager.goToSleep(eventTime,
1105 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1106 break;
1107 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1108 mPowerManager.goToSleep(eventTime,
1109 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1110 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1111 break;
1112 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1113 mPowerManager.goToSleep(eventTime,
1114 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1115 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1116 launchHomeFromHotKey();
1117 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001118 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001119 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001120 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001121 }
1122 }
1123 }
1124
1125 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1126 switch (behavior) {
1127 case MULTI_PRESS_POWER_NOTHING:
1128 break;
1129 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001130 if (!isUserSetupComplete()) {
1131 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1132 break;
1133 }
1134
Jeff Brown13f00f02014-10-31 14:45:50 -07001135 if (isTheaterModeEnabled()) {
1136 Slog.i(TAG, "Toggling theater mode off.");
1137 Settings.Global.putInt(mContext.getContentResolver(),
1138 Settings.Global.THEATER_MODE_ON, 0);
1139 if (!interactive) {
1140 wakeUpFromPowerKey(eventTime);
1141 }
1142 } else {
1143 Slog.i(TAG, "Toggling theater mode on.");
1144 Settings.Global.putInt(mContext.getContentResolver(),
1145 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001146
1147 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001148 mPowerManager.goToSleep(eventTime,
1149 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1150 }
1151 }
1152 break;
1153 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001154 Slog.i(TAG, "Starting brightness boost.");
1155 if (!interactive) {
1156 wakeUpFromPowerKey(eventTime);
1157 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001158 mPowerManager.boostScreenBrightness(eventTime);
1159 break;
1160 }
1161 }
1162
1163 private int getMaxMultiPressPowerCount() {
1164 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1165 return 3;
1166 }
1167 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1168 return 2;
1169 }
1170 return 1;
1171 }
1172
1173 private void powerLongPress() {
1174 final int behavior = getResolvedLongPressOnPowerBehavior();
1175 switch (behavior) {
1176 case LONG_PRESS_POWER_NOTHING:
1177 break;
1178 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1179 mPowerKeyHandled = true;
1180 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1181 performAuditoryFeedbackForAccessibilityIfNeed();
1182 }
1183 showGlobalActionsInternal();
1184 break;
1185 case LONG_PRESS_POWER_SHUT_OFF:
1186 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1187 mPowerKeyHandled = true;
1188 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1189 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1190 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1191 break;
1192 }
1193 }
1194
Nick Vaccarob593a812015-05-15 11:23:05 -07001195 private void sleepPress(long eventTime) {
1196 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1197 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1198 }
1199 }
1200
1201 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001202 switch (mShortPressOnSleepBehavior) {
1203 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001204 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001205 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1206 mPowerManager.goToSleep(eventTime,
1207 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001208 break;
1209 }
1210 }
1211
Jeff Brown13f00f02014-10-31 14:45:50 -07001212 private int getResolvedLongPressOnPowerBehavior() {
1213 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1214 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1215 }
1216 return mLongPressOnPowerBehavior;
1217 }
1218
1219 private boolean hasLongPressOnPowerBehavior() {
1220 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001221 }
1222
1223 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001224 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001225 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1226 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001227 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001228 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1229 && now <= mScreenshotChordPowerKeyTime
1230 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1231 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001232 cancelPendingPowerKeyAction();
1233
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001234 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001235 }
1236 }
1237 }
1238
Winson Chung1cea2f32012-10-08 20:42:01 -07001239 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001240 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001241 // Double the time it takes to take a screenshot from the keyguard
1242 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001243 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001244 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001245 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001246 }
1247
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001248 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001249 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001250 }
1251
Jeff Brown13f00f02014-10-31 14:45:50 -07001252 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001253 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001254 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001255 mEndCallKeyHandled = true;
1256 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1257 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001258 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001259 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001260 }
1261 };
1262
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001263 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001264 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001265 public void run() {
1266 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001267 }
1268 };
1269
Alan Viverettee34560b22014-07-10 14:50:06 -07001270 @Override
1271 public void showGlobalActions() {
1272 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1273 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1274 }
1275
1276 void showGlobalActionsInternal() {
1277 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001278 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001279 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001280 }
Jim Millerab954542014-10-10 18:21:49 -07001281 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001282 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1283 if (keyguardShowing) {
1284 // since it took two seconds of long press to bring this up,
1285 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001286 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001287 }
1288 }
1289
1290 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001291 return Settings.Global.getInt(
1292 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001293 }
1294
Maurice Lam99c6e072014-04-28 18:24:28 -07001295 boolean isUserSetupComplete() {
1296 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1297 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1298 }
1299
Jeff Brown13f00f02014-10-31 14:45:50 -07001300 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001301 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1302 getHdmiControl().turnOnTv();
1303
Jeff Brown13f00f02014-10-31 14:45:50 -07001304 // If there's a dream running then use home to escape the dream
1305 // but don't actually go home.
1306 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1307 mDreamManagerInternal.stopDream(false /*immediate*/);
1308 return;
1309 }
1310
1311 // Go home!
1312 launchHomeFromHotKey();
1313 }
1314
Jinsuk Kime601b712015-07-07 08:01:02 +09001315 /**
1316 * Creates an accessor to HDMI control service that performs the operation of
1317 * turning on TV (optional) and switching input to us. If HDMI control service
1318 * is not available or we're not a HDMI playback device, the operation is no-op.
1319 */
1320 private HdmiControl getHdmiControl() {
1321 if (null == mHdmiControl) {
1322 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1323 Context.HDMI_CONTROL_SERVICE);
1324 HdmiPlaybackClient client = null;
1325 if (manager != null) {
1326 client = manager.getPlaybackClient();
1327 }
1328 mHdmiControl = new HdmiControl(client);
1329 }
1330 return mHdmiControl;
1331 }
1332
1333 private static class HdmiControl {
1334 private final HdmiPlaybackClient mClient;
1335
1336 private HdmiControl(HdmiPlaybackClient client) {
1337 mClient = client;
1338 }
1339
1340 public void turnOnTv() {
1341 if (mClient == null) {
1342 return;
1343 }
1344 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1345 @Override
1346 public void onComplete(int result) {
1347 if (result != HdmiControlManager.RESULT_SUCCESS) {
1348 Log.w(TAG, "One touch play failed: " + result);
1349 }
1350 }
1351 });
1352 }
1353 }
1354
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001355 private void handleLongPressOnHome(int deviceId) {
Jaewan Kim52632e22016-01-14 18:01:52 +09001356 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
1357 return;
1358 }
1359 mHomeConsumed = true;
1360 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001361
Jaewan Kim52632e22016-01-14 18:01:52 +09001362 switch (mLongPressOnHomeBehavior) {
1363 case LONG_PRESS_HOME_RECENT_SYSTEM_UI:
Jeff Browncaca8812013-05-09 13:34:33 -07001364 toggleRecentApps();
Jaewan Kim52632e22016-01-14 18:01:52 +09001365 break;
1366 case LONG_PRESS_HOME_ASSIST:
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001367 launchAssistAction(null, deviceId);
Jaewan Kim52632e22016-01-14 18:01:52 +09001368 break;
Jaewan Kim52632e22016-01-14 18:01:52 +09001369 default:
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001370 Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior);
Jaewan Kim52632e22016-01-14 18:01:52 +09001371 break;
Jim Millere6ad1a82010-08-20 19:25:39 -07001372 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001373 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001374
Jeff Browncaca8812013-05-09 13:34:33 -07001375 private void handleDoubleTapOnHome() {
1376 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1377 mHomeConsumed = true;
1378 toggleRecentApps();
1379 }
1380 }
1381
Jaewan Kimc552b042016-01-18 16:08:45 +09001382 private void requestTvPictureInPicture(KeyEvent event) {
1383 if (DEBUG_INPUT) Log.d(TAG, "requestTvPictureInPicture event=" + event);
1384 mHandler.removeMessages(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1385 Message msg = mHandler.obtainMessage(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1386 msg.setAsynchronous(true);
1387 msg.sendToTarget();
1388 }
1389
1390 private void requestTvPictureInPictureInternal() {
1391 try {
1392 IStatusBarService statusbar = getStatusBarService();
1393 if (statusbar != null) {
1394 statusbar.requestTvPictureInPicture();
1395 }
1396 } catch (RemoteException|IllegalArgumentException e) {
1397 Slog.e(TAG, "Cannot handle picture-in-picture key", e);
1398 // re-acquire status bar service next time it is needed.
1399 mStatusBarService = null;
1400 }
Jaewan Kim52632e22016-01-14 18:01:52 +09001401 }
1402
Jeff Browncaca8812013-05-09 13:34:33 -07001403 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1404 @Override
1405 public void run() {
1406 if (mHomeDoubleTapPending) {
1407 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001408 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001409 }
1410 }
1411 };
1412
Mark Renoufc1256912015-03-11 14:38:23 -04001413 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001414 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001415 }
1416
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001417 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001418 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001419 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001420 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001421 mContext = context;
1422 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001423 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001424 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001425 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001426 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001427 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001428 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001429
1430 // Init display burn-in protection
1431 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1432 com.android.internal.R.bool.config_enableBurnInProtection);
1433 // Allow a system property to override this. Used by developer settings.
1434 boolean burnInProtectionDevMode =
1435 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1436 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1437 final int minHorizontal;
1438 final int maxHorizontal;
1439 final int minVertical;
1440 final int maxVertical;
1441 final int maxRadius;
1442 if (burnInProtectionDevMode) {
1443 minHorizontal = -8;
1444 maxHorizontal = 8;
1445 minVertical = -8;
1446 maxVertical = -4;
1447 maxRadius = (isRoundWindow()) ? 6 : -1;
1448 } else {
1449 Resources resources = context.getResources();
1450 minHorizontal = resources.getInteger(
1451 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1452 maxHorizontal = resources.getInteger(
1453 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1454 minVertical = resources.getInteger(
1455 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1456 maxVertical = resources.getInteger(
1457 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1458 maxRadius = resources.getInteger(
1459 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1460 }
1461 mBurnInProtectionHelper = new BurnInProtectionHelper(
1462 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001463 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001464
Jeff Brown70825162012-03-28 17:27:48 -07001465 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001466 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001467 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001468 try {
1469 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1470 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001471 mSettingsObserver = new SettingsObserver(mHandler);
1472 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001473 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001474 mUiMode = context.getResources().getInteger(
1475 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001476 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1477 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1478 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1479 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001480 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1481 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001482 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1483 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1484 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1485 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1486 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1487 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1488 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1489 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001490
Jeff Brown96307042012-07-27 15:51:34 -07001491 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1492 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001493 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001494 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1495 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001496 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001497 mSupportAutoRotation = mContext.getResources().getBoolean(
1498 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001499 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001500 com.android.internal.R.integer.config_lidOpenRotation);
1501 mCarDockRotation = readRotation(
1502 com.android.internal.R.integer.config_carDockRotation);
1503 mDeskDockRotation = readRotation(
1504 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001505 mUndockedHdmiRotation = readRotation(
1506 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001507 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1508 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1509 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1510 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001511 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1512 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1513 mLidNavigationAccessibility = mContext.getResources().getInteger(
1514 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001515 mLidControlsScreenLock = mContext.getResources().getBoolean(
1516 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001517 mLidControlsSleep = mContext.getResources().getBoolean(
1518 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001519 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1520 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001521
1522 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1523 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1524 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1525 || mContext.getResources().getBoolean(
1526 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1527 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1528 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001529 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1530 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001531 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1532 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1533 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1534 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1535 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1536 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1537
Bryce Lee55e846d2014-11-04 12:43:44 -08001538 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1539 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1540
Bryce Leed3b28402015-03-09 15:49:13 +00001541 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1542 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1543
Jeff Brown13f00f02014-10-31 14:45:50 -07001544 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1545 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1546 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1547 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1548 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1549 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1550 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1551 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001552 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1553 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001554
John Spurlock61560172015-02-06 19:46:04 -05001555 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001556
Jeff Brownf71343d2013-05-31 17:59:11 -07001557 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001558
Svetoslav8e3feb12014-02-24 13:46:47 -08001559 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1560 Context.ACCESSIBILITY_SERVICE);
1561
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001562 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001563 IntentFilter filter = new IntentFilter();
1564 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1565 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1566 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1567 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001568 filter.addAction(Intent.ACTION_DOCK_EVENT);
1569 Intent intent = context.registerReceiver(mDockReceiver, filter);
1570 if (intent != null) {
1571 // Retrieve current sticky dock event broadcast.
1572 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1573 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1574 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001575
Jeff Brown6aaf2952012-10-05 16:01:08 -07001576 // register for dream-related broadcasts
1577 filter = new IntentFilter();
1578 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1579 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1580 context.registerReceiver(mDreamReceiver, filter);
1581
Christopher Tate5e08af02012-09-21 17:17:22 -07001582 // register for multiuser-relevant broadcasts
1583 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1584 context.registerReceiver(mMultiuserReceiver, filter);
1585
John Spurlock57306e62013-04-22 09:48:49 -04001586 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001587 mSystemGestures = new SystemGesturesPointerEventListener(context,
1588 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001589 @Override
1590 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001591 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001592 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001593 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001594 }
1595 @Override
1596 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001597 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001598 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001599 }
1600 }
1601 @Override
1602 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001603 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001604 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001605 }
1606 }
1607 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001608 public void onFling(int duration) {
1609 if (mPowerManagerInternal != null) {
1610 mPowerManagerInternal.powerHint(
1611 PowerManagerInternal.POWER_HINT_INTERACTION, duration);
1612 }
1613 }
1614 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001615 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001616 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001617 }
Adrian Roos3595be42015-03-05 16:31:15 +01001618 @Override
1619 public void onDown() {
1620 mOrientationListener.onTouchStart();
1621 }
1622 @Override
1623 public void onUpOrCancel() {
1624 mOrientationListener.onTouchEnd();
1625 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001626 @Override
1627 public void onMouseHoverAtTop() {
1628 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1629 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1630 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1631 mHandler.sendMessageDelayed(msg, 500);
1632 }
1633 @Override
1634 public void onMouseHoverAtBottom() {
1635 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1636 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1637 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1638 mHandler.sendMessageDelayed(msg, 500);
1639 }
1640 @Override
1641 public void onMouseLeaveFromEdge() {
1642 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1643 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001644 });
John Spurlockf1a36642013-10-12 17:50:42 -04001645 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001646 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001647
Jeff Brownc2346132012-04-13 01:55:38 -07001648 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001649 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1650 com.android.internal.R.array.config_longPressVibePattern);
1651 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1652 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001653 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1654 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001655 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1656 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001657 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1658 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001659 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1660 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1661 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1662 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001663 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1664 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001665
Christopher Tatee90585f2012-03-05 18:56:25 -08001666 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1667 com.android.internal.R.bool.config_enableScreenshotChord);
Jorim Jaggi406585a2015-12-21 10:58:56 +01001668 mForceWindowDrawsStatusBarBackground = mContext.getResources().getBoolean(
1669 R.bool.config_forceWindowDrawsStatusBarBackground);
Christopher Tatee90585f2012-03-05 18:56:25 -08001670
Justin Kohd378ad72013-04-01 12:18:26 -07001671 mGlobalKeyManager = new GlobalKeyManager(mContext);
1672
Joe Onoratoea495d42011-04-06 11:41:11 -07001673 // Controls rotation and the like.
1674 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001675
1676 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001677 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001678 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1679 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001680 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001681
1682 mWindowManagerInternal.registerAppTransitionListener(
1683 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001684 }
1685
Jeff Brownf71343d2013-05-31 17:59:11 -07001686 /**
1687 * Read values from config.xml that may be overridden depending on
1688 * the configuration of the device.
1689 * eg. Disable long press on home goes to recents on sw600dp.
1690 */
1691 private void readConfigurationDependentBehaviors() {
Jaewan Kimc552b042016-01-18 16:08:45 +09001692 final Resources res = mContext.getResources();
1693
1694 mLongPressOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001695 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1696 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Jaewan Kim52632e22016-01-14 18:01:52 +09001697 mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) {
Jeff Brownf71343d2013-05-31 17:59:11 -07001698 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1699 }
1700
Jaewan Kimc552b042016-01-18 16:08:45 +09001701 mDoubleTapOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001702 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1703 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1704 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1705 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1706 }
Jaewan Kim49117872016-01-19 17:24:08 +09001707
1708 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING;
1709 if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) {
1710 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE;
1711 }
Jeff Brownf71343d2013-05-31 17:59:11 -07001712 }
1713
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001714 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001715 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001716 // This method might be called before the policy has been fully initialized
1717 // or for other displays we don't care about.
1718 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1719 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001720 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001721 mDisplay = display;
1722
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001723 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001724 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001725 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001726 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001727 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001728 mLandscapeRotation = Surface.ROTATION_0;
1729 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001730 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001731 mPortraitRotation = Surface.ROTATION_90;
1732 mUpsideDownRotation = Surface.ROTATION_270;
1733 } else {
1734 mPortraitRotation = Surface.ROTATION_270;
1735 mUpsideDownRotation = Surface.ROTATION_90;
1736 }
1737 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001738 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001739 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001740 mPortraitRotation = Surface.ROTATION_0;
1741 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001742 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001743 mLandscapeRotation = Surface.ROTATION_270;
1744 mSeascapeRotation = Surface.ROTATION_90;
1745 } else {
1746 mLandscapeRotation = Surface.ROTATION_90;
1747 mSeascapeRotation = Surface.ROTATION_270;
1748 }
1749 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001750
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001751 mStatusBarHeight =
1752 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001753
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001754 // Height of the navigation bar when presented horizontally at bottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001755 mNavigationBarHeightForRotationDefault[mPortraitRotation] =
1756 mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001757 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001758 mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
1759 mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001760 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001761
1762 // Width of the navigation bar when presented vertically along one side
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001763 mNavigationBarWidthForRotationDefault[mPortraitRotation] =
1764 mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
1765 mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
1766 mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001767 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001768
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001769 // Height of the navigation bar when presented horizontally at bottom
1770 mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
1771 mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
1772 res.getDimensionPixelSize(
1773 com.android.internal.R.dimen.navigation_bar_height_car_mode);
1774 mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
1775 mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
1776 com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
1777
1778 // Width of the navigation bar when presented vertically along one side
1779 mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
1780 mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
1781 mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
1782 mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
1783 res.getDimensionPixelSize(
1784 com.android.internal.R.dimen.navigation_bar_width_car_mode);
1785
Daniel Sandler4a066c52012-04-20 14:49:13 -04001786 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001787 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001788 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001789
Devin Kimd7b12b42014-05-05 14:34:58 -07001790 // Allow the navigation bar to move on non-square small devices (phones).
1791 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001792
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001793 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001794 // Allow a system property to override this. Used by the emulator.
1795 // See also hasNavigationBar().
1796 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1797 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001798 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001799 } else if ("0".equals(navBarOverride)) {
1800 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001801 }
1802
Jeff Brown27f1d672012-10-17 18:32:34 -07001803 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1804 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001805 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001806 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001807 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001808 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001809 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001810 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001811
Chong Zhangae6119ff2014-11-11 18:54:39 -08001812 // For demo purposes, allow the rotation of the remote display to be controlled.
1813 // By default, remote display locks rotation to landscape.
1814 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1815 mDemoRotation = mPortraitRotation;
1816 } else {
1817 mDemoRotation = mLandscapeRotation;
1818 }
1819 mDemoRotationLock = SystemProperties.getBoolean(
1820 "persist.demo.rotationlock", false);
1821
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001822 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1823 // http://developer.android.com/guide/practices/screens_support.html#range
1824 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1825 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1826 // For debug purposes the next line turns this feature off with:
1827 // $ adb shell setprop config.override_forced_orient true
1828 // $ adb shell wm size reset
1829 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1830 }
1831
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001832 /**
1833 * @return whether the navigation bar can be hidden, e.g. the device has a
1834 * navigation bar and touch exploration is not enabled
1835 */
1836 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04001837 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001838 }
1839
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001840 @Override
1841 public boolean isDefaultOrientationForced() {
1842 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001843 }
1844
Dianne Hackbornc652de82013-02-15 16:32:56 -08001845 @Override
1846 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1847 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1848 mOverscanLeft = left;
1849 mOverscanTop = top;
1850 mOverscanRight = right;
1851 mOverscanBottom = bottom;
1852 }
1853 }
1854
Dianne Hackbornc777e072010-02-12 13:07:59 -08001855 public void updateSettings() {
1856 ContentResolver resolver = mContext.getContentResolver();
1857 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001858 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001859 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001860 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001861 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1862 UserHandle.USER_CURRENT);
1863 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001864 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001865 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1866 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001867
Jeff Browna20dda42014-05-27 20:57:24 -07001868 // Configure wake gesture.
1869 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1870 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1871 UserHandle.USER_CURRENT) != 0;
1872 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1873 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1874 updateWakeGestureListenerLp();
1875 }
1876
Jeff Brown207673cd2012-06-05 17:47:11 -07001877 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001878 int userRotation = Settings.System.getIntForUser(resolver,
1879 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1880 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001881 if (mUserRotation != userRotation) {
1882 mUserRotation = userRotation;
1883 updateRotation = true;
1884 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001885 int userRotationMode = Settings.System.getIntForUser(resolver,
1886 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001887 WindowManagerPolicy.USER_ROTATION_FREE :
1888 WindowManagerPolicy.USER_ROTATION_LOCKED;
1889 if (mUserRotationMode != userRotationMode) {
1890 mUserRotationMode = userRotationMode;
1891 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001892 updateOrientationListenerLp();
1893 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001894
Dianne Hackbornc777e072010-02-12 13:07:59 -08001895 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001896 int pointerLocation = Settings.System.getIntForUser(resolver,
1897 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001898 if (mPointerLocationMode != pointerLocation) {
1899 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001900 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1901 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001902 }
1903 }
1904 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001905 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1906 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1907 String imId = Settings.Secure.getStringForUser(resolver,
1908 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001909 boolean hasSoftInput = imId != null && imId.length() > 0;
1910 if (mHasSoftInput != hasSoftInput) {
1911 mHasSoftInput = hasSoftInput;
1912 updateRotation = true;
1913 }
John Spurlockf1a36642013-10-12 17:50:42 -04001914 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001915 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001916 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001917 }
1918 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001919 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001920 }
1921 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001922 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001923 }
Jeff Brown70825162012-03-28 17:27:48 -07001924 }
1925
Jeff Browna20dda42014-05-27 20:57:24 -07001926 private void updateWakeGestureListenerLp() {
1927 if (shouldEnableWakeGestureLp()) {
1928 mWakeGestureListener.requestWakeUpTrigger();
1929 } else {
1930 mWakeGestureListener.cancelWakeUpTrigger();
1931 }
1932 }
1933
1934 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001935 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001936 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1937 && mWakeGestureListener.isSupported();
1938 }
1939
Jeff Brown70825162012-03-28 17:27:48 -07001940 private void enablePointerLocation() {
1941 if (mPointerLocationView == null) {
1942 mPointerLocationView = new PointerLocationView(mContext);
1943 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001944 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1945 WindowManager.LayoutParams.MATCH_PARENT,
1946 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001947 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001948 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1949 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1950 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1951 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001952 if (ActivityManager.isHighEndGfx()) {
1953 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1954 lp.privateFlags |=
1955 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1956 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001957 lp.format = PixelFormat.TRANSLUCENT;
1958 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001959 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001960 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001961 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001962 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001963 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001964 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001965 }
Jeff Brown70825162012-03-28 17:27:48 -07001966
1967 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001968 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001969 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1970 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001971 wm.removeView(mPointerLocationView);
1972 mPointerLocationView = null;
1973 }
1974 }
1975
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001976 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001977 try {
1978 int rotation = mContext.getResources().getInteger(resID);
1979 switch (rotation) {
1980 case 0:
1981 return Surface.ROTATION_0;
1982 case 90:
1983 return Surface.ROTATION_90;
1984 case 180:
1985 return Surface.ROTATION_180;
1986 case 270:
1987 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001988 }
1989 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001990 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001991 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001992 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001993 }
1994
1995 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001996 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001997 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001998 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001999
2000 outAppOp[0] = AppOpsManager.OP_NONE;
2001
Wale Ogunwale74bf0652015-01-12 10:24:36 -08002002 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
2003 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
2004 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
2005 return WindowManagerGlobal.ADD_INVALID_TYPE;
2006 }
2007
2008 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
2009 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07002010 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002011 }
2012 String permission = null;
2013 switch (type) {
2014 case TYPE_TOAST:
2015 // XXX right now the app process has complete control over
2016 // this... should introduce a token to let the system
2017 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04002018 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002019 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05002020 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002021 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002022 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07002023 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002024 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07002025 case TYPE_ACCESSIBILITY_OVERLAY:
Jason Monk8f7f3182015-11-18 16:35:14 -05002026 case TYPE_QS_DIALOG:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002027 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002028 break;
2029 case TYPE_PHONE:
2030 case TYPE_PRIORITY_PHONE:
2031 case TYPE_SYSTEM_ALERT:
2032 case TYPE_SYSTEM_ERROR:
2033 case TYPE_SYSTEM_OVERLAY:
2034 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002035 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002036 break;
2037 default:
2038 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
2039 }
2040 if (permission != null) {
Billy Laucbe540f2015-06-25 01:51:44 +01002041 if (permission == android.Manifest.permission.SYSTEM_ALERT_WINDOW) {
2042 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01002043 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01002044 if (callingUid == Process.SYSTEM_UID) {
2045 return WindowManagerGlobal.ADD_OKAY;
2046 }
2047
Billy Lau060275f2015-07-15 22:29:19 +01002048 // check if user has enabled this operation. SecurityException will be thrown if
2049 // this app has not been allowed by the user
Billy Laucbe540f2015-06-25 01:51:44 +01002050 final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid,
2051 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01002052 switch (mode) {
2053 case AppOpsManager.MODE_ALLOWED:
2054 case AppOpsManager.MODE_IGNORED:
2055 // although we return ADD_OKAY for MODE_IGNORED, the added window will
2056 // actually be hidden in WindowManagerService
2057 return WindowManagerGlobal.ADD_OKAY;
2058 case AppOpsManager.MODE_ERRORED:
Billy Laucbe540f2015-06-25 01:51:44 +01002059 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01002060 default:
2061 // in the default mode, we will make a decision here based on
2062 // checkCallingPermission()
2063 if (mContext.checkCallingPermission(permission) !=
2064 PackageManager.PERMISSION_GRANTED) {
2065 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
2066 } else {
2067 return WindowManagerGlobal.ADD_OKAY;
2068 }
Billy Laucbe540f2015-06-25 01:51:44 +01002069 }
Billy Laucbe540f2015-06-25 01:51:44 +01002070 }
2071
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002072 if (mContext.checkCallingOrSelfPermission(permission)
2073 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07002074 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002075 }
2076 }
Jeff Brown98365d72012-08-19 20:30:52 -07002077 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002078 }
Craig Mautner88400d32012-09-30 12:35:45 -07002079
2080 @Override
2081 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
2082
2083 // If this switch statement is modified, modify the comment in the declarations of
2084 // the type in {@link WindowManager.LayoutParams} as well.
2085 switch (attrs.type) {
2086 default:
2087 // These are the windows that by default are shown only to the user that created
2088 // them. If this needs to be overridden, set
2089 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
2090 // {@link WindowManager.LayoutParams}. Note that permission
2091 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
2092 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
2093 return true;
2094 }
2095 break;
2096
2097 // These are the windows that by default are shown to all users. However, to
2098 // protect against spoofing, check permissions below.
2099 case TYPE_APPLICATION_STARTING:
2100 case TYPE_BOOT_PROGRESS:
2101 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07002102 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08002103 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07002104 case TYPE_KEYGUARD_DIALOG:
2105 case TYPE_MAGNIFICATION_OVERLAY:
2106 case TYPE_NAVIGATION_BAR:
2107 case TYPE_NAVIGATION_BAR_PANEL:
2108 case TYPE_PHONE:
2109 case TYPE_POINTER:
2110 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002111 case TYPE_SEARCH_BAR:
2112 case TYPE_STATUS_BAR:
2113 case TYPE_STATUS_BAR_PANEL:
2114 case TYPE_STATUS_BAR_SUB_PANEL:
2115 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002116 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07002117 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002118 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002119 break;
2120 }
2121
2122 // Check if third party app has set window to system window type.
2123 return mContext.checkCallingOrSelfPermission(
2124 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
2125 != PackageManager.PERMISSION_GRANTED;
2126 }
2127
Craig Mautner967212c2013-04-13 21:10:58 -07002128 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002129 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2130 switch (attrs.type) {
2131 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002132 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002133 // These types of windows can't receive input events.
2134 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2135 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002136 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002137 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002138 case TYPE_STATUS_BAR:
2139
2140 // If the Keyguard is in a hidden state (occluded by another window), we force to
2141 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2142 // the keyguard as occluded wouldn't set these flags again.
2143 // See {@link #processKeyguardSetHiddenResultLw}.
2144 if (mKeyguardHidden) {
2145 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2146 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2147 }
2148 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002149 }
Adrian Roos38502112014-04-09 21:04:11 +02002150
2151 if (attrs.type != TYPE_STATUS_BAR) {
2152 // The status bar is the only window allowed to exhibit keyguard behavior.
2153 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2154 }
Adrian Roosea562512014-05-05 13:33:03 +02002155
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002156 if (ActivityManager.isHighEndGfx()) {
2157 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
2158 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2159 }
2160 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
Jorim Jaggi406585a2015-12-21 10:58:56 +01002161 || (mForceWindowDrawsStatusBarBackground
2162 && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT)) {
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002163 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
2164 }
Adrian Roosea562512014-05-05 13:33:03 +02002165 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002166 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002167
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002168 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002169 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002170 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002171
Michael Wright3818c922014-09-02 13:59:07 -07002172 private void readCameraLensCoverState() {
2173 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2174 }
2175
Jeff Browndaa37532012-05-01 15:54:03 -07002176 private boolean isHidden(int accessibilityMode) {
2177 switch (accessibilityMode) {
2178 case 1:
2179 return mLidState == LID_CLOSED;
2180 case 2:
2181 return mLidState == LID_OPEN;
2182 default:
2183 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002184 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002185 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002186
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002187 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002188 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002189 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2190 int navigationPresence) {
2191 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2192
Jeff Brownf71343d2013-05-31 17:59:11 -07002193 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002194 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07002195 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002196
Jeff Browndaa37532012-05-01 15:54:03 -07002197 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2198 || (keyboardPresence == PRESENCE_INTERNAL
2199 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002200 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002201 if (!mHasSoftInput) {
2202 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2203 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002204 }
2205
Jeff Browndaa37532012-05-01 15:54:03 -07002206 if (config.navigation == Configuration.NAVIGATION_NONAV
2207 || (navigationPresence == PRESENCE_INTERNAL
2208 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002209 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002210 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002211 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002212
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002213 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002214 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002215 public int windowTypeToLayerLw(int type) {
2216 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002217 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002218 }
2219 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07002220 case TYPE_PRIVATE_PRESENTATION:
2221 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002222 case TYPE_WALLPAPER:
2223 // wallpaper is at the bottom, though the window manager may move it.
2224 return 2;
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002225 case TYPE_DOCK_DIVIDER:
2226 return 2;
Jason Monk8f7f3182015-11-18 16:35:14 -05002227 case TYPE_QS_DIALOG:
2228 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002229 case TYPE_PHONE:
2230 return 3;
2231 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002232 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002233 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002234 case TYPE_VOICE_INTERACTION:
2235 // voice interaction layer is almost immediately above apps.
2236 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002237 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002238 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002239 case TYPE_SYSTEM_DIALOG:
2240 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002241 case TYPE_TOAST:
2242 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002243 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002244 case TYPE_PRIORITY_PHONE:
2245 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002246 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002247 case TYPE_DREAM:
2248 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002249 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002250 case TYPE_SYSTEM_ALERT:
2251 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002252 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002253 case TYPE_INPUT_METHOD:
2254 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002255 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002256 case TYPE_INPUT_METHOD_DIALOG:
2257 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002258 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002259 case TYPE_KEYGUARD_SCRIM:
2260 // the safety window that shows behind keyguard while keyguard is starting
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002261 return 14;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002262 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002263 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002264 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002265 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002266 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002267 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002268 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002269 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002270 case TYPE_VOLUME_OVERLAY:
2271 // the on-screen volume indicator and controller shown when the user
2272 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002273 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002274 case TYPE_SYSTEM_OVERLAY:
2275 // the on-screen volume indicator and controller shown when the user
2276 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002277 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002278 case TYPE_NAVIGATION_BAR:
2279 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002280 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002281 case TYPE_NAVIGATION_BAR_PANEL:
2282 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002283 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002284 case TYPE_SYSTEM_ERROR:
2285 // system-level error dialogs
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002286 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002287 case TYPE_MAGNIFICATION_OVERLAY:
2288 // used to highlight the magnified portion of a display
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002289 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002290 case TYPE_DISPLAY_OVERLAY:
2291 // used to simulate secondary display devices
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002292 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002293 case TYPE_DRAG:
2294 // the drag layer: input for drag-and-drop is associated with this window,
2295 // which sits above all other focusable windows
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002296 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002297 case TYPE_ACCESSIBILITY_OVERLAY:
2298 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002299 return 27;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002300 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002301 return 28;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002302 case TYPE_BOOT_PROGRESS:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002303 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002304 case TYPE_POINTER:
2305 // the (mouse) pointer layer
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002306 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002307 }
2308 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002309 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002310 }
2311
2312 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002313 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002314 public int subWindowTypeToLayerLw(int type) {
2315 switch (type) {
2316 case TYPE_APPLICATION_PANEL:
2317 case TYPE_APPLICATION_ATTACHED_DIALOG:
2318 return APPLICATION_PANEL_SUBLAYER;
2319 case TYPE_APPLICATION_MEDIA:
2320 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002321 case TYPE_APPLICATION_MEDIA_OVERLAY:
2322 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002323 case TYPE_APPLICATION_SUB_PANEL:
2324 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002325 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2326 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002327 }
2328 Log.e(TAG, "Unknown sub-window type: " + type);
2329 return 0;
2330 }
2331
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002332 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002333 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002334 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002335 }
2336
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002337 private int getNavigationBarWidth(int rotation, int uiMode) {
2338 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2339 return mNavigationBarWidthForRotationInCarMode[rotation];
2340 } else {
2341 return mNavigationBarWidthForRotationDefault[rotation];
2342 }
2343 }
2344
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002345 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002346 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
2347 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002348 if (mHasNavigationBar) {
2349 // For a basic navigation bar, when we are in landscape mode we place
2350 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002351 if (mNavigationBarCanMove && fullWidth > fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002352 return fullWidth - getNavigationBarWidth(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002353 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002354 }
2355 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002356 }
2357
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002358 private int getNavigationBarHeight(int rotation, int uiMode) {
2359 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2360 return mNavigationBarHeightForRotationInCarMode[rotation];
2361 } else {
2362 return mNavigationBarHeightForRotationDefault[rotation];
2363 }
2364 }
2365
Jose Lima9546b202014-07-02 17:21:51 -07002366 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002367 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
2368 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002369 if (mHasNavigationBar) {
2370 // For a basic navigation bar, when we are in portrait mode we place
2371 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002372 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002373 return fullHeight - getNavigationBarHeight(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002374 }
2375 }
2376 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002377 }
2378
Jose Lima9546b202014-07-02 17:21:51 -07002379 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002380 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) {
2381 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002382 }
2383
Jose Lima9546b202014-07-02 17:21:51 -07002384 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002385 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
John Spurlock80f00c12013-06-13 11:10:51 -04002386 // There is a separate status bar at the top of the display. We don't count that as part
2387 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002388 // we do want to exclude it since applications can't generally use that part
2389 // of the screen.
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002390 return getNonDecorDisplayHeight(
2391 fullWidth, fullHeight, rotation, uiMode) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002392 }
2393
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002394 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002395 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2396 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002397 (isKeyguardHostWindow(attrs) &&
2398 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002399 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002400 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002401
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002402 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002403 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2404 return attrs.type == TYPE_STATUS_BAR;
2405 }
2406
2407 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002408 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002409 switch (attrs.type) {
2410 case TYPE_STATUS_BAR:
2411 case TYPE_NAVIGATION_BAR:
2412 case TYPE_WALLPAPER:
2413 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002414 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002415 return false;
2416 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002417 // Hide only windows below the keyguard host window.
2418 return windowTypeToLayerLw(win.getBaseType())
2419 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002420 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002421 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002422
Craig Mautner7d7808f2014-09-11 18:02:38 -07002423 @Override
2424 public WindowState getWinShowWhenLockedLw() {
2425 return mWinShowWhenLocked;
2426 }
2427
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002428 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002429 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002430 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2431 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002432 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002433 if (!SHOW_STARTING_ANIMATIONS) {
2434 return null;
2435 }
2436 if (packageName == null) {
2437 return null;
2438 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002439
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002440 WindowManager wm = null;
2441 View view = null;
2442
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002443 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002444 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002445 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2446 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2447 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002448 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002449 try {
2450 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002451 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002452 } catch (PackageManager.NameNotFoundException e) {
2453 // Ignore
2454 }
2455 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002456
Jorim Jaggia16cc152015-06-01 16:55:05 -07002457 PhoneWindow win = new PhoneWindow(context);
2458 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002459
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002460 Resources r = context.getResources();
2461 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002462
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002463 win.setType(
2464 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002465
2466 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2467 // Assumes it's safe to show starting windows of launched apps while
2468 // the keyguard is being hidden. This is okay because starting windows never show
2469 // secret information.
2470 if (mKeyguardHidden) {
2471 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2472 }
2473 }
2474
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002475 // Force the window flags: this is a fake window, so it is not really
2476 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2477 // flag because we do know that the next window will take input
2478 // focus, so we want to get the IME window up on top of us right away.
2479 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002480 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002481 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2482 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2483 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002484 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002485 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2486 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2487 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002488
Adam Powell04fe6eb2013-05-31 14:39:48 -07002489 win.setDefaultIcon(icon);
2490 win.setDefaultLogo(logo);
2491
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002492 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002493 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002494
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002495 final WindowManager.LayoutParams params = win.getAttributes();
2496 params.token = appToken;
2497 params.packageName = packageName;
2498 params.windowAnimations = win.getWindowStyle().getResourceId(
2499 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002500 params.privateFlags |=
2501 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002502 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002503
2504 if (!compatInfo.supportsScreen()) {
2505 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2506 }
2507
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002508 params.setTitle("Starting " + packageName);
2509
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002510 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2511 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002512
Craig Mautner6fbda632012-07-03 09:26:39 -07002513 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002514 TAG, "Adding starting window for " + packageName
2515 + " / " + appToken + ": "
2516 + (view.getParent() != null ? view : null));
2517
2518 wm.addView(view, params);
2519
2520 // Only return the view if it was successfully added to the
2521 // window manager... which we can tell by it having a parent.
2522 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002523 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002524 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002525 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2526 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002527 } catch (RuntimeException e) {
2528 // don't crash if something else bad happens, for example a
2529 // failure loading resources because we are loading from an app
2530 // on external storage that has been unmounted.
2531 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002532 } finally {
2533 if (view != null && view.getParent() == null) {
2534 Log.w(TAG, "view not successfully added to wm, removing view");
2535 wm.removeViewImmediate(view);
2536 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002537 }
2538
2539 return null;
2540 }
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 removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002545 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2546 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002547
2548 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002549 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002550 wm.removeView(window);
2551 }
2552 }
2553
2554 /**
2555 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002556 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002557 * Currently enforces that three window types are singletons:
2558 * <ul>
2559 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002560 * <li>KEYGUARD_TYPE</li>
2561 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002562 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002563 * @param win The window to be added
2564 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002565 *
Jeff Brown98365d72012-08-19 20:30:52 -07002566 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2567 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002568 */
Jose Lima9546b202014-07-02 17:21:51 -07002569 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002570 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2571 switch (attrs.type) {
2572 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002573 mContext.enforceCallingOrSelfPermission(
2574 android.Manifest.permission.STATUS_BAR_SERVICE,
2575 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002576 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002577 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002578 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002579 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002580 }
2581 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002582 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002583 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002584 case TYPE_NAVIGATION_BAR:
2585 mContext.enforceCallingOrSelfPermission(
2586 android.Manifest.permission.STATUS_BAR_SERVICE,
2587 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002588 if (mNavigationBar != null) {
2589 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002590 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002591 }
2592 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002593 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002594 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002595 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002596 break;
Jim Millere898ac52012-04-06 17:10:57 -07002597 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002598 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002599 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002600 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002601 mContext.enforceCallingOrSelfPermission(
2602 android.Manifest.permission.STATUS_BAR_SERVICE,
2603 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002604 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002605 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002606 if (mKeyguardScrim != null) {
2607 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2608 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002609 mKeyguardScrim = win;
2610 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002611 }
Jeff Brown98365d72012-08-19 20:30:52 -07002612 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002613 }
2614
2615 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002616 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002617 public void removeWindowLw(WindowState win) {
2618 if (mStatusBar == win) {
2619 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002620 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002621 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002622 } else if (mKeyguardScrim == win) {
2623 Log.v(TAG, "Removing keyguard scrim");
2624 mKeyguardScrim = null;
2625 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002626 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002627 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002628 }
2629 }
2630
2631 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002632
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002633 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002634 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002635 public int selectAnimationLw(WindowState win, int transit) {
2636 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2637 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002638 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002639 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002640 if (transit == TRANSIT_EXIT
2641 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002642 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002643 } else if (transit == TRANSIT_ENTER
2644 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002645 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002646 }
2647 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002648 if (win.getAttrs().windowAnimations != 0) {
2649 return 0;
2650 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002651 // This can be on either the bottom or the right.
2652 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002653 if (transit == TRANSIT_EXIT
2654 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002655 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002656 } else if (transit == TRANSIT_ENTER
2657 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002658 return R.anim.dock_bottom_enter;
2659 }
2660 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002661 if (transit == TRANSIT_EXIT
2662 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002663 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002664 } else if (transit == TRANSIT_ENTER
2665 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002666 return R.anim.dock_right_enter;
2667 }
2668 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002669 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002670 return selectDockedDividerAnimationLw(win, transit);
Craig Mautner4b71aa12012-12-27 17:20:01 -08002671 }
2672
2673 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002674 if (win.hasAppShownWindows()) {
2675 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2676 return com.android.internal.R.anim.app_starting_exit;
2677 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002678 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002679 && transit == TRANSIT_ENTER) {
2680 // Special case: we are animating in a dream, while the keyguard
2681 // is shown. We don't want an animation on the dream, because
2682 // we need it shown immediately with the keyguard animating away
2683 // to reveal it.
2684 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002685 }
2686
2687 return 0;
2688 }
2689
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002690 private int selectDockedDividerAnimationLw(WindowState win, int transit) {
2691 int insets = mWindowManagerFuncs.getDockedDividerInsetsLw();
2692
2693 // If the divider is behind the navigation bar, don't animate.
2694 if (mNavigationBar != null
2695 && (win.getFrameLw().top + insets >= mNavigationBar.getFrameLw().top
2696 || win.getFrameLw().left + insets >= mNavigationBar.getFrameLw().left)) {
2697 return 0;
2698 }
2699 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
2700 return R.anim.fade_in;
2701 } else if (transit == TRANSIT_EXIT) {
2702 return R.anim.fade_out;
2703 } else {
2704 return 0;
2705 }
2706 }
2707
Craig Mautner3c174372013-02-21 17:54:37 -08002708 @Override
2709 public void selectRotationAnimationLw(int anim[]) {
2710 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2711 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2712 + (mTopFullscreenOpaqueWindowState == null ?
2713 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2714 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2715 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2716 case ROTATION_ANIMATION_CROSSFADE:
2717 anim[0] = R.anim.rotation_animation_xfade_exit;
2718 anim[1] = R.anim.rotation_animation_enter;
2719 break;
2720 case ROTATION_ANIMATION_JUMPCUT:
2721 anim[0] = R.anim.rotation_animation_jump_exit;
2722 anim[1] = R.anim.rotation_animation_enter;
2723 break;
2724 case ROTATION_ANIMATION_ROTATE:
2725 default:
2726 anim[0] = anim[1] = 0;
2727 break;
2728 }
2729 } else {
2730 anim[0] = anim[1] = 0;
2731 }
2732 }
2733
2734 @Override
2735 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2736 boolean forceDefault) {
2737 switch (exitAnimId) {
2738 case R.anim.rotation_animation_xfade_exit:
2739 case R.anim.rotation_animation_jump_exit:
2740 // These are the only cases that matter.
2741 if (forceDefault) {
2742 return false;
2743 }
2744 int anim[] = new int[2];
2745 selectRotationAnimationLw(anim);
2746 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2747 default:
2748 return true;
2749 }
2750 }
2751
2752 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002753 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2754 boolean goingToNotificationShade) {
2755 if (goingToNotificationShade) {
2756 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002757 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002758
2759 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2760 R.anim.lock_screen_behind_enter_wallpaper :
2761 R.anim.lock_screen_behind_enter);
2762
2763 // TODO: Use XML interpolators when we have log interpolators available in XML.
2764 final List<Animation> animations = set.getAnimations();
2765 for (int i = animations.size() - 1; i >= 0; --i) {
2766 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2767 }
2768
2769 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002770 }
2771
2772
2773 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002774 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2775 if (goingToNotificationShade) {
2776 return null;
2777 } else {
2778 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2779 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002780 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002781
2782 private static void awakenDreams() {
2783 IDreamManager dreamManager = getDreamManager();
2784 if (dreamManager != null) {
2785 try {
2786 dreamManager.awaken();
2787 } catch (RemoteException e) {
2788 // fine, stay asleep then
2789 }
2790 }
2791 }
2792
2793 static IDreamManager getDreamManager() {
2794 return IDreamManager.Stub.asInterface(
2795 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2796 }
2797
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002798 TelecomManager getTelecommService() {
2799 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002800 }
2801
Jeff Brown4d396052010-10-29 21:50:21 -07002802 static IAudioService getAudioService() {
2803 IAudioService audioService = IAudioService.Stub.asInterface(
2804 ServiceManager.checkService(Context.AUDIO_SERVICE));
2805 if (audioService == null) {
2806 Log.w(TAG, "Unable to find IAudioService interface.");
2807 }
2808 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002809 }
2810
2811 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002812 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002813 }
2814
2815 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2816 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2817 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2818 };
2819
2820 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002821 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002822 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002823 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002824 final int keyCode = event.getKeyCode();
2825 final int repeatCount = event.getRepeatCount();
2826 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002827 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002828 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2829 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002830
Jeff Brown40013652012-05-16 21:22:36 -07002831 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002832 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002833 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2834 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002835 }
2836
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002837 // If we think we might have a volume down & power key chord on the way
2838 // but we're not sure, then tell the dispatcher to wait a little while and
2839 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002840 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002841 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002842 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002843 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2844 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002845 if (now < timeoutTime) {
2846 return timeoutTime - now;
2847 }
2848 }
2849 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002850 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002851 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002852 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002853 }
2854 return -1;
2855 }
2856 }
2857
Michael Wright6a62e552014-06-03 19:19:48 -07002858 // Cancel any pending meta actions if we see any other keys being pressed between the down
2859 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002860 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002861 mPendingMetaAction = false;
2862 }
2863
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002864 // First we always handle the home key here, so applications
2865 // can never break it, although if keyguard is on, we do let
2866 // it handle it, because that gives us the correct 5 second
2867 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002868 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002869
Jeff Brown49ed71d2010-12-06 17:13:33 -08002870 // If we have released the home key, and didn't do anything else
2871 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002872 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002873 cancelPreloadRecentApps();
2874
Jeff Brown49ed71d2010-12-06 17:13:33 -08002875 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002876 if (mHomeConsumed) {
2877 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002878 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002879 }
Jeff Browncaca8812013-05-09 13:34:33 -07002880
2881 if (canceled) {
2882 Log.i(TAG, "Ignoring HOME; event canceled.");
2883 return -1;
2884 }
2885
Yorke Lee4f803242014-12-15 23:22:06 +00002886 // If an incoming call is ringing, HOME is totally disabled.
2887 // (The user is already on the InCallUI at this point,
2888 // and his ONLY options are to answer or reject the call.)
2889 TelecomManager telecomManager = getTelecommService();
2890 if (telecomManager != null && telecomManager.isRinging()) {
2891 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2892 return -1;
2893 }
2894
Jeff Browncaca8812013-05-09 13:34:33 -07002895 // Delay handling home if a double-tap is possible.
2896 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2897 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2898 mHomeDoubleTapPending = true;
2899 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2900 ViewConfiguration.getDoubleTapTimeout());
2901 return -1;
2902 }
2903
Jeff Brown13f00f02014-10-31 14:45:50 -07002904 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002905 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002906 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002907
2908 // If a system window has focus, then it doesn't make sense
2909 // right now to interact with applications.
2910 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2911 if (attrs != null) {
2912 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002913 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2914 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2915 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002916 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002917 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002918 }
2919 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2920 for (int i=0; i<typeCount; i++) {
2921 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2922 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002923 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002924 }
2925 }
2926 }
Jeff Browncaca8812013-05-09 13:34:33 -07002927
2928 // Remember that home is pressed and handle special actions.
2929 if (repeatCount == 0) {
2930 mHomePressed = true;
2931 if (mHomeDoubleTapPending) {
2932 mHomeDoubleTapPending = false;
2933 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2934 handleDoubleTapOnHome();
2935 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2936 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2937 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002938 }
Jeff Browncaca8812013-05-09 13:34:33 -07002939 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2940 if (!keyguardOn) {
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09002941 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002942 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002943 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002944 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002945 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002946 // Hijack modified menu keys for debugging features
2947 final int chordBug = KeyEvent.META_SHIFT_ON;
2948
2949 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002950 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002951 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002952 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2953 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002954 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002955 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002956 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002957 Intent service = new Intent();
2958 service.setClassName(mContext, "com.android.server.LoadAverageService");
2959 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002960 boolean shown = Settings.Global.getInt(
2961 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002962 if (!shown) {
2963 mContext.startService(service);
2964 } else {
2965 mContext.stopService(service);
2966 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002967 Settings.Global.putInt(
2968 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002969 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002970 }
2971 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002972 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002973 if (down) {
2974 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002975 mSearchKeyShortcutPending = true;
2976 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002977 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002978 } else {
2979 mSearchKeyShortcutPending = false;
2980 if (mConsumeSearchKeyUp) {
2981 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002982 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002983 }
2984 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002985 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002986 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002987 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002988 if (down && repeatCount == 0) {
2989 preloadRecentApps();
2990 } else if (!down) {
2991 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002992 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002993 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002994 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002995 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2996 if (down) {
2997 IStatusBarService service = getStatusBarService();
2998 if (service != null) {
2999 try {
3000 service.expandNotificationsPanel();
3001 } catch (RemoteException e) {
3002 // do nothing.
3003 }
3004 }
3005 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01003006 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
3007 if (down) {
3008 if (repeatCount == 0) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003009 toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003010 }
3011 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003012 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
3013 if (down) {
3014 if (repeatCount == 0) {
3015 mAssistKeyLongPressed = false;
3016 } else if (repeatCount == 1) {
3017 mAssistKeyLongPressed = true;
3018 if (!keyguardOn) {
3019 launchAssistLongPressAction();
3020 }
3021 }
3022 } else {
3023 if (mAssistKeyLongPressed) {
3024 mAssistKeyLongPressed = false;
3025 } else {
3026 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003027 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003028 }
3029 }
3030 }
3031 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003032 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
3033 if (!down) {
3034 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07003035 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003036 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3037 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07003038 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
3039 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
3040 if (dic != null) {
3041 try {
3042 dic.exitIdle("voice-search");
3043 } catch (RemoteException e) {
3044 }
3045 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003046 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07003047 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003048 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003049 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003050 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003051 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
3052 if (down && repeatCount == 0) {
3053 mHandler.post(mScreenshotRunnable);
3054 }
3055 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003056 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3057 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3058 if (down) {
3059 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3060
3061 // Disable autobrightness if it's on
3062 int auto = Settings.System.getIntForUser(
3063 mContext.getContentResolver(),
3064 Settings.System.SCREEN_BRIGHTNESS_MODE,
3065 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3066 UserHandle.USER_CURRENT_OR_SELF);
3067 if (auto != 0) {
3068 Settings.System.putIntForUser(mContext.getContentResolver(),
3069 Settings.System.SCREEN_BRIGHTNESS_MODE,
3070 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3071 UserHandle.USER_CURRENT_OR_SELF);
3072 }
3073
3074 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3075 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3076 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3077 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3078 Settings.System.SCREEN_BRIGHTNESS,
3079 mPowerManager.getDefaultScreenBrightnessSetting(),
3080 UserHandle.USER_CURRENT_OR_SELF);
3081 brightness += step;
3082 // Make sure we don't go beyond the limits.
3083 brightness = Math.min(max, brightness);
3084 brightness = Math.max(min, brightness);
3085
3086 Settings.System.putIntForUser(mContext.getContentResolver(),
3087 Settings.System.SCREEN_BRIGHTNESS, brightness,
3088 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003089 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003090 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003091 }
3092 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003093 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3094 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3095 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
3096 if (mUseTvRouting) {
3097 // On TVs volume keys never go to the foreground app.
3098 dispatchDirectAudioEvent(event);
3099 return -1;
3100 }
Michael Wrightce0c13a2014-07-30 10:49:21 -07003101 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003102 if (down) {
3103 mPendingMetaAction = true;
3104 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003105 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003106 }
3107 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003108 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003109
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003110 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003111 // Any printing key that is chorded with Search should be consumed
3112 // even if no shortcut was invoked. This prevents text from being
3113 // inadvertently inserted when using a keyboard that has built-in macro
3114 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003115 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003116 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3117 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003118 mConsumeSearchKeyUp = true;
3119 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003120 if (down && repeatCount == 0 && !keyguardOn) {
3121 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3122 if (shortcutIntent != null) {
3123 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003124 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003125 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003126 } catch (ActivityNotFoundException ex) {
3127 Slog.w(TAG, "Dropping shortcut key combination because "
3128 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003129 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003130 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003131 } else {
3132 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003133 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003134 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003135 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003136 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003137 }
3138 }
3139
Jeff Brown68b909d2011-12-07 16:36:01 -08003140 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003141 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003142 && (metaState & KeyEvent.META_META_ON) != 0) {
3143 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003144 if (kcm.isPrintingKey(keyCode)) {
3145 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3146 metaState & ~(KeyEvent.META_META_ON
3147 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3148 if (shortcutIntent != null) {
3149 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3150 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003151 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07003152 } catch (ActivityNotFoundException ex) {
3153 Slog.w(TAG, "Dropping shortcut key combination because "
3154 + "the activity to which it is registered was not found: "
3155 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3156 }
3157 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003158 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003159 }
3160 }
3161
Jeff Brown6651a632011-11-28 12:59:11 -08003162 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003163 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003164 String category = sApplicationLaunchKeyCategories.get(keyCode);
3165 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003166 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003167 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3168 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003169 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003170 } catch (ActivityNotFoundException ex) {
3171 Slog.w(TAG, "Dropping application launch key because "
3172 + "the activity to which it is registered was not found: "
3173 + "keyCode=" + keyCode + ", category=" + category, ex);
3174 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003175 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003176 }
3177 }
3178
Michael Wright61c46752014-08-21 16:57:33 -07003179 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003180 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003181 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003182 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003183 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003184 mRecentAppsHeldModifiers = shiftlessModifiers;
3185 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003186 return -1;
3187 }
3188 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003189 } else if (!down && mRecentAppsHeldModifiers != 0
3190 && (metaState & mRecentAppsHeldModifiers) == 0) {
3191 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003192 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003193 }
3194
Yohei Yukawaae61f712015-12-09 13:00:10 -08003195 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003196 if (down && repeatCount == 0
3197 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3198 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003199 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3200 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3201 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003202 return -1;
3203 }
3204 if (mLanguageSwitchKeyPressed && !down
3205 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3206 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3207 mLanguageSwitchKeyPressed = false;
3208 return -1;
3209 }
3210
Jeff Brown13f00f02014-10-31 14:45:50 -07003211 if (isValidGlobalKey(keyCode)
3212 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003213 return -1;
3214 }
3215
Michael Wright6a62e552014-06-03 19:19:48 -07003216 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003217 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003218 return -1;
3219 }
3220
Jeff Brown68b909d2011-12-07 16:36:01 -08003221 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003222 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003223 }
3224
Jeff Brown3915bb82010-11-05 15:02:16 -07003225 /** {@inheritDoc} */
3226 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003227 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003228 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003229 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003230 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3231 + ", flags=" + event.getFlags()
3232 + ", keyCode=" + event.getKeyCode()
3233 + ", scanCode=" + event.getScanCode()
3234 + ", metaState=" + event.getMetaState()
3235 + ", repeatCount=" + event.getRepeatCount()
3236 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003237 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003238
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003239 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003240 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3241 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003242 final int keyCode = event.getKeyCode();
3243 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003244 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3245 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003246
Jeff Brown54875002011-04-06 15:33:01 -07003247 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003248 final FallbackAction fallbackAction;
3249 if (initialDown) {
3250 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3251 } else {
3252 fallbackAction = mFallbackActions.get(keyCode);
3253 }
3254
3255 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003256 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003257 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3258 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003259 }
3260
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003261 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3262 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003263 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003264 event.getAction(), fallbackAction.keyCode,
3265 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003266 event.getDeviceId(), event.getScanCode(),
3267 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003268
3269 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3270 fallbackEvent.recycle();
3271 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003272 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003273
3274 if (initialDown) {
3275 mFallbackActions.put(keyCode, fallbackAction);
3276 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3277 mFallbackActions.remove(keyCode);
3278 fallbackAction.recycle();
3279 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003280 }
3281 }
3282
Jeff Brown40013652012-05-16 21:22:36 -07003283 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003284 if (fallbackEvent == null) {
3285 Slog.d(TAG, "No fallback.");
3286 } else {
3287 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3288 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003289 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003290 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003291 }
3292
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003293 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003294 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003295 if ((actions & ACTION_PASS_TO_USER) != 0) {
3296 long delayMillis = interceptKeyBeforeDispatching(
3297 win, fallbackEvent, policyFlags);
3298 if (delayMillis == 0) {
3299 return true;
3300 }
3301 }
3302 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003303 }
3304
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003305 private void launchAssistLongPressAction() {
3306 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3307 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3308
3309 // launch the search activity
3310 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3311 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3312 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003313 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003314 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003315 SearchManager searchManager = getSearchManager();
3316 if (searchManager != null) {
3317 searchManager.stopSearch();
3318 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003319 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003320 } catch (ActivityNotFoundException e) {
3321 Slog.w(TAG, "No activity to handle assist long press action.", e);
3322 }
3323 }
3324
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003325 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003326 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003327 if (!isUserSetupComplete()) {
3328 // Disable opening assist window during setup
3329 return;
3330 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003331 Bundle args = null;
3332 if (deviceId > Integer.MIN_VALUE) {
3333 args = new Bundle();
3334 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003335 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003336 if ((mContext.getResources().getConfiguration().uiMode
3337 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3338 // On TV, use legacy handling until assistants are implemented in the proper way.
3339 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3340 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3341 } else {
3342 try {
3343 if (hint != null) {
3344 if (args == null) {
3345 args = new Bundle();
3346 }
3347 args.putBoolean(hint, true);
3348 }
3349 IStatusBarService statusbar = getStatusBarService();
3350 if (statusbar != null) {
3351 statusbar.startAssist(args);
3352 }
3353 } catch (RemoteException e) {
3354 Slog.e(TAG, "RemoteException when starting assist", e);
3355 // re-acquire status bar service next time it is needed.
3356 mStatusBarService = null;
3357 }
3358 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003359 }
3360
Bart Sears8b1c27c2015-03-18 23:51:02 +00003361 private void startActivityAsUser(Intent intent, UserHandle handle) {
3362 if (isUserSetupComplete()) {
3363 mContext.startActivityAsUser(intent, handle);
3364 } else {
3365 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3366 }
3367 }
3368
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003369 private SearchManager getSearchManager() {
3370 if (mSearchManager == null) {
3371 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3372 }
3373 return mSearchManager;
3374 }
3375
Jeff Browncaca8812013-05-09 13:34:33 -07003376 private void preloadRecentApps() {
3377 mPreloadedRecentApps = true;
3378 try {
3379 IStatusBarService statusbar = getStatusBarService();
3380 if (statusbar != null) {
3381 statusbar.preloadRecentApps();
3382 }
3383 } catch (RemoteException e) {
3384 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3385 // re-acquire status bar service next time it is needed.
3386 mStatusBarService = null;
3387 }
3388 }
3389
3390 private void cancelPreloadRecentApps() {
3391 if (mPreloadedRecentApps) {
3392 mPreloadedRecentApps = false;
3393 try {
3394 IStatusBarService statusbar = getStatusBarService();
3395 if (statusbar != null) {
3396 statusbar.cancelPreloadRecentApps();
3397 }
3398 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003399 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003400 // re-acquire status bar service next time it is needed.
3401 mStatusBarService = null;
3402 }
3403 }
3404 }
3405
3406 private void toggleRecentApps() {
3407 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003408 try {
3409 IStatusBarService statusbar = getStatusBarService();
3410 if (statusbar != null) {
3411 statusbar.toggleRecentApps();
3412 }
3413 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003414 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3415 // re-acquire status bar service next time it is needed.
3416 mStatusBarService = null;
3417 }
3418 }
3419
Craig Mautner84984fa2014-06-19 11:19:20 -07003420 @Override
3421 public void showRecentApps() {
3422 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3423 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3424 }
3425
Winson Chung1e8d71b2014-05-16 17:05:22 -07003426 private void showRecentApps(boolean triggeredFromAltTab) {
3427 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3428 try {
3429 IStatusBarService statusbar = getStatusBarService();
3430 if (statusbar != null) {
3431 statusbar.showRecentApps(triggeredFromAltTab);
3432 }
3433 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003434 Slog.e(TAG, "RemoteException when showing recent apps", e);
3435 // re-acquire status bar service next time it is needed.
3436 mStatusBarService = null;
3437 }
3438 }
3439
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003440 private void toggleKeyboardShortcutsMenu() {
Clara Bayarrif2debb12015-07-10 14:47:17 +01003441 try {
3442 IStatusBarService statusbar = getStatusBarService();
3443 if (statusbar != null) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003444 statusbar.toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003445 }
3446 } catch (RemoteException e) {
3447 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3448 }
3449 }
3450
Winson Chungcdcd4872014-08-05 18:00:13 -07003451 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003452 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3453 try {
3454 IStatusBarService statusbar = getStatusBarService();
3455 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003456 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003457 }
3458 } catch (RemoteException e) {
3459 Slog.e(TAG, "RemoteException when closing recent apps", e);
3460 // re-acquire status bar service next time it is needed.
3461 mStatusBarService = null;
3462 }
3463 }
3464
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003465 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003466 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003467 }
3468
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003469 /**
3470 * A home key -> launch home action was detected. Take the appropriate action
3471 * given the situation with the keyguard.
3472 */
Bryce Lee662ed802015-04-10 20:11:39 +00003473 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3474 if (respectKeyguard) {
3475 if (isKeyguardShowingAndNotOccluded()) {
3476 // don't launch home if keyguard showing
3477 return;
3478 }
3479
3480 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3481 // when in keyguard restricted mode, must first verify unlock
3482 // before launching home
3483 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3484 @Override
3485 public void onKeyguardExitResult(boolean success) {
3486 if (success) {
3487 try {
3488 ActivityManagerNative.getDefault().stopAppSwitches();
3489 } catch (RemoteException e) {
3490 }
3491 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3492 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003493 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003494 }
Bryce Lee662ed802015-04-10 20:11:39 +00003495 });
3496 return;
3497 }
3498 }
3499
3500 // no keyguard stuff to worry about, just launch home!
3501 try {
3502 ActivityManagerNative.getDefault().stopAppSwitches();
3503 } catch (RemoteException e) {
3504 }
3505 if (mRecentsVisible) {
3506 // Hide Recents and notify it to launch Home
3507 if (awakenFromDreams) {
3508 awakenDreams();
3509 }
Bryce Lee662ed802015-04-10 20:11:39 +00003510 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003511 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003512 // Otherwise, just launch Home
3513 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3514 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003515 }
3516 }
3517
John Spurlock04db1762013-05-13 12:46:41 -04003518 private final Runnable mClearHideNavigationFlag = new Runnable() {
3519 @Override
3520 public void run() {
3521 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3522 // Clear flags.
3523 mForceClearedSystemUiFlags &=
3524 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3525 }
3526 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003527 }
3528 };
3529
3530 /**
3531 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3532 * to determine when the nav bar should be shown and prevent applications from
3533 * receiving those touches.
3534 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003535 final class HideNavInputEventReceiver extends InputEventReceiver {
3536 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3537 super(inputChannel, looper);
3538 }
3539
Dianne Hackborndf89e652011-10-06 22:35:11 -07003540 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003541 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003542 boolean handled = false;
3543 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003544 if (event instanceof MotionEvent
3545 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3546 final MotionEvent motionEvent = (MotionEvent)event;
3547 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003548 // When the user taps down, we re-show the nav bar.
3549 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003550 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003551 // Any user activity always causes us to show the
3552 // navigation controls, if they had been hidden.
3553 // We also clear the low profile and only content
3554 // flags so that tapping on the screen will atomically
3555 // restore all currently hidden screen decorations.
3556 int newVal = mResettingSystemUiFlags |
3557 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3558 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3559 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003560 if (mResettingSystemUiFlags != newVal) {
3561 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003562 changed = true;
3563 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003564 // We don't allow the system's nav bar to be hidden
3565 // again for 1 second, to prevent applications from
3566 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003567 newVal = mForceClearedSystemUiFlags |
3568 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003569 if (mForceClearedSystemUiFlags != newVal) {
3570 mForceClearedSystemUiFlags = newVal;
3571 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003572 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003573 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003574 }
3575 if (changed) {
3576 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3577 }
3578 }
3579 }
3580 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003581 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003582 }
3583 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003584 }
3585 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3586 new InputEventReceiver.Factory() {
3587 @Override
3588 public InputEventReceiver createInputEventReceiver(
3589 InputChannel inputChannel, Looper looper) {
3590 return new HideNavInputEventReceiver(inputChannel, looper);
3591 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003592 };
3593
3594 @Override
3595 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003596 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3597 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003598 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003599
Dianne Hackborndf89e652011-10-06 22:35:11 -07003600 // Reset any bits in mForceClearingStatusBarVisibility that
3601 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003602 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003603 // Clear any bits in the new visibility that are currently being
3604 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003605 return visibility & ~mResettingSystemUiFlags
3606 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003607 }
3608
Craig Mautner69b08182012-09-05 13:07:13 -07003609 @Override
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003610 public void getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
3611 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003612 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003613 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3614 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003615
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003616 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3617 if (useOutsets) {
3618 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3619 if (outset > 0) {
3620 if (displayRotation == Surface.ROTATION_0) {
3621 outOutsets.bottom += outset;
3622 } else if (displayRotation == Surface.ROTATION_90) {
3623 outOutsets.right += outset;
3624 } else if (displayRotation == Surface.ROTATION_180) {
3625 outOutsets.top += outset;
3626 } else if (displayRotation == Surface.ROTATION_270) {
3627 outOutsets.left += outset;
3628 }
3629 }
3630 }
3631
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003632 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003633 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003634 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003635 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003636 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003637 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3638 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3639 } else {
3640 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3641 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3642 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003643 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3644 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003645 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003646 availRight - mStableFullscreenRight,
3647 availBottom - mStableFullscreenBottom);
3648 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003649 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003650 availRight - mStableRight, availBottom - mStableBottom);
3651 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003652 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003653 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003654 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003655 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003656 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003657 availRight - mCurRight, availBottom - mCurBottom);
3658 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003659 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003660 availRight - mCurRight, availBottom - mCurBottom);
3661 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003662
3663 outStableInsets.set(mStableLeft, mStableTop,
3664 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003665 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003666 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003667 outContentInsets.setEmpty();
3668 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003669 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003670
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003671 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3672 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3673 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3674 }
3675
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003676 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003677 @Override
3678 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003679 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003680 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003681 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3682 if (isDefaultDisplay) {
3683 switch (displayRotation) {
3684 case Surface.ROTATION_90:
3685 overscanLeft = mOverscanTop;
3686 overscanTop = mOverscanRight;
3687 overscanRight = mOverscanBottom;
3688 overscanBottom = mOverscanLeft;
3689 break;
3690 case Surface.ROTATION_180:
3691 overscanLeft = mOverscanRight;
3692 overscanTop = mOverscanBottom;
3693 overscanRight = mOverscanLeft;
3694 overscanBottom = mOverscanTop;
3695 break;
3696 case Surface.ROTATION_270:
3697 overscanLeft = mOverscanBottom;
3698 overscanTop = mOverscanLeft;
3699 overscanRight = mOverscanTop;
3700 overscanBottom = mOverscanRight;
3701 break;
3702 default:
3703 overscanLeft = mOverscanLeft;
3704 overscanTop = mOverscanTop;
3705 overscanRight = mOverscanRight;
3706 overscanBottom = mOverscanBottom;
3707 break;
3708 }
3709 } else {
3710 overscanLeft = 0;
3711 overscanTop = 0;
3712 overscanRight = 0;
3713 overscanBottom = 0;
3714 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003715 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3716 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3717 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3718 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003719 mSystemLeft = 0;
3720 mSystemTop = 0;
3721 mSystemRight = displayWidth;
3722 mSystemBottom = displayHeight;
3723 mUnrestrictedScreenLeft = overscanLeft;
3724 mUnrestrictedScreenTop = overscanTop;
3725 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3726 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3727 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3728 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003729 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3730 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003731 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003732 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003733 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003734 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003735 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003736 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003737 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003738 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003739 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003740 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003741
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003742 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3743 final Rect pf = mTmpParentFrame;
3744 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003745 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003746 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003747 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003748 pf.left = df.left = of.left = vf.left = mDockLeft;
3749 pf.top = df.top = of.top = vf.top = mDockTop;
3750 pf.right = df.right = of.right = vf.right = mDockRight;
3751 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003752 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003753
Craig Mautner69b08182012-09-05 13:07:13 -07003754 if (isDefaultDisplay) {
3755 // For purposes of putting out fake window up to steal focus, we will
3756 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003757 final int sysui = mLastSystemUiFlags;
3758 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003759 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003760 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003761 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3762 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3763 boolean navAllowedHidden = immersive || immersiveSticky;
3764 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003765 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3766 if (!isKeyguardShowing) {
3767 navTranslucent &= areTranslucentBarsAllowed();
3768 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003769
Craig Mautner69b08182012-09-05 13:07:13 -07003770 // When the navigation bar isn't visible, we put up a fake
3771 // input window to catch all touch events. This way we can
3772 // detect when the user presses anywhere to bring back the nav
3773 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003774 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003775 if (mInputConsumer != null) {
3776 mInputConsumer.dismiss();
3777 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003778 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003779 } else if (mInputConsumer == null) {
3780 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3781 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003782 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003783
Craig Mautner69b08182012-09-05 13:07:13 -07003784 // For purposes of positioning and showing the nav bar, if we have
3785 // decided that it can't be hidden (because of the screen aspect ratio),
3786 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003787 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003788
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003789 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003790 displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003791 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003792 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003793 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003794 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003795 if (updateSysUiVisibility) {
3796 updateSystemUiVisibilityLw();
3797 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003798 }
3799 }
3800
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003801 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3802 boolean isKeyguardShowing) {
3803 // decide where the status bar goes ahead of time
3804 if (mStatusBar != null) {
3805 // apply any navigation bar insets
3806 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3807 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3808 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3809 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3810 + mUnrestrictedScreenTop;
3811 vf.left = mStableLeft;
3812 vf.top = mStableTop;
3813 vf.right = mStableRight;
3814 vf.bottom = mStableBottom;
3815
3816 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3817
3818 // Let the status bar determine its size.
3819 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3820 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3821 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3822
3823 // For layout, the status bar is always at the top with our fixed height.
3824 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3825
3826 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3827 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003828 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003829 if (!isKeyguardShowing) {
3830 statusBarTranslucent &= areTranslucentBarsAllowed();
3831 }
3832
3833 // If the status bar is hidden, we don't want to cause
3834 // windows behind it to scroll.
3835 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3836 // Status bar may go away, so the screen area it occupies
3837 // is available to apps but just covering them when the
3838 // status bar is visible.
3839 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3840
3841 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3842 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3843 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3844 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3845
3846 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3847 String.format(
3848 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3849 mDockLeft, mDockTop, mDockRight, mDockBottom,
3850 mContentLeft, mContentTop, mContentRight, mContentBottom,
3851 mCurLeft, mCurTop, mCurRight, mCurBottom));
3852 }
3853 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
3854 && !statusBarTransient && !statusBarTranslucent
3855 && !mStatusBarController.wasRecentlyTranslucent()) {
3856 // If the opaque status bar is currently requested to be visible,
3857 // and not in the process of animating on or off, then
3858 // we can tell the app that it is covered by it.
3859 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3860 }
3861 if (mStatusBarController.checkHiddenLw()) {
3862 return true;
3863 }
3864 }
3865 return false;
3866 }
3867
3868 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003869 int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003870 boolean navTranslucent, boolean navAllowedHidden) {
3871 if (mNavigationBar != null) {
3872 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
3873 // Force the navigation bar to its appropriate place and
3874 // size. We need to do this directly, instead of relying on
3875 // it to bubble up from the nav bar, because this needs to
3876 // change atomically with screen rotations.
Jorim Jaggi737af722015-12-31 10:42:27 +01003877 mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003878 if (mNavigationBarOnBottom) {
3879 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
3880 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003881 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003882 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
3883 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
3884 if (transientNavBarShowing) {
3885 mNavigationBarController.setBarShowingLw(true);
3886 } else if (navVisible) {
3887 mNavigationBarController.setBarShowingLw(true);
3888 mDockBottom = mTmpNavigationFrame.top;
3889 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3890 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
3891 } else {
3892 // We currently want to hide the navigation UI.
3893 mNavigationBarController.setBarShowingLw(false);
3894 }
3895 if (navVisible && !navTranslucent && !navAllowedHidden
3896 && !mNavigationBar.isAnimatingLw()
3897 && !mNavigationBarController.wasRecentlyTranslucent()) {
3898 // If the opaque nav bar is currently requested to be visible,
3899 // and not in the process of animating on or off, then
3900 // we can tell the app that it is covered by it.
3901 mSystemBottom = mTmpNavigationFrame.top;
3902 }
3903 } else {
3904 // Landscape screen; nav bar goes to the right.
3905 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003906 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003907 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
3908 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
3909 if (transientNavBarShowing) {
3910 mNavigationBarController.setBarShowingLw(true);
3911 } else if (navVisible) {
3912 mNavigationBarController.setBarShowingLw(true);
3913 mDockRight = mTmpNavigationFrame.left;
3914 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3915 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
3916 } else {
3917 // We currently want to hide the navigation UI.
3918 mNavigationBarController.setBarShowingLw(false);
3919 }
3920 if (navVisible && !navTranslucent && !navAllowedHidden
3921 && !mNavigationBar.isAnimatingLw()
3922 && !mNavigationBarController.wasRecentlyTranslucent()) {
3923 // If the nav bar is currently requested to be visible,
3924 // and not in the process of animating on or off, then
3925 // we can tell the app that it is covered by it.
3926 mSystemRight = mTmpNavigationFrame.left;
3927 }
3928 }
3929 // Make sure the content and current rectangles are updated to
3930 // account for the restrictions from the navigation bar.
3931 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3932 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3933 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3934 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3935 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3936 // And compute the final frame.
3937 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
3938 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3939 mTmpNavigationFrame, mTmpNavigationFrame);
3940 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
3941 if (mNavigationBarController.checkHiddenLw()) {
3942 return true;
3943 }
3944 }
3945 return false;
3946 }
3947
Jorim Jaggi737af722015-12-31 10:42:27 +01003948 private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) {
3949 return !mNavigationBarCanMove || displayWidth < displayHeight;
3950 }
3951
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003952 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003953 @Override
John Spurlock46646232013-09-30 22:32:42 -04003954 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003955 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3956 return mStatusBar.getSurfaceLayer();
3957 }
3958
3959 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3960 return mNavigationBar.getSurfaceLayer();
3961 }
3962
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003963 return 0;
3964 }
3965
Craig Mautner967212c2013-04-13 21:10:58 -07003966 @Override
3967 public void getContentRectLw(Rect r) {
3968 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3969 }
3970
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003971 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3972 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003973 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3974 // Here's a special case: if this attached window is a panel that is
3975 // above the dock window, and the window it is attached to is below
3976 // the dock window, then the frames we computed for the window it is
3977 // attached to can not be used because the dock is effectively part
3978 // of the underlying window and the attached window is floating on top
3979 // of the whole thing. So, we ignore the attached window and explicitly
3980 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003981 df.left = of.left = cf.left = vf.left = mDockLeft;
3982 df.top = of.top = cf.top = vf.top = mDockTop;
3983 df.right = of.right = cf.right = vf.right = mDockRight;
3984 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003985 } else {
3986 // The effective display frame of the attached window depends on
3987 // whether it is taking care of insetting its content. If not,
3988 // we need to use the parent's content frame so that the entire
3989 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003990 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003991 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003992 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003993 // Set the content frame of the attached window to the parent's decor frame
3994 // (same as content frame when IME isn't present) if specifically requested by
3995 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3996 // Otherwise, use the overscan frame.
3997 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3998 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003999 } else {
4000 // If the window is resizing, then we want to base the content
4001 // frame on our attached content frame to resize... however,
4002 // things can be tricky if the attached window is NOT in resize
4003 // mode, in which case its content frame will be larger.
4004 // Ungh. So to deal with that, make sure the content frame
4005 // we end up using is not covering the IM dock.
4006 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004007 if (attached.isVoiceInteraction()) {
4008 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
4009 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
4010 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
4011 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
4012 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004013 if (cf.left < mContentLeft) cf.left = mContentLeft;
4014 if (cf.top < mContentTop) cf.top = mContentTop;
4015 if (cf.right > mContentRight) cf.right = mContentRight;
4016 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
4017 }
4018 }
4019 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004020 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004021 vf.set(attached.getVisibleFrameLw());
4022 }
4023 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
4024 // window should be positioned relative to its parent or the entire
4025 // screen.
4026 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
4027 ? attached.getFrameLw() : df);
4028 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004029
4030 private void applyStableConstraints(int sysui, int fl, Rect r) {
4031 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4032 // If app is requesting a stable layout, don't let the
4033 // content insets go below the stable values.
4034 if ((fl & FLAG_FULLSCREEN) != 0) {
4035 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
4036 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
4037 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
4038 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
4039 } else {
4040 if (r.left < mStableLeft) r.left = mStableLeft;
4041 if (r.top < mStableTop) r.top = mStableTop;
4042 if (r.right > mStableRight) r.right = mStableRight;
4043 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
4044 }
4045 }
4046 }
4047
Jorim Jaggiaa806142015-05-20 18:04:16 -07004048 private boolean canReceiveInput(WindowState win) {
4049 boolean notFocusable =
4050 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4051 boolean altFocusableIm =
4052 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4053 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4054 return !notFocusableForIm;
4055 }
4056
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004057 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004058 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004059 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004060 // We've already done the navigation bar and status bar. If the status bar can receive
4061 // input, we need to layout it again to accomodate for the IME window.
4062 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004063 return;
4064 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004065 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004066 final boolean isDefaultDisplay = win.isDefaultDisplay();
4067 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004068 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4069 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004070 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004071 offsetInputMethodWindowLw(mLastInputMethodWindow);
4072 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004073
John Spurlockc6d1c602014-01-17 15:22:06 -05004074 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004075 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004076 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004077
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004078 final Rect pf = mTmpParentFrame;
4079 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004080 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004081 final Rect cf = mTmpContentFrame;
4082 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004083 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004084 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004085 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004086 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004087
4088 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004089 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004090
Craig Mautnerf683b562012-10-02 11:10:57 -07004091 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4092
Adrian Roosfa104232014-06-20 16:10:14 -07004093 if (isDefaultDisplay) {
4094 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4095 } else {
4096 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4097 }
4098
Craig Mautner69b08182012-09-05 13:07:13 -07004099 if (!isDefaultDisplay) {
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);
Craig Mautner69b08182012-09-05 13:07:13 -07004104 } else {
4105 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004106 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4107 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4108 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004109 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004110 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004111 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004112 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004113 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004114 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4115 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4116 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004117 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004118 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004119 // ...with content insets above the nav bar
4120 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004121 // IM dock windows always go to the bottom of the screen.
4122 attrs.gravity = Gravity.BOTTOM;
4123 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004124 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004125 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004126 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004127 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4128 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004129 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004130 // Note: In Phone landscape mode, the button bar should also be excluded.
4131 cf.right = vf.right = mStableRight;
4132 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004133 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07004134 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004135 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4136 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4137 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4138 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4139 cf.left = vf.left = mStableLeft;
4140 cf.top = vf.top = mStableTop;
4141 cf.right = vf.right = mStableRight;
4142 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004143
4144 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4145 cf.bottom = mContentBottom;
4146 } else {
4147 cf.bottom = mDockBottom;
4148 vf.bottom = mContentBottom;
4149 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004150 } else {
John Spurlock46646232013-09-30 22:32:42 -04004151
4152 // Default policy decor for the default display
4153 dcf.left = mSystemLeft;
4154 dcf.top = mSystemTop;
4155 dcf.right = mSystemRight;
4156 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004157 final boolean inheritTranslucentDecor = (attrs.privateFlags
4158 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004159 final boolean isAppWindow =
4160 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4161 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4162 final boolean topAtRest =
4163 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4164 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004165 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4166 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004167 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4168 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004169 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
4170 && !mForceWindowDrawsStatusBarBackground) {
John Spurlock46646232013-09-30 22:32:42 -04004171 // Ensure policy decor includes status bar
4172 dcf.top = mStableTop;
4173 }
John Spurlockbd957402013-10-03 11:38:39 -04004174 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004175 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4176 && (fl & WindowManager.LayoutParams.
4177 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004178 // Ensure policy decor includes navigation bar
4179 dcf.bottom = mStableBottom;
4180 dcf.right = mStableRight;
4181 }
4182 }
4183
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004184 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4185 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004186 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004187 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004188 // This is the case for a normal activity window: we want it
4189 // to cover all of the screen space, and it can take care of
4190 // moving its contents to account for screen decorations that
4191 // intrude into that space.
4192 if (attached != null) {
4193 // If this window is attached to another, our display
4194 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004195 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004196 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004197 if (attrs.type == TYPE_STATUS_BAR_PANEL
4198 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004199 // Status bar panels are the only windows who can go on top of
4200 // the status bar. They are protected by the STATUS_BAR_SERVICE
4201 // permission, so they have the same privileges as the status
4202 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004203 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004204 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004205
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004206 pf.left = df.left = of.left = hasNavBar
4207 ? mDockLeft : mUnrestrictedScreenLeft;
4208 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4209 pf.right = df.right = of.right = hasNavBar
4210 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4211 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4212 pf.bottom = df.bottom = of.bottom = hasNavBar
4213 ? mRestrictedScreenTop+mRestrictedScreenHeight
4214 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004215
Craig Mautnereda67292013-04-28 13:50:14 -07004216 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004217 "Laying out status bar window: (%d,%d - %d,%d)",
4218 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004219 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004220 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4221 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4222 // Asking to layout into the overscan region, so give it that pure
4223 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004224 pf.left = df.left = of.left = mOverscanScreenLeft;
4225 pf.top = df.top = of.top = mOverscanScreenTop;
4226 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4227 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4228 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004229 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004230 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004231 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4232 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004233 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004234 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004235 // only do this for application windows to ensure no window that
4236 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004237 pf.left = df.left = mOverscanScreenLeft;
4238 pf.top = df.top = mOverscanScreenTop;
4239 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4240 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004241 // We need to tell the app about where the frame inside the overscan
4242 // is, so it can inset its content by that amount -- it didn't ask
4243 // to actually extend itself into the overscan region.
4244 of.left = mUnrestrictedScreenLeft;
4245 of.top = mUnrestrictedScreenTop;
4246 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4247 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004248 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004249 pf.left = df.left = mRestrictedOverscanScreenLeft;
4250 pf.top = df.top = mRestrictedOverscanScreenTop;
4251 pf.right = df.right = mRestrictedOverscanScreenLeft
4252 + mRestrictedOverscanScreenWidth;
4253 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4254 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004255 // We need to tell the app about where the frame inside the overscan
4256 // is, so it can inset its content by that amount -- it didn't ask
4257 // to actually extend itself into the overscan region.
4258 of.left = mUnrestrictedScreenLeft;
4259 of.top = mUnrestrictedScreenTop;
4260 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4261 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004262 }
Craig Mautner69b08182012-09-05 13:07:13 -07004263
John Spurlock46646232013-09-30 22:32:42 -04004264 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004265 if (win.isVoiceInteraction()) {
4266 cf.left = mVoiceContentLeft;
4267 cf.top = mVoiceContentTop;
4268 cf.right = mVoiceContentRight;
4269 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004270 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004271 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4272 cf.left = mDockLeft;
4273 cf.top = mDockTop;
4274 cf.right = mDockRight;
4275 cf.bottom = mDockBottom;
4276 } else {
4277 cf.left = mContentLeft;
4278 cf.top = mContentTop;
4279 cf.right = mContentRight;
4280 cf.bottom = mContentBottom;
4281 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004282 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004283 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004284 // Full screen windows are always given a layout that is as if the
4285 // status bar and other transient decors are gone. This is to avoid
4286 // bad states when moving from a window that is not hding the
4287 // status bar to one that is.
4288 cf.left = mRestrictedScreenLeft;
4289 cf.top = mRestrictedScreenTop;
4290 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4291 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004292 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004293 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004294 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4295 vf.left = mCurLeft;
4296 vf.top = mCurTop;
4297 vf.right = mCurRight;
4298 vf.bottom = mCurBottom;
4299 } else {
4300 vf.set(cf);
4301 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004302 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004303 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4304 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4305 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004306 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4307 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004308 // A window that has requested to fill the entire screen just
4309 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004310 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004311 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4312 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004313 pf.left = df.left = of.left = cf.left = hasNavBar
4314 ? mDockLeft : mUnrestrictedScreenLeft;
4315 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4316 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004317 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004318 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004319 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004320 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004321 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004322 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004323 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4324 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004325 } else if (attrs.type == TYPE_NAVIGATION_BAR
4326 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004327 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004328 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4329 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4330 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4331 + mUnrestrictedScreenWidth;
4332 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4333 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004334 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004335 "Laying out navigation bar window: (%d,%d - %d,%d)",
4336 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004337 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4338 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004339 && ((fl & FLAG_FULLSCREEN) != 0)) {
4340 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004341 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4342 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4343 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4344 + mOverscanScreenWidth;
4345 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4346 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004347 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004348 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004349 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4350 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4351 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4352 + mOverscanScreenWidth;
4353 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4354 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004355 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004356 // The wallpaper also has Real Ultimate Power, but we want to tell
4357 // it about the overscan area.
4358 pf.left = df.left = mOverscanScreenLeft;
4359 pf.top = df.top = mOverscanScreenTop;
4360 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4361 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4362 of.left = cf.left = mUnrestrictedScreenLeft;
4363 of.top = cf.top = mUnrestrictedScreenTop;
4364 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4365 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004366 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004367 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4368 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4369 // Asking to layout into the overscan region, so give it that pure
4370 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004371 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4372 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4373 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004374 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004375 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004376 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004377 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004378 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004379 && (attrs.type == TYPE_STATUS_BAR
4380 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01004381 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004382 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004383 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4384 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004385 // Asking for layout as if the nav bar is hidden, lets the
4386 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004387 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004388 // can be above the nav bar can do this.
4389 // XXX This assumes that an app asking for this will also
4390 // ask for layout in only content. We can't currently figure out
4391 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004392 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4393 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4394 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4395 + mUnrestrictedScreenWidth;
4396 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4397 + mUnrestrictedScreenHeight;
Jorim Jaggi9f6798a2016-02-10 22:16:06 -08004398 } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) {
4399 pf.left = df.left = of.left = mRestrictedScreenLeft;
4400 pf.top = df.top = of.top = mRestrictedScreenTop;
4401 pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4402 pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop
4403 + mRestrictedScreenHeight;
4404 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4405 cf.left = mDockLeft;
4406 cf.top = mDockTop;
4407 cf.right = mDockRight;
4408 cf.bottom = mDockBottom;
4409 } else {
4410 cf.left = mContentLeft;
4411 cf.top = mContentTop;
4412 cf.right = mContentRight;
4413 cf.bottom = mContentBottom;
4414 }
Joe Onorato29fc2c92010-11-24 10:26:50 -08004415 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004416 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4417 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4418 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4419 + mRestrictedScreenWidth;
4420 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4421 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004422 }
Craig Mautner69b08182012-09-05 13:07:13 -07004423
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004424 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004425
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004426 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4427 vf.left = mCurLeft;
4428 vf.top = mCurTop;
4429 vf.right = mCurRight;
4430 vf.bottom = mCurBottom;
4431 } else {
4432 vf.set(cf);
4433 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004434 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004435 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4436 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004437 // A child window should be placed inside of the same visible
4438 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004439 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004440 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004441 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4442 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004443 // Otherwise, a normal window must be placed inside the content
4444 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004445 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4446 // Status bar panels and the volume dialog are the only windows who can go on
4447 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004448 // permission, so they have the same privileges as the status
4449 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004450 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4451 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4452 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4453 + mRestrictedScreenWidth;
4454 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4455 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004456 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004457 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004458 pf.left = df.left = of.left = cf.left = mStableLeft;
4459 pf.top = df.top = of.top = cf.top = mStableTop;
4460 pf.right = df.right = of.right = cf.right = mStableRight;
4461 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004462 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004463 pf.left = mContentLeft;
4464 pf.top = mContentTop;
4465 pf.right = mContentRight;
4466 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004467 if (win.isVoiceInteraction()) {
4468 df.left = of.left = cf.left = mVoiceContentLeft;
4469 df.top = of.top = cf.top = mVoiceContentTop;
4470 df.right = of.right = cf.right = mVoiceContentRight;
4471 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4472 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004473 df.left = of.left = cf.left = mDockLeft;
4474 df.top = of.top = cf.top = mDockTop;
4475 df.right = of.right = cf.right = mDockRight;
4476 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004477 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004478 df.left = of.left = cf.left = mContentLeft;
4479 df.top = of.top = cf.top = mContentTop;
4480 df.right = of.right = cf.right = mContentRight;
4481 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004482 }
4483 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4484 vf.left = mCurLeft;
4485 vf.top = mCurTop;
4486 vf.right = mCurRight;
4487 vf.bottom = mCurBottom;
4488 } else {
4489 vf.set(cf);
4490 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004491 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004492 }
4493 }
Craig Mautner69b08182012-09-05 13:07:13 -07004494
Craig Mautnerb816bed2013-07-23 10:26:17 -07004495 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4496 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004497 df.left = df.top = -10000;
4498 df.right = df.bottom = 10000;
4499 if (attrs.type != TYPE_WALLPAPER) {
4500 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4501 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4502 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004503 }
4504
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004505 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4506 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004507 // We only want to apply outsets to certain types of windows. For example, we never want to
4508 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004509 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004510 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004511 osf = mTmpOutsetFrame;
4512 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4513 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4514 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004515 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004516 if (rotation == Surface.ROTATION_0) {
4517 osf.bottom += outset;
4518 } else if (rotation == Surface.ROTATION_90) {
4519 osf.right += outset;
4520 } else if (rotation == Surface.ROTATION_180) {
4521 osf.top -= outset;
4522 } else if (rotation == Surface.ROTATION_270) {
4523 osf.left -= outset;
4524 }
4525 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4526 + " with rotation " + rotation + ", result: " + osf);
4527 }
4528 }
4529
Craig Mautnereda67292013-04-28 13:50:14 -07004530 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004531 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004532 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004533 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004534 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004535 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004536 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004537 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004538 + " sf=" + sf.toShortString()
4539 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004540
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004541 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004542
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004543 // Dock windows carve out the bottom of the screen, so normal windows
4544 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004545 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4546 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004547 setLastInputMethodWindowLw(null, null);
4548 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004549 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004550 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4551 && !win.getGivenInsetsPendingLw()) {
4552 offsetVoiceInputWindowLw(win);
4553 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004554 }
4555
satok1bc0a492012-04-25 22:47:12 +09004556 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004557 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004558 top += win.getGivenContentInsetsLw().top;
4559 if (mContentBottom > top) {
4560 mContentBottom = top;
4561 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004562 if (mVoiceContentBottom > top) {
4563 mVoiceContentBottom = top;
4564 }
satok1bc0a492012-04-25 22:47:12 +09004565 top = win.getVisibleFrameLw().top;
4566 top += win.getGivenVisibleInsetsLw().top;
4567 if (mCurBottom > top) {
4568 mCurBottom = top;
4569 }
Craig Mautnereda67292013-04-28 13:50:14 -07004570 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004571 + mDockBottom + " mContentBottom="
4572 + mContentBottom + " mCurBottom=" + mCurBottom);
4573 }
4574
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004575 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004576 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004577 top += win.getGivenContentInsetsLw().top;
4578 if (mVoiceContentBottom > top) {
4579 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004580 }
4581 }
4582
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004583 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004584 @Override
4585 public void finishLayoutLw() {
4586 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004587 }
4588
4589 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004590 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004591 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004592 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004593 mTopFullscreenOpaqueOrDimmingWindowState = null;
Jorim Jaggi86905582016-02-09 21:36:09 -08004594 mTopDockedOpaqueWindowState = null;
4595 mTopDockedOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004596 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004597 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004598 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004599 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004600 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004601 mForcingShowNavBar = false;
4602 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004603
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004604 mHideLockScreen = false;
4605 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004606 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004607 mShowingLockscreen = false;
4608 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004609 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004610 mKeyguardSecure = isKeyguardSecure();
4611 mKeyguardSecureIncludingHidden = mKeyguardSecure
4612 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004613 }
4614
4615 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004616 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004617 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4618 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004619 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4620 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004621 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004622 if (mTopFullscreenOpaqueWindowState == null
4623 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4624 mForcingShowNavBar = true;
4625 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004626 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004627 if (attrs.type == TYPE_STATUS_BAR) {
4628 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4629 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004630 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004631 }
4632 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4633 mForceStatusBarTransparent = true;
4634 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004635 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004636
4637 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4638 && attrs.type < FIRST_SYSTEM_WINDOW;
4639 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4640 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Jorim Jaggi86905582016-02-09 21:36:09 -08004641 final int stackId = win.getStackId();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004642 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004643 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004644 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004645 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004646 mForceStatusBarFromKeyguard = true;
4647 } else {
4648 mForceStatusBar = true;
4649 }
4650 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004651 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004652 // If the lockscreen was showing when the dream started then wait
4653 // for the dream to draw before hiding the lockscreen.
4654 if (!mDreamingLockscreen
4655 || (win.isVisibleLw() && win.hasDrawnLw())) {
4656 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004657 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004658 }
4659 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004660
Yohei Yukawad1a09222015-06-30 16:22:05 -07004661 final IApplicationToken appToken = win.getAppToken();
4662
4663 // For app windows that are not attached, we decide if all windows in the app they
4664 // represent should be hidden or if we should hide the lockscreen. For attached app
4665 // windows we defer the decision to the window it is attached to.
4666 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004667 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004668 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004669 mAppsToBeHidden.remove(appToken);
4670 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004671 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004672 if (dismissKeyguard && !mKeyguardSecure) {
4673 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004674 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004675 mWinShowWhenLocked = win;
4676 mHideLockScreen = true;
4677 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004678 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004679 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004680 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004681 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004682 mAppsToBeHidden.add(appToken);
4683 } else {
4684 mAppsToBeHidden.remove(appToken);
4685 }
4686 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004687 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004688 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004689 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004690 if (isFullscreen(attrs) && StackId.normallyFullscreenWindows(stackId)) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004691 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4692 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004693 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4694 mTopFullscreenOpaqueOrDimmingWindowState = win;
4695 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004696 if (!mAppsThatDismissKeyguard.isEmpty() &&
4697 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4698 if (DEBUG_LAYOUT) Slog.v(TAG,
4699 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004700 mDismissKeyguard = (mWinDismissingKeyguard == win
4701 && mSecureDismissingKeyguard == mKeyguardSecure)
4702 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004703 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004704 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004705 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004706 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4707 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004708 if (DEBUG_LAYOUT) Slog.v(TAG,
4709 "Setting mHideLockScreen to true by win " + win);
4710 mHideLockScreen = true;
4711 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004712 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004713 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004714 mAllowLockscreenWhenOn = true;
4715 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004716 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004717
4718 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004719 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4720 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004721 win.hideLw(false);
4722 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004723 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004724 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4725 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4726 // that is being hidden in an animation - keep the
4727 // keyguard hidden until the new window shows up and
4728 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004729 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004730 mHideLockScreen = true;
4731 mWinShowWhenLocked = win;
4732 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004733 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004734
4735 // Keep track of the window if it's dimming but not necessarily fullscreen.
4736 final boolean reallyVisible = win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw();
4737 if (mTopFullscreenOpaqueOrDimmingWindowState == null && reallyVisible
4738 && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01004739 mTopFullscreenOpaqueOrDimmingWindowState = win;
4740 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004741
4742 // We need to keep track of the top "fullscreen" opaque window for the docked stack
4743 // separately, because both the "real fullscreen" opaque window and the one for the docked
4744 // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.
4745 if (mTopDockedOpaqueWindowState == null && reallyVisible && appWindow && attached == null
4746 && isFullscreen(attrs) && stackId == DOCKED_STACK_ID) {
4747 mTopDockedOpaqueWindowState = win;
4748 if (mTopDockedOpaqueOrDimmingWindowState == null) {
4749 mTopDockedOpaqueOrDimmingWindowState = win;
4750 }
4751 }
4752
4753 // Also keep track of any windows that are dimming but not necessarily fullscreen in the
4754 // docked stack.
4755 if (mTopDockedOpaqueOrDimmingWindowState == null && reallyVisible && win.isDimming()
4756 && stackId == DOCKED_STACK_ID) {
4757 mTopDockedOpaqueOrDimmingWindowState = win;
4758 }
4759 }
4760
4761 private boolean isFullscreen(WindowManager.LayoutParams attrs) {
4762 return attrs.x == 0 && attrs.y == 0
4763 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4764 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004765 }
4766
4767 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004768 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004769 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004770 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4771 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4772 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004773 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4774 // fullscreen window.
4775 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4776 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4777 mTopFullscreenOpaqueWindowState.hideLw(false);
4778 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4779 }
4780
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004781 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004782 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004783
4784 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4785 ? mTopFullscreenOpaqueWindowState.getAttrs()
4786 : null;
4787
Jeff Brownc8018eb2012-10-29 21:33:27 -07004788 // If we are not currently showing a dream then remember the current
4789 // lockscreen state. We will use this to determine whether the dream
4790 // started while the lockscreen was showing and remember this state
4791 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004792 if (!mShowingDream) {
4793 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004794 if (mDreamingSleepTokenNeeded) {
4795 mDreamingSleepTokenNeeded = false;
4796 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4797 }
4798 } else {
4799 if (!mDreamingSleepTokenNeeded) {
4800 mDreamingSleepTokenNeeded = true;
4801 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4802 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004803 }
4804
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004805 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004806 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004807 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004808 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004809 boolean shouldBeTransparent = mForceStatusBarTransparent
4810 && !mForceStatusBar
4811 && !mForceStatusBarFromKeyguard;
4812 if (!shouldBeTransparent) {
4813 mStatusBarController.setShowTransparent(false /* transparent */);
4814 } else if (!mStatusBar.isVisibleLw()) {
4815 mStatusBarController.setShowTransparent(true /* transparent */);
4816 }
4817 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004818 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004819 if (mStatusBarController.setBarShowingLw(true)) {
4820 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4821 }
Craig Mautner81defc72013-10-29 11:10:42 -07004822 // Maintain fullscreen layout until incoming animation is complete.
4823 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004824 // Transient status bar on the lockscreen is not allowed
4825 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4826 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4827 mLastSystemUiFlags, mLastSystemUiFlags);
4828 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004829 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004830 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004831 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004832 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004833 + " shown position: "
4834 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004835 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004836 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004837 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004838 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004839 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004840 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004841 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004842 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4843 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004844 if (mStatusBarController.isTransientShowing()) {
4845 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004846 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4847 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07004848 } else if (topIsFullscreen
4849 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
4850 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07004851 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004852 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004853 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004854 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004855 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004856 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004857 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004858 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004859 if (mStatusBarController.setBarShowingLw(true)) {
4860 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4861 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004862 }
4863 }
4864 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004865
Craig Mautner81defc72013-10-29 11:10:42 -07004866 if (mTopIsFullscreen != topIsFullscreen) {
4867 if (!topIsFullscreen) {
4868 // Force another layout when status bar becomes fully shown.
4869 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4870 }
4871 mTopIsFullscreen = topIsFullscreen;
4872 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004873
Craig Mautner39834192012-09-02 07:47:24 -07004874 // Hide the key guard if a visible window explicitly specifies that it wants to be
4875 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004876 if (mKeyguardDelegate != null && mStatusBar != null) {
4877 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4878 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004879 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004880 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004881 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004882 changes |= FINISH_LAYOUT_REDO_LAYOUT
4883 | FINISH_LAYOUT_REDO_CONFIG
4884 | FINISH_LAYOUT_REDO_WALLPAPER;
4885 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004886 if (mKeyguardDelegate.isShowing()) {
4887 mHandler.post(new Runnable() {
4888 @Override
4889 public void run() {
4890 mKeyguardDelegate.keyguardDone(false, false);
4891 }
4892 });
4893 }
4894 } else if (mHideLockScreen) {
4895 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004896 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004897 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004898 changes |= FINISH_LAYOUT_REDO_LAYOUT
4899 | FINISH_LAYOUT_REDO_CONFIG
4900 | FINISH_LAYOUT_REDO_WALLPAPER;
4901 }
4902 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004903 mKeyguardHidden = false;
4904 if (setKeyguardOccludedLw(false)) {
4905 changes |= FINISH_LAYOUT_REDO_LAYOUT
4906 | FINISH_LAYOUT_REDO_CONFIG
4907 | FINISH_LAYOUT_REDO_WALLPAPER;
4908 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004909 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4910 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004911 mHandler.post(new Runnable() {
4912 @Override
4913 public void run() {
4914 mKeyguardDelegate.dismiss();
4915 }
4916 });
4917 }
4918 } else {
4919 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004920 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004921 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004922 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004923 changes |= FINISH_LAYOUT_REDO_LAYOUT
4924 | FINISH_LAYOUT_REDO_CONFIG
4925 | FINISH_LAYOUT_REDO_WALLPAPER;
4926 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004927 }
4928 }
Joe Onorato664644d2011-01-23 17:53:23 -08004929
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004930 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004931 // If the navigation bar has been hidden or shown, we need to do another
4932 // layout pass to update that window.
4933 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4934 }
Joe Onorato664644d2011-01-23 17:53:23 -08004935
Mike Lockwood28569302010-01-28 11:54:40 -05004936 // update since mAllowLockscreenWhenOn might have changed
4937 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004938 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004939 }
4940
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004941 /**
Jim Millerab954542014-10-10 18:21:49 -07004942 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004943 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004944 * @return Whether the flags have changed and we have to redo the layout.
4945 */
Jim Millerab954542014-10-10 18:21:49 -07004946 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4947 boolean wasOccluded = mKeyguardOccluded;
4948 boolean showing = mKeyguardDelegate.isShowing();
4949 if (wasOccluded && !isOccluded && showing) {
4950 mKeyguardOccluded = false;
4951 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004952 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4953 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4954 return true;
Jim Millerab954542014-10-10 18:21:49 -07004955 } else if (!wasOccluded && isOccluded && showing) {
4956 mKeyguardOccluded = true;
4957 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004958 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4959 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4960 return true;
4961 } else {
4962 return false;
4963 }
4964 }
4965
4966 private boolean isStatusBarKeyguard() {
4967 return mStatusBar != null
4968 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4969 }
4970
Jose Lima9546b202014-07-02 17:21:51 -07004971 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004972 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004973 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004974 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004975 return false;
4976 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004977 return true;
4978 }
4979
Jose Lima9546b202014-07-02 17:21:51 -07004980 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004981 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004982 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004983 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004984 // If the navigation bar has been hidden or shown, we need to do another
4985 // layout pass to update that window.
4986 return FINISH_LAYOUT_REDO_LAYOUT;
4987 }
4988 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004989 }
4990
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004991 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004992 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004993 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4994 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004995 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4996 if (newLidState == mLidState) {
4997 return;
4998 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004999
Jeff Brownc458ce92012-04-30 14:58:40 -07005000 mLidState = newLidState;
5001 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005002 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07005003
5004 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005005 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
5006 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07005007 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07005008 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005009 }
5010 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005011
Michael Wright3818c922014-09-02 13:59:07 -07005012 @Override
5013 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
5014 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
5015 if (mCameraLensCoverState == lensCoverState) {
5016 return;
5017 }
5018 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
5019 lensCoverState == CAMERA_LENS_UNCOVERED) {
5020 Intent intent;
5021 final boolean keyguardActive = mKeyguardDelegate == null ? false :
5022 mKeyguardDelegate.isShowing();
5023 if (keyguardActive) {
5024 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
5025 } else {
5026 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
5027 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005028 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
5029 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00005030 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07005031 }
5032 mCameraLensCoverState = lensCoverState;
5033 }
5034
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005035 void setHdmiPlugged(boolean plugged) {
5036 if (mHdmiPlugged != plugged) {
5037 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005038 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005039 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08005040 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005041 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07005042 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005043 }
5044 }
5045
Joe Onoratoea495d42011-04-06 11:41:11 -07005046 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07005047 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07005048 // watch for HDMI plug messages if the hdmi switch exists
5049 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
5050 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
5051
Joe Onoratoea495d42011-04-06 11:41:11 -07005052 final String filename = "/sys/class/switch/hdmi/state";
5053 FileReader reader = null;
5054 try {
5055 reader = new FileReader(filename);
5056 char[] buf = new char[15];
5057 int n = reader.read(buf);
5058 if (n > 1) {
5059 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
5060 }
5061 } catch (IOException ex) {
5062 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5063 } catch (NumberFormatException ex) {
5064 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5065 } finally {
5066 if (reader != null) {
5067 try {
5068 reader.close();
5069 } catch (IOException ex) {
5070 }
Joe Onoratodc100302011-01-11 17:07:41 -08005071 }
5072 }
5073 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07005074 // This dance forces the code in setHdmiPlugged to run.
5075 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
5076 mHdmiPlugged = !plugged;
5077 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08005078 }
5079
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07005080 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005081 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005082
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005083 final Runnable mScreenshotTimeout = new Runnable() {
5084 @Override public void run() {
5085 synchronized (mScreenshotLock) {
5086 if (mScreenshotConnection != null) {
5087 mContext.unbindService(mScreenshotConnection);
5088 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005089 }
Winson Chung9112ec32011-06-27 13:15:32 -07005090 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005091 }
5092 };
5093
5094 // Assume this is called from the Handler thread.
5095 private void takeScreenshot() {
5096 synchronized (mScreenshotLock) {
5097 if (mScreenshotConnection != null) {
5098 return;
5099 }
5100 ComponentName cn = new ComponentName("com.android.systemui",
5101 "com.android.systemui.screenshot.TakeScreenshotService");
5102 Intent intent = new Intent();
5103 intent.setComponent(cn);
5104 ServiceConnection conn = new ServiceConnection() {
5105 @Override
5106 public void onServiceConnected(ComponentName name, IBinder service) {
5107 synchronized (mScreenshotLock) {
5108 if (mScreenshotConnection != this) {
5109 return;
5110 }
5111 Messenger messenger = new Messenger(service);
5112 Message msg = Message.obtain(null, 1);
5113 final ServiceConnection myConn = this;
5114 Handler h = new Handler(mHandler.getLooper()) {
5115 @Override
5116 public void handleMessage(Message msg) {
5117 synchronized (mScreenshotLock) {
5118 if (mScreenshotConnection == myConn) {
5119 mContext.unbindService(mScreenshotConnection);
5120 mScreenshotConnection = null;
5121 mHandler.removeCallbacks(mScreenshotTimeout);
5122 }
5123 }
5124 }
5125 };
5126 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005127 msg.arg1 = msg.arg2 = 0;
5128 if (mStatusBar != null && mStatusBar.isVisibleLw())
5129 msg.arg1 = 1;
5130 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5131 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005132 try {
5133 messenger.send(msg);
5134 } catch (RemoteException e) {
5135 }
5136 }
5137 }
5138 @Override
5139 public void onServiceDisconnected(ComponentName name) {}
5140 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08005141 if (mContext.bindServiceAsUser(
5142 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005143 mScreenshotConnection = conn;
5144 mHandler.postDelayed(mScreenshotTimeout, 10000);
5145 }
5146 }
Winson Chung9112ec32011-06-27 13:15:32 -07005147 }
5148
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005149 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005150 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005151 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005152 if (!mSystemBooted) {
5153 // If we have not yet booted, don't let key events do anything.
5154 return 0;
5155 }
5156
Jeff Brown037c33e2014-04-09 00:31:55 -07005157 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005158 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5159 final boolean canceled = event.isCanceled();
5160 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005161
Jeff Brown3122e442010-10-11 23:32:49 -07005162 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005163
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005164 // If screen is off then we treat the case where the keyguard is open but hidden
5165 // the same as if it were open and in front.
5166 // This will prevent any keys other than the power button from waking the screen
5167 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005168 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005169 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005170 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005171 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005172
Jeff Brown40013652012-05-16 21:22:36 -07005173 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005174 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005175 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005176 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005177 }
5178
Jeff Brown037c33e2014-04-09 00:31:55 -07005179 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005180 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005181 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5182 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005183 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005184 // When the device is interactive or the key is injected pass the
5185 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005186 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005187 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07005188 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
5189 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5190 // to the application but preserve its wake key status to make sure we still move
5191 // from dozing to fully interactive if we would normally go from off to fully
5192 // interactive.
5193 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07005194 } else {
5195 // When the screen is off and the key is not injected, determine whether
5196 // to wake the device but don't pass the key to the application.
5197 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005198 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5199 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005200 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005201 }
5202
Justin Kohd378ad72013-04-01 12:18:26 -07005203 // If the key would be handled globally, just return the result, don't worry about special
5204 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005205 if (isValidGlobalKey(keyCode)
5206 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005207 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005208 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005209 }
Justin Kohd378ad72013-04-01 12:18:26 -07005210 return result;
5211 }
5212
Jeff Brownbae8e772014-06-12 19:59:45 -07005213 boolean useHapticFeedback = down
5214 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5215 && event.getRepeatCount() == 0;
5216
Jeff Brown4d396052010-10-29 21:50:21 -07005217 // Handle special keys.
5218 switch (keyCode) {
5219 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005220 case KeyEvent.KEYCODE_VOLUME_UP:
5221 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005222 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5223 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005224 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005225 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005226 mScreenshotChordVolumeDownKeyTriggered = true;
5227 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5228 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005229 cancelPendingPowerKeyAction();
5230 interceptScreenshotChord();
5231 }
5232 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005233 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005234 cancelPendingScreenshotChordAction();
5235 }
5236 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5237 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005238 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005239 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005240 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005241 cancelPendingPowerKeyAction();
5242 cancelPendingScreenshotChordAction();
5243 }
5244 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005245 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005246 cancelPendingScreenshotChordAction();
5247 }
5248 }
Jeff Brown4d396052010-10-29 21:50:21 -07005249 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005250 TelecomManager telecomManager = getTelecommService();
5251 if (telecomManager != null) {
5252 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005253 // If an incoming call is ringing, either VOLUME key means
5254 // "silence ringer". We handle these keys here, rather than
5255 // in the InCallScreen, to make sure we'll respond to them
5256 // even if the InCallScreen hasn't come to the foreground yet.
5257 // Look for the DOWN event here, to agree with the "fallback"
5258 // behavior in the InCallScreen.
5259 Log.i(TAG, "interceptKeyBeforeQueueing:"
5260 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005261
Santos Cordon6848f722014-05-21 15:22:12 -07005262 // Silence the ringer. (It's safe to call this
5263 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005264 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005265
Santos Cordon6848f722014-05-21 15:22:12 -07005266 // And *don't* pass this key thru to the current activity
5267 // (which is probably the InCallScreen.)
5268 result &= ~ACTION_PASS_TO_USER;
5269 break;
5270 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005271 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005272 && (result & ACTION_PASS_TO_USER) == 0) {
5273 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005274 // the application, just pass it to the session service.
5275
5276 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005277 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005278 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005279 }
5280 }
Jaewan Kim765487f2016-01-12 14:45:42 +09005281 }
5282 if (mUseTvRouting) {
5283 // On TVs, defer special key handlings to
5284 // {@link interceptKeyBeforeDispatching()}.
5285 result |= ACTION_PASS_TO_USER;
5286 } else if ((result & ACTION_PASS_TO_USER) == 0) {
5287 // If we aren't passing to the user and no one else
5288 // handled it send it to the session manager to
5289 // figure out.
5290 MediaSessionLegacyHelper.getHelper(mContext)
5291 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07005292 }
5293 break;
5294 }
5295
5296 case KeyEvent.KEYCODE_ENDCALL: {
5297 result &= ~ACTION_PASS_TO_USER;
5298 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005299 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005300 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005301 if (telecomManager != null) {
5302 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005303 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005304 if (interactive && !hungUp) {
5305 mEndCallKeyHandled = false;
5306 mHandler.postDelayed(mEndCallLongPress,
5307 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5308 } else {
5309 mEndCallKeyHandled = true;
5310 }
Jeff Brown4d396052010-10-29 21:50:21 -07005311 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005312 if (!mEndCallKeyHandled) {
5313 mHandler.removeCallbacks(mEndCallLongPress);
5314 if (!canceled) {
5315 if ((mEndcallBehavior
5316 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5317 if (goHome()) {
5318 break;
5319 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005320 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005321 if ((mEndcallBehavior
5322 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5323 mPowerManager.goToSleep(event.getEventTime(),
5324 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5325 isWakeKey = false;
5326 }
Jeff Brown4d396052010-10-29 21:50:21 -07005327 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005328 }
Jeff Brown4d396052010-10-29 21:50:21 -07005329 }
5330 break;
5331 }
5332
5333 case KeyEvent.KEYCODE_POWER: {
5334 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005335 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005336 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005337 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005338 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005339 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005340 }
5341 break;
5342 }
5343
Jeff Brown6212a492014-03-07 13:58:47 -08005344 case KeyEvent.KEYCODE_SLEEP: {
5345 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005346 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005347 if (!mPowerManager.isInteractive()) {
5348 useHapticFeedback = false; // suppress feedback if already non-interactive
5349 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005350 if (down) {
5351 sleepPress(event.getEventTime());
5352 } else {
5353 sleepRelease(event.getEventTime());
5354 }
Jeff Brown6212a492014-03-07 13:58:47 -08005355 break;
5356 }
5357
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005358 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5359 result &= ~ACTION_PASS_TO_USER;
5360 isWakeKey = false;
5361 if (!down) {
5362 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5363 }
5364 break;
5365 }
5366
Jeff Brown6212a492014-03-07 13:58:47 -08005367 case KeyEvent.KEYCODE_WAKEUP: {
5368 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005369 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005370 break;
5371 }
5372
Jeff Brown4d396052010-10-29 21:50:21 -07005373 case KeyEvent.KEYCODE_MEDIA_PLAY:
5374 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5375 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005376 case KeyEvent.KEYCODE_HEADSETHOOK:
5377 case KeyEvent.KEYCODE_MUTE:
5378 case KeyEvent.KEYCODE_MEDIA_STOP:
5379 case KeyEvent.KEYCODE_MEDIA_NEXT:
5380 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5381 case KeyEvent.KEYCODE_MEDIA_REWIND:
5382 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005383 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5384 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005385 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5386 // If the global session is active pass all media keys to it
5387 // instead of the active window.
5388 result &= ~ACTION_PASS_TO_USER;
5389 }
Jeff Brown4d396052010-10-29 21:50:21 -07005390 if ((result & ACTION_PASS_TO_USER) == 0) {
5391 // Only do this if we would otherwise not pass it to the user. In that
5392 // case, the PhoneWindow class will do the same thing, except it will
5393 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005394 // Note that we need to make a copy of the key event here because the
5395 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005396 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005397 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5398 new KeyEvent(event));
5399 msg.setAsynchronous(true);
5400 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005401 }
5402 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005403 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005404
Jeff Brown4d396052010-10-29 21:50:21 -07005405 case KeyEvent.KEYCODE_CALL: {
5406 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005407 TelecomManager telecomManager = getTelecommService();
5408 if (telecomManager != null) {
5409 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005410 Log.i(TAG, "interceptKeyBeforeQueueing:"
5411 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005412 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005413
Santos Cordon6848f722014-05-21 15:22:12 -07005414 // And *don't* pass this key thru to the current activity
5415 // (which is presumably the InCallScreen.)
5416 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005417 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005418 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005419 }
Jeff Brown4d396052010-10-29 21:50:21 -07005420 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005421 }
Michael Wright869a67c2014-08-26 19:33:06 -07005422 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5423 // Only do this if we would otherwise not pass it to the user. In that case,
5424 // interceptKeyBeforeDispatching would apply a similar but different policy in
5425 // order to invoke voice assist actions. Note that we need to make a copy of the
5426 // key event here because the original key event will be recycled when we return.
5427 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5428 mBroadcastWakeLock.acquire();
5429 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5430 keyguardActive ? 1 : 0, 0);
5431 msg.setAsynchronous(true);
5432 msg.sendToTarget();
5433 }
Jaewan Kim49117872016-01-19 17:24:08 +09005434 break;
5435 }
5436 case KeyEvent.KEYCODE_WINDOW: {
5437 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
5438 if (!down) {
Jaewan Kimc552b042016-01-18 16:08:45 +09005439 requestTvPictureInPicture(event);
Jaewan Kim49117872016-01-19 17:24:08 +09005440 }
5441 result &= ~ACTION_PASS_TO_USER;
5442 }
5443 break;
Michael Wright869a67c2014-08-26 19:33:06 -07005444 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005445 }
Jeff Brown26875502014-01-30 21:47:47 -08005446
Jeff Brownbae8e772014-06-12 19:59:45 -07005447 if (useHapticFeedback) {
5448 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5449 }
5450
Jeff Brown26875502014-01-30 21:47:47 -08005451 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005452 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005453 }
Bryce Lee584a4452014-10-21 15:55:55 -07005454
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005455 return result;
5456 }
5457
Jeff Brown1c2e4942012-11-06 16:32:01 -08005458 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005459 * Returns true if the key can have global actions attached to it.
5460 * We reserve all power management keys for the system since they require
5461 * very careful handling.
5462 */
5463 private static boolean isValidGlobalKey(int keyCode) {
5464 switch (keyCode) {
5465 case KeyEvent.KEYCODE_POWER:
5466 case KeyEvent.KEYCODE_WAKEUP:
5467 case KeyEvent.KEYCODE_SLEEP:
5468 return false;
5469 default:
5470 return true;
5471 }
5472 }
5473
5474 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005475 * When the screen is off we ignore some keys that might otherwise typically
5476 * be considered wake keys. We filter them out here.
5477 *
5478 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5479 * is always considered a wake key.
5480 */
5481 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5482 switch (keyCode) {
5483 // ignore volume keys unless docked
5484 case KeyEvent.KEYCODE_VOLUME_UP:
5485 case KeyEvent.KEYCODE_VOLUME_DOWN:
5486 case KeyEvent.KEYCODE_VOLUME_MUTE:
5487 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5488
5489 // ignore media and camera keys
5490 case KeyEvent.KEYCODE_MUTE:
5491 case KeyEvent.KEYCODE_HEADSETHOOK:
5492 case KeyEvent.KEYCODE_MEDIA_PLAY:
5493 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5494 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5495 case KeyEvent.KEYCODE_MEDIA_STOP:
5496 case KeyEvent.KEYCODE_MEDIA_NEXT:
5497 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5498 case KeyEvent.KEYCODE_MEDIA_REWIND:
5499 case KeyEvent.KEYCODE_MEDIA_RECORD:
5500 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005501 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005502 case KeyEvent.KEYCODE_CAMERA:
5503 return false;
5504 }
5505 return true;
5506 }
5507
5508
Jeff Brown56194eb2011-03-02 19:23:13 -08005509 /** {@inheritDoc} */
5510 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005511 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5512 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005513 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5514 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005515 return 0;
5516 }
Michael Wright70af00a2014-09-03 19:30:20 -07005517 }
Bryce Lee5c138322014-11-03 08:26:09 -08005518
Michael Wright70af00a2014-09-03 19:30:20 -07005519 if (shouldDispatchInputWhenNonInteractive()) {
5520 return ACTION_PASS_TO_USER;
5521 }
Bryce Lee5c138322014-11-03 08:26:09 -08005522
Bryce Lee812d7022014-11-10 13:33:28 -08005523 // If we have not passed the action up and we are in theater mode without dreaming,
5524 // there will be no dream to intercept the touch and wake into ambient. The device should
5525 // wake up in this case.
5526 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005527 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5528 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005529 }
5530
Jeff Brown037c33e2014-04-09 00:31:55 -07005531 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005532 }
5533
Michael Wright70af00a2014-09-03 19:30:20 -07005534 private boolean shouldDispatchInputWhenNonInteractive() {
Joe LaPennaf2b9b2d2015-11-17 22:22:37 +00005535 // Send events to keyguard while the screen is on.
5536 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5537 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005538 return true;
5539 }
5540
5541 // Send events to a dozing dream even if the screen is off since the dream
5542 // is in control of the state of the screen.
5543 IDreamManager dreamManager = getDreamManager();
5544
5545 try {
5546 if (dreamManager != null && dreamManager.isDreaming()) {
5547 return true;
5548 }
5549 } catch (RemoteException e) {
5550 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5551 }
5552
5553 // Otherwise, consume events since the user can't see what is being
5554 // interacted with.
5555 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005556 }
5557
RoboErik001c59c2015-01-26 15:53:51 -08005558 private void dispatchDirectAudioEvent(KeyEvent event) {
5559 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5560 return;
5561 }
5562 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005563 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5564 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005565 String pkgName = mContext.getOpPackageName();
5566 switch (keyCode) {
5567 case KeyEvent.KEYCODE_VOLUME_UP:
5568 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005569 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005570 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005571 } catch (RemoteException e) {
5572 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5573 }
5574 break;
5575 case KeyEvent.KEYCODE_VOLUME_DOWN:
5576 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005577 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005578 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005579 } catch (RemoteException e) {
5580 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5581 }
5582 break;
5583 case KeyEvent.KEYCODE_VOLUME_MUTE:
5584 try {
5585 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005586 getAudioService().adjustSuggestedStreamVolume(
5587 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005588 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005589 }
5590 } catch (RemoteException e) {
5591 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5592 }
5593 break;
5594 }
5595 }
5596
Jeff Brown40013652012-05-16 21:22:36 -07005597 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5598 if (DEBUG_INPUT) {
5599 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005600 }
5601
Jeff Brown40013652012-05-16 21:22:36 -07005602 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5603 if (DEBUG_INPUT) {
5604 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5605 }
5606
5607 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5608 mHavePendingMediaKeyRepeatWithWakeLock = false;
5609 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5610 }
5611
5612 dispatchMediaKeyWithWakeLockToAudioService(event);
5613
5614 if (event.getAction() == KeyEvent.ACTION_DOWN
5615 && event.getRepeatCount() == 0) {
5616 mHavePendingMediaKeyRepeatWithWakeLock = true;
5617
5618 Message msg = mHandler.obtainMessage(
5619 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5620 msg.setAsynchronous(true);
5621 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5622 } else {
5623 mBroadcastWakeLock.release();
5624 }
5625 }
5626
5627 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5628 mHavePendingMediaKeyRepeatWithWakeLock = false;
5629
5630 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5631 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5632 if (DEBUG_INPUT) {
5633 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5634 }
5635
5636 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5637 mBroadcastWakeLock.release();
5638 }
5639
5640 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5641 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005642 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005643 }
5644 }
5645
Michael Wright869a67c2014-08-26 19:33:06 -07005646 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005647 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5648 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5649 if (dic != null) {
5650 try {
5651 dic.exitIdle("voice-search");
5652 } catch (RemoteException e) {
5653 }
5654 }
Michael Wright869a67c2014-08-26 19:33:06 -07005655 Intent voiceIntent =
5656 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5657 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005658 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005659 mBroadcastWakeLock.release();
5660 }
5661
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005662 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005663 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005664 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005665 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5666 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5667 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005668 } else {
5669 try {
5670 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5671 ServiceManager.getService(Context.UI_MODE_SERVICE));
5672 mUiMode = uiModeService.getCurrentModeType();
5673 } catch (RemoteException e) {
5674 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005675 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005676 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005677 synchronized (mLock) {
5678 updateOrientationListenerLp();
5679 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005680 }
5681 };
5682
Jeff Brown6aaf2952012-10-05 16:01:08 -07005683 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5684 @Override
5685 public void onReceive(Context context, Intent intent) {
5686 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005687 if (mKeyguardDelegate != null) {
5688 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005689 }
5690 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005691 if (mKeyguardDelegate != null) {
5692 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005693 }
5694 }
5695 }
5696 };
5697
Christopher Tate5e08af02012-09-21 17:17:22 -07005698 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5699 @Override
5700 public void onReceive(Context context, Intent intent) {
5701 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5702 // tickle the settings observer: this first ensures that we're
5703 // observing the relevant settings for the newly-active user,
5704 // and then updates our own bookkeeping based on the now-
5705 // current user.
5706 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005707
5708 // force a re-application of focused window sysui visibility.
5709 // the window may never have been shown for this user
5710 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005711 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005712 mLastSystemUiFlags = 0;
5713 updateSystemUiVisibilityLw();
5714 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005715 }
5716 }
5717 };
5718
Adrian Roosddc8b272015-05-21 16:28:27 -07005719 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005720 @Override
5721 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005722 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5723 if (!isUserSetupComplete()) {
5724 // Swipe-up for navigation bar is disabled during setup
5725 return;
5726 }
5727 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5728 mNavigationBarController.showTransient();
5729 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005730 }
5731 };
5732
John Spurlocke1f366f2013-08-05 12:22:40 -04005733 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005734 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005735 if (!isUserSetupComplete()) {
5736 // Swipe-up for navigation bar is disabled during setup
5737 return;
5738 }
John Spurlock27735a42013-08-14 17:57:38 -04005739 boolean sb = mStatusBarController.checkShowTransientBarLw();
5740 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005741 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005742 // Don't show status bar when swiping on already visible navigation bar
5743 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005744 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005745 return;
5746 }
John Spurlock27735a42013-08-14 17:57:38 -04005747 if (sb) mStatusBarController.showTransient();
5748 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005749 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005750 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005751 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005752 }
5753 }
5754
Jeff Brown3ee549c2014-09-22 20:14:39 -07005755 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005756 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005757 public void startedGoingToSleep(int why) {
5758 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005759 if (mKeyguardDelegate != null) {
5760 mKeyguardDelegate.onStartedGoingToSleep(why);
5761 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005762 }
5763
5764 // Called on the PowerManager's Notifier thread.
5765 @Override
5766 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005767 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005768 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005769 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005770
5771 // We must get this work done here because the power manager will drop
5772 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005773 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005774 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005775 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005776 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005777 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005778 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005779 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005780 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005781 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005782 }
5783
Jeff Brown3ee549c2014-09-22 20:14:39 -07005784 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005785 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005786 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005787 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005788 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005789
Jeff Brown3ee549c2014-09-22 20:14:39 -07005790 // Since goToSleep performs these functions synchronously, we must
5791 // do the same here. We cannot post this work to a handler because
5792 // that might cause it to become reordered with respect to what
5793 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005794 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005795 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005796
Jeff Browna20dda42014-05-27 20:57:24 -07005797 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005798 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005799 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005800 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005801
Jim Miller5ecd8112013-01-09 18:50:26 -08005802 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005803 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005804 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005805 }
5806
Jeff Brown416c49c2015-05-26 19:50:18 -07005807 // Called on the PowerManager's Notifier thread.
5808 @Override
5809 public void finishedWakingUp() {
5810 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5811 }
5812
5813 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005814 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07005815 }
5816
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005817 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07005818 final boolean theaterModeEnabled = isTheaterModeEnabled();
5819 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005820 return false;
5821 }
5822
Bryce Leed3896842015-06-23 17:06:51 -07005823 if (theaterModeEnabled) {
5824 Settings.Global.putInt(mContext.getContentResolver(),
5825 Settings.Global.THEATER_MODE_ON, 0);
5826 }
5827
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005828 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07005829 return true;
5830 }
5831
Jeff Brown36c4db82014-09-19 12:05:31 -07005832 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005833 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07005834 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005835 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005836 }
5837
Jeff Brown36c4db82014-09-19 12:05:31 -07005838 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005839 if (mKeyguardDelegate != null) {
5840 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5841 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005842 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005843 }
5844
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005845 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5846 // as well as enabling the orientation change logic/sensor.
5847 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5848 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005849 }
5850
5851 // Called on the DisplayManager's DisplayPowerController thread.
5852 @Override
5853 public void screenTurnedOff() {
5854 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5855
Jeff Brown48d1b142015-06-10 16:36:03 -07005856 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005857 synchronized (mLock) {
5858 mScreenOnEarly = false;
5859 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005860 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005861 mWindowManagerDrawComplete = false;
5862 mScreenOnListener = null;
5863 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005864
5865 if (mKeyguardDelegate != null) {
5866 mKeyguardDelegate.onScreenTurnedOff();
5867 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005868 }
5869 }
5870
Jeff Brown3ee549c2014-09-22 20:14:39 -07005871 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005872 @Override
5873 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005874 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005875
Jeff Brown48d1b142015-06-10 16:36:03 -07005876 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005877 synchronized (mLock) {
5878 mScreenOnEarly = true;
5879 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005880 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005881 mWindowManagerDrawComplete = false;
5882 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07005883
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005884 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07005885 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5886 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005887 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
5888 } else {
5889 if (DEBUG_WAKEUP) Slog.d(TAG,
5890 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
5891 finishKeyguardDrawn();
5892 }
5893 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005894 }
5895
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005896 // Called on the DisplayManager's DisplayPowerController thread.
5897 @Override
5898 public void screenTurnedOn() {
5899 synchronized (mLock) {
5900 if (mKeyguardDelegate != null) {
5901 mKeyguardDelegate.onScreenTurnedOn();
5902 }
5903 }
5904 }
5905
Jeff Brown36c4db82014-09-19 12:05:31 -07005906 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005907 synchronized (mLock) {
5908 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005909 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005910 }
5911
Jeff Brown36c4db82014-09-19 12:05:31 -07005912 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005913 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005914
5915 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005916 }
5917
Craig Mautner8a0da012014-05-31 15:13:37 -07005918 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005919 synchronized (mLock) {
5920 // We have just finished drawing screen content. Since the orientation listener
5921 // gets only installed when all windows are drawn, we try to install it again.
5922 updateOrientationListenerLp();
5923 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005924 final ScreenOnListener listener;
5925 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005926 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005927 if (DEBUG_WAKEUP) Slog.d(TAG,
5928 "finishScreenTurningOn: mAwake=" + mAwake
5929 + ", mScreenOnEarly=" + mScreenOnEarly
5930 + ", mScreenOnFully=" + mScreenOnFully
5931 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5932 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5933
5934 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5935 || (mAwake && !mKeyguardDrawComplete)) {
5936 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005937 }
5938
Jeff Brown3ee549c2014-09-22 20:14:39 -07005939 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5940 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005941 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005942 mScreenOnFully = true;
5943
5944 // Remember the first time we draw the keyguard so we know when we're done with
5945 // the main part of booting and can enable the screen and hide boot messages.
5946 if (!mKeyguardDrawnOnce && mAwake) {
5947 mKeyguardDrawnOnce = true;
5948 enableScreen = true;
5949 if (mBootMessageNeedsHiding) {
5950 mBootMessageNeedsHiding = false;
5951 hideBootMessages();
5952 }
5953 } else {
5954 enableScreen = false;
5955 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005956 }
5957
Jeff Brown3ee549c2014-09-22 20:14:39 -07005958 if (listener != null) {
5959 listener.onScreenOn();
5960 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005961
Jeff Brown3ee549c2014-09-22 20:14:39 -07005962 if (enableScreen) {
5963 try {
5964 mWindowManager.enableScreenIfNeeded();
5965 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005966 }
Craig Mautnera631d492014-08-05 15:16:01 -07005967 }
5968 }
5969
5970 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005971 synchronized (mLock) {
5972 if (!mKeyguardDrawnOnce) {
5973 mBootMessageNeedsHiding = true;
5974 return; // keyguard hasn't drawn the first time yet, not done booting
5975 }
Craig Mautnera631d492014-08-05 15:16:01 -07005976 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005977
5978 if (mBootMsgDialog != null) {
5979 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5980 mBootMsgDialog.dismiss();
5981 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005982 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005983 }
5984
5985 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005986 public boolean isScreenOn() {
5987 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005988 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005989
Dianne Hackborn08743722009-12-21 12:16:51 -08005990 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005991 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005992 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005993 if (mKeyguardDelegate != null) {
5994 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005995 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005996 }
5997
5998 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005999 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006000 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08006001 if (mKeyguardDelegate != null) {
6002 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006003 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006004 }
6005
Jim Millerab954542014-10-10 18:21:49 -07006006 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006007 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07006008 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006009 }
6010
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006011 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006012 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006013 public boolean isKeyguardLocked() {
6014 return keyguardOn();
6015 }
6016
6017 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006018 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006019 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006020 if (mKeyguardDelegate == null) return false;
6021 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006022 }
6023
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006024 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006025 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07006026 public boolean isKeyguardShowingOrOccluded() {
6027 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
6028 }
6029
6030 /** {@inheritDoc} */
6031 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006032 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006033 if (mKeyguardDelegate == null) return false;
6034 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006035 }
6036
Jose Lima9546b202014-07-02 17:21:51 -07006037 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006038 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07006039 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006040 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05006041 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07006042 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05006043 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02006044 // ask the keyguard to prompt the user to authenticate if necessary
6045 mKeyguardDelegate.dismiss();
6046 }
6047 });
6048 }
6049 }
6050
6051 public void notifyActivityDrawnForKeyguardLw() {
6052 if (mKeyguardDelegate != null) {
6053 mHandler.post(new Runnable() {
6054 @Override
6055 public void run() {
6056 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05006057 }
6058 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006059 }
6060 }
6061
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006062 @Override
6063 public boolean isKeyguardDrawnLw() {
6064 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006065 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006066 }
6067 }
6068
Jorim Jaggi0d674622014-05-21 01:34:15 +02006069 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006070 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02006071 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006072 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006073 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02006074 }
6075 }
6076
Jorim Jaggi737af722015-12-31 10:42:27 +01006077 @Override
6078 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6079 Rect outInsets) {
6080 outInsets.setEmpty();
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006081
6082 // Navigation bar and status bar.
6083 getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets);
Jorim Jaggi737af722015-12-31 10:42:27 +01006084 if (mStatusBar != null) {
6085 outInsets.top = mStatusBarHeight;
6086 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006087 }
6088
6089 @Override
6090 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6091 Rect outInsets) {
6092 outInsets.setEmpty();
6093
6094 // Only navigation bar
Jorim Jaggi737af722015-12-31 10:42:27 +01006095 if (mNavigationBar != null) {
6096 if (isNavigationBarOnBottom(displayWidth, displayHeight)) {
6097 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
6098 } else {
6099 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
6100 }
6101 }
6102 }
6103
Jorim Jaggi5060bd82016-02-19 17:12:19 -08006104 @Override
6105 public boolean isDockSideAllowed(int dockSide) {
6106
6107 // We do not allow all dock sides at which the navigation bar touches the docked stack.
6108 if (!mNavigationBarCanMove) {
6109 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT || dockSide == DOCKED_RIGHT;
6110 } else {
6111 return dockSide == DOCKED_TOP || dockSide == DOCKED_LEFT;
6112 }
6113 }
6114
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006115 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006116 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006117 }
6118
6119 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006120 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006121 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006122
Jeff Brown01a98dd2011-09-20 15:08:29 -07006123 @Override
6124 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006125 if (false) {
6126 Slog.v(TAG, "rotationForOrientationLw(orient="
6127 + orientation + ", last=" + lastRotation
6128 + "); user=" + mUserRotation + " "
6129 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
6130 ? "USER_ROTATION_LOCKED" : "")
6131 );
6132 }
6133
Craig Mautner46ac6fa2013-08-01 10:06:34 -07006134 if (mForceDefaultOrientation) {
6135 return Surface.ROTATION_0;
6136 }
6137
The Android Open Source Project0727d222009-03-11 12:11:58 -07006138 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07006139 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
6140 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07006141 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07006142 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006143
Jeff Browndec6cf42011-11-15 14:08:20 -08006144 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07006145 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006146 // Ignore sensor when lid switch is open and rotation is forced.
6147 preferredRotation = mLidOpenRotation;
6148 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07006149 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006150 // Ignore sensor when in car dock unless explicitly enabled.
6151 // This case can override the behavior of NOSENSOR, and can also
6152 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006153 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006154 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08006155 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6156 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
6157 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07006158 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006159 // Ignore sensor when in desk dock unless explicitly enabled.
6160 // This case can override the behavior of NOSENSOR, and can also
6161 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006162 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006163 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006164 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
6165 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08006166 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006167 preferredRotation = mDemoHdmiRotation;
6168 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
6169 && mUndockedHdmiRotation >= 0) {
6170 // Ignore sensor when plugged into HDMI and an undocked orientation has
6171 // been specified in the configuration (only for legacy devices without
6172 // full multi-display support).
6173 // Note that the dock orientation overrides the HDMI orientation.
6174 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08006175 } else if (mDemoRotationLock) {
6176 // Ignore sensor when demo rotation lock is enabled.
6177 // Note that the dock orientation and HDMI rotation lock override this.
6178 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006179 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
6180 // Application just wants to remain locked in the last rotation.
6181 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08006182 } else if (!mSupportAutoRotation) {
6183 // If we don't support auto-rotation then bail out here and ignore
6184 // the sensor and any rotation lock settings.
6185 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07006186 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07006187 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006188 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6189 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
6190 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
6191 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07006192 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
6193 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6194 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
6195 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
6196 // Otherwise, use sensor only if requested by the application or enabled
6197 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07006198 if (mAllowAllRotations < 0) {
6199 // Can't read this during init() because the context doesn't
6200 // have display metrics at that time so we cannot determine
6201 // tablet vs. phone then.
6202 mAllowAllRotations = mContext.getResources().getBoolean(
6203 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
6204 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006205 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07006206 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006207 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6208 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006209 preferredRotation = sensorRotation;
6210 } else {
6211 preferredRotation = lastRotation;
6212 }
Jeff Brown207673cd2012-06-05 17:47:11 -07006213 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
6214 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
6215 // Apply rotation lock. Does not apply to NOSENSOR.
6216 // The idea is that the user rotation expresses a weak preference for the direction
6217 // of gravity and as NOSENSOR is never affected by gravity, then neither should
6218 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07006219 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08006220 } else {
6221 // No overriding preference.
6222 // We will do exactly what the application asked us to do.
6223 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07006224 }
6225
Dianne Hackborne5439f22010-10-02 16:53:50 -07006226 switch (orientation) {
6227 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006228 // Return portrait unless overridden.
6229 if (isAnyPortrait(preferredRotation)) {
6230 return preferredRotation;
6231 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07006232 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006233
Jeff Brown01a98dd2011-09-20 15:08:29 -07006234 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006235 // Return landscape unless overridden.
6236 if (isLandscapeOrSeascape(preferredRotation)) {
6237 return preferredRotation;
6238 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006239 return mLandscapeRotation;
6240
6241 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006242 // Return reverse portrait unless overridden.
6243 if (isAnyPortrait(preferredRotation)) {
6244 return preferredRotation;
6245 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006246 return mUpsideDownRotation;
6247
6248 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006249 // Return seascape unless overridden.
6250 if (isLandscapeOrSeascape(preferredRotation)) {
6251 return preferredRotation;
6252 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006253 return mSeascapeRotation;
6254
6255 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006256 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006257 // Return either landscape rotation.
6258 if (isLandscapeOrSeascape(preferredRotation)) {
6259 return preferredRotation;
6260 }
6261 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006262 return lastRotation;
6263 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006264 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006265
Jeff Brown01a98dd2011-09-20 15:08:29 -07006266 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006267 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006268 // Return either portrait rotation.
6269 if (isAnyPortrait(preferredRotation)) {
6270 return preferredRotation;
6271 }
6272 if (isAnyPortrait(lastRotation)) {
6273 return lastRotation;
6274 }
6275 return mPortraitRotation;
6276
6277 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006278 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6279 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006280 if (preferredRotation >= 0) {
6281 return preferredRotation;
6282 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006283 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006284 }
6285 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006286 }
6287
Jeff Brown01a98dd2011-09-20 15:08:29 -07006288 @Override
6289 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6290 switch (orientation) {
6291 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6292 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6293 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6294 return isAnyPortrait(rotation);
6295
6296 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6297 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6298 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6299 return isLandscapeOrSeascape(rotation);
6300
6301 default:
6302 return true;
6303 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006304 }
6305
Jeff Brownc0347aa2011-09-23 17:26:09 -07006306 @Override
6307 public void setRotationLw(int rotation) {
6308 mOrientationListener.setCurrentRotation(rotation);
6309 }
6310
Jeff Brown01a98dd2011-09-20 15:08:29 -07006311 private boolean isLandscapeOrSeascape(int rotation) {
6312 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006313 }
6314
Jeff Brown01a98dd2011-09-20 15:08:29 -07006315 private boolean isAnyPortrait(int rotation) {
6316 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006317 }
6318
Jose Lima9546b202014-07-02 17:21:51 -07006319 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006320 public int getUserRotationMode() {
6321 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006322 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6323 WindowManagerPolicy.USER_ROTATION_FREE :
6324 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006325 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006326
6327 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006328 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006329 public void setUserRotationMode(int mode, int rot) {
6330 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006331
6332 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006333 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006334 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006335 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006336 rot,
6337 UserHandle.USER_CURRENT);
6338 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006339 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006340 0,
6341 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006342 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006343 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006344 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006345 1,
6346 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006347 }
6348 }
6349
Jose Lima9546b202014-07-02 17:21:51 -07006350 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006351 public void setSafeMode(boolean safeMode) {
6352 mSafeMode = safeMode;
6353 performHapticFeedbackLw(null, safeMode
6354 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6355 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006356 }
Craig Mautnereda67292013-04-28 13:50:14 -07006357
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006358 static long[] getLongIntArray(Resources r, int resid) {
6359 int[] ar = r.getIntArray(resid);
6360 if (ar == null) {
6361 return null;
6362 }
6363 long[] out = new long[ar.length];
6364 for (int i=0; i<ar.length; i++) {
6365 out[i] = ar[i];
6366 }
6367 return out;
6368 }
Craig Mautnereda67292013-04-28 13:50:14 -07006369
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006370 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006371 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006372 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006373 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006374 mKeyguardDelegate.onSystemReady();
6375
Michael Wright3818c922014-09-02 13:59:07 -07006376 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006377 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006378 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006379 synchronized (mLock) {
6380 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006381 mSystemReady = true;
6382 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006383 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006384 public void run() {
6385 updateSettings();
6386 }
6387 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006388
6389 bindKeyguardNow = mDeferBindKeyguard;
6390 if (bindKeyguardNow) {
6391 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6392 mDeferBindKeyguard = false;
6393 }
6394 }
6395
6396 if (bindKeyguardNow) {
6397 mKeyguardDelegate.bindService(mContext);
6398 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006399 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006400 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006401 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006402
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006403 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006404 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006405 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006406 boolean bindKeyguardNow = false;
6407 synchronized (mLock) {
6408 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6409 // in systemReady if not.
6410 if (mKeyguardDelegate != null) {
6411 bindKeyguardNow = true;
6412 } else {
6413 // Because mKeyguardDelegate is null, we know that the synchronized block in
6414 // systemReady didn't run yet and setting this will actually have an effect.
6415 mDeferBindKeyguard = true;
6416 }
6417 }
6418 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006419 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006420 mKeyguardDelegate.onBootCompleted();
6421 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006422 synchronized (mLock) {
6423 mSystemBooted = true;
6424 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006425 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006426 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006427 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006428 }
6429
Dianne Hackborn661cd522011-08-22 00:26:20 -07006430 ProgressDialog mBootMsgDialog = null;
6431
6432 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006433 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006434 public void showBootMessage(final CharSequence msg, final boolean always) {
6435 mHandler.post(new Runnable() {
6436 @Override public void run() {
6437 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006438 int theme;
Jaewan Kim49117872016-01-19 17:24:08 +09006439 if (mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006440 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
Jaewan Kim49117872016-01-19 17:24:08 +09006441 } else if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006442 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6443 } else {
6444 theme = 0;
6445 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006446
6447 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006448 // This dialog will consume all events coming in to
6449 // it, to avoid it trying to do things too early in boot.
6450 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6451 return true;
6452 }
6453 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6454 return true;
6455 }
6456 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6457 return true;
6458 }
6459 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6460 return true;
6461 }
6462 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6463 return true;
6464 }
6465 @Override public boolean dispatchPopulateAccessibilityEvent(
6466 AccessibilityEvent event) {
6467 return true;
6468 }
6469 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006470 if (mContext.getPackageManager().isUpgrade()) {
6471 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6472 } else {
6473 mBootMsgDialog.setTitle(R.string.android_start_title);
6474 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006475 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6476 mBootMsgDialog.setIndeterminate(true);
6477 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006478 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006479 mBootMsgDialog.getWindow().addFlags(
6480 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6481 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6482 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006483 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6484 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6485 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006486 mBootMsgDialog.setCancelable(false);
6487 mBootMsgDialog.show();
6488 }
6489 mBootMsgDialog.setMessage(msg);
6490 }
6491 });
6492 }
6493
6494 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006495 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006496 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006497 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006498 }
6499
Mike Lockwood28569302010-01-28 11:54:40 -05006500 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006501 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006502 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006503 // ***************************************
6504 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6505 // ***************************************
6506 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6507 // WITH ITS LOCKS HELD.
6508 //
6509 // This code must be VERY careful about the locks
6510 // it acquires.
6511 // In fact, the current code acquires way too many,
6512 // and probably has lurking deadlocks.
6513
Mike Lockwood28569302010-01-28 11:54:40 -05006514 synchronized (mScreenLockTimeout) {
6515 if (mLockScreenTimerActive) {
6516 // reset the timer
6517 mHandler.removeCallbacks(mScreenLockTimeout);
6518 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6519 }
6520 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006521 }
6522
Adam Cohenf7522022012-10-03 20:03:18 -07006523 class ScreenLockTimeout implements Runnable {
6524 Bundle options;
6525
6526 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006527 public void run() {
6528 synchronized (this) {
6529 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006530 if (mKeyguardDelegate != null) {
6531 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006532 }
Mike Lockwood28569302010-01-28 11:54:40 -05006533 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006534 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006535 }
6536 }
Mike Lockwood28569302010-01-28 11:54:40 -05006537
Adam Cohenf7522022012-10-03 20:03:18 -07006538 public void setLockOptions(Bundle options) {
6539 this.options = options;
6540 }
6541 }
6542
6543 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6544
Jose Lima9546b202014-07-02 17:21:51 -07006545 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006546 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006547 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6548 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006549 if (options != null) {
6550 // In case multiple calls are made to lockNow, we don't wipe out the options
6551 // until the runnable actually executes.
6552 mScreenLockTimeout.setLockOptions(options);
6553 }
Jim Miller93c518e2012-01-17 15:55:31 -08006554 mHandler.post(mScreenLockTimeout);
6555 }
6556
Mike Lockwood28569302010-01-28 11:54:40 -05006557 private void updateLockScreenTimeout() {
6558 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006559 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006560 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006561 if (mLockScreenTimerActive != enable) {
6562 if (enable) {
6563 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08006564 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05006565 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6566 } else {
6567 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6568 mHandler.removeCallbacks(mScreenLockTimeout);
6569 }
6570 mLockScreenTimerActive = enable;
6571 }
6572 }
6573 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006574
Jeff Brown061ea992015-04-17 19:55:47 -07006575 private void updateDreamingSleepToken(boolean acquire) {
6576 if (acquire) {
6577 if (mDreamingSleepToken == null) {
6578 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6579 }
6580 } else {
6581 if (mDreamingSleepToken != null) {
6582 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006583 mDreamingSleepToken = null;
6584 }
6585 }
6586 }
6587
6588 private void updateScreenOffSleepToken(boolean acquire) {
6589 if (acquire) {
6590 if (mScreenOffSleepToken == null) {
6591 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6592 }
6593 } else {
6594 if (mScreenOffSleepToken != null) {
6595 mScreenOffSleepToken.release();
6596 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006597 }
6598 }
6599 }
6600
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006601 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006602 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006603 public void enableScreenAfterBoot() {
6604 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006605 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006606 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006607 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006608
Jeff Brownc458ce92012-04-30 14:58:40 -07006609 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006610 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006611 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006612 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006613 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01006614 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
6615 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07006616 }
Jeff Browna20dda42014-05-27 20:57:24 -07006617
6618 synchronized (mLock) {
6619 updateWakeGestureListenerLp();
6620 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006621 }
6622
Jeff Brown4f5fa282014-06-12 19:19:15 -07006623 void updateUiMode() {
6624 if (mUiModeManager == null) {
6625 mUiModeManager = IUiModeManager.Stub.asInterface(
6626 ServiceManager.getService(Context.UI_MODE_SERVICE));
6627 }
6628 try {
6629 mUiMode = mUiModeManager.getCurrentModeType();
6630 } catch (RemoteException e) {
6631 }
6632 }
6633
Jeff Brown01a98dd2011-09-20 15:08:29 -07006634 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006635 try {
6636 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006637 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6638 } catch (RemoteException e) {
6639 // Ignore
6640 }
6641 }
6642
6643 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6644 try {
6645 //set orientation on WindowManager
6646 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006647 } catch (RemoteException e) {
6648 // Ignore
6649 }
6650 }
6651
Daniel Sandler6396c722013-04-16 20:19:09 -04006652 /**
6653 * Return an Intent to launch the currently active dock app as home. Returns
6654 * null if the standard home should be launched, which is the case if any of the following is
6655 * true:
6656 * <ul>
6657 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07006658 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04006659 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6660 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6661 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6662 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006663 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006664 */
6665 Intent createHomeDockIntent() {
6666 Intent intent = null;
6667
6668 // What home does is based on the mode, not the dock state. That
6669 // is, when in car mode you should be taken to car home regardless
6670 // of whether we are actually in a car dock.
6671 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07006672 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04006673 intent = mCarDockIntent;
6674 }
6675 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6676 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6677 intent = mDeskDockIntent;
6678 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006679 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6680 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6681 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6682 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6683 // Always launch dock home from home when watch is docked, if it exists.
6684 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006685 }
6686
6687 if (intent == null) {
6688 return null;
6689 }
6690
6691 ActivityInfo ai = null;
6692 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6693 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006694 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006695 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006696 if (info != null) {
6697 ai = info.activityInfo;
6698 }
6699 if (ai != null
6700 && ai.metaData != null
6701 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6702 intent = new Intent(intent);
6703 intent.setClassName(ai.packageName, ai.name);
6704 return intent;
6705 }
6706
6707 return null;
6708 }
6709
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006710 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6711 if (awakenFromDreams) {
6712 awakenDreams();
6713 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006714
6715 Intent dock = createHomeDockIntent();
6716 if (dock != null) {
6717 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006718 if (fromHomeKey) {
6719 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6720 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006721 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006722 return;
6723 } catch (ActivityNotFoundException e) {
6724 }
6725 }
6726
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006727 Intent intent;
6728
6729 if (fromHomeKey) {
6730 intent = new Intent(mHomeIntent);
6731 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6732 } else {
6733 intent = mHomeIntent;
6734 }
6735
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006736 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006737 }
Craig Mautnereda67292013-04-28 13:50:14 -07006738
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006739 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006740 * goes to the home screen
6741 * @return whether it did anything
6742 */
6743 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006744 if (!isUserSetupComplete()) {
6745 Slog.i(TAG, "Not going home because user setup is in progress.");
6746 return false;
6747 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006748 if (false) {
6749 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006750 try {
6751 ActivityManagerNative.getDefault().stopAppSwitches();
6752 } catch (RemoteException e) {
6753 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006754 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006755 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006756 } else {
6757 // This code brings home to the front or, if it is already
6758 // at the front, puts the device to sleep.
6759 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006760 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6761 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6762 Log.d(TAG, "UTS-TEST-MODE");
6763 } else {
6764 ActivityManagerNative.getDefault().stopAppSwitches();
6765 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006766 Intent dock = createHomeDockIntent();
6767 if (dock != null) {
6768 int result = ActivityManagerNative.getDefault()
6769 .startActivityAsUser(null, null, dock,
6770 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6771 null, null, 0,
6772 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006773 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006774 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6775 return false;
6776 }
6777 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006778 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006779 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006780 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006781 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006782 null, null, 0,
6783 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006784 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006785 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006786 return false;
6787 }
6788 } catch (RemoteException ex) {
6789 // bummer, the activity manager, which is in this process, is dead
6790 }
6791 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006792 return true;
6793 }
Craig Mautnereda67292013-04-28 13:50:14 -07006794
6795 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006796 public void setCurrentOrientationLw(int newOrientation) {
6797 synchronized (mLock) {
6798 if (newOrientation != mCurrentAppOrientation) {
6799 mCurrentAppOrientation = newOrientation;
6800 updateOrientationListenerLp();
6801 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006802 }
6803 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006804
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006805 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6806 if (!isGlobalAccessibilityGestureEnabled()) {
6807 return;
6808 }
6809 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6810 Context.AUDIO_SERVICE);
6811 if (audioManager.isSilentMode()) {
6812 return;
6813 }
6814 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6815 Settings.System.DEFAULT_NOTIFICATION_URI);
6816 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6817 ringTone.play();
6818 }
Craig Mautnereda67292013-04-28 13:50:14 -07006819
Bryce Lee584a4452014-10-21 15:55:55 -07006820 private boolean isTheaterModeEnabled() {
6821 return Settings.Global.getInt(mContext.getContentResolver(),
6822 Settings.Global.THEATER_MODE_ON, 0) == 1;
6823 }
6824
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006825 private boolean isGlobalAccessibilityGestureEnabled() {
6826 return Settings.Global.getInt(mContext.getContentResolver(),
6827 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6828 }
6829
Craig Mautnereda67292013-04-28 13:50:14 -07006830 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006831 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006832 if (!mVibrator.hasVibrator()) {
6833 return false;
6834 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006835 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6836 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006837 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006838 return false;
6839 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006840 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006841 switch (effectId) {
6842 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006843 pattern = mLongPressVibePattern;
6844 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006845 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006846 pattern = mVirtualKeyVibePattern;
6847 break;
6848 case HapticFeedbackConstants.KEYBOARD_TAP:
6849 pattern = mKeyboardTapVibePattern;
6850 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006851 case HapticFeedbackConstants.CLOCK_TICK:
6852 pattern = mClockTickVibePattern;
6853 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006854 case HapticFeedbackConstants.CALENDAR_DATE:
6855 pattern = mCalendarDateVibePattern;
6856 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006857 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006858 pattern = mSafeModeDisabledVibePattern;
6859 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006860 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006861 pattern = mSafeModeEnabledVibePattern;
6862 break;
Mady Mellore8608912015-06-05 09:02:55 -07006863 case HapticFeedbackConstants.CONTEXT_CLICK:
6864 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006865 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006866 default:
6867 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006868 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006869 int owningUid;
6870 String owningPackage;
6871 if (win != null) {
6872 owningUid = win.getOwningUid();
6873 owningPackage = win.getOwningPackage();
6874 } else {
6875 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006876 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006877 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006878 if (pattern.length == 1) {
6879 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006880 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006881 } else {
6882 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006883 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006884 }
6885 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006886 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006887
6888 @Override
6889 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006890 }
6891
Jeff Brownc38c9be2012-10-04 13:16:19 -07006892 @Override
6893 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006894 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006895 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006896 }
6897 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006898
Dianne Hackborndf89e652011-10-06 22:35:11 -07006899 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006900 // If there is no window focused, there will be nobody to handle the events
6901 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006902 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6903 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006904 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006905 return 0;
6906 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006907 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006908 // We are updating at a point where the keyguard has gotten
6909 // focus, but we were last in a state where the top window is
6910 // hiding it. This is probably because the keyguard as been
6911 // shown while the top window was displayed, so we want to ignore
6912 // it here because this is just a very transient change and it
6913 // will quickly lose focus once it correctly gets hidden.
6914 return 0;
6915 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006916
John Spurlock1db8b682014-02-18 11:18:59 -05006917 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006918 & ~mResettingSystemUiFlags
6919 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006920 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006921 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006922 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07006923
6924 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6925 tmpVisibility |= StatusBarManager.DISABLE_RECENT;
6926 }
6927
Jorim Jaggi86905582016-02-09 21:36:09 -08006928 final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */,
6929 mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState);
6930 final int dockedVisibility = updateLightStatusBarLw(0 /* vis */,
6931 mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState);
6932 mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds);
6933 mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds);
John Spurlock79da8332013-09-20 12:04:47 -04006934 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006935 final int diff = visibility ^ mLastSystemUiFlags;
Jorim Jaggi86905582016-02-09 21:36:09 -08006936 final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags;
6937 final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006938 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Jorim Jaggi86905582016-02-09 21:36:09 -08006939 if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu
6940 && mFocusedApp == win.getAppToken()
6941 && mLastNonDockedStackBounds.equals(mNonDockedStackBounds)
6942 && mLastDockedStackBounds.equals(mDockedStackBounds)) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006943 return 0;
6944 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006945 mLastSystemUiFlags = visibility;
Jorim Jaggi86905582016-02-09 21:36:09 -08006946 mLastFullscreenStackSysUiFlags = fullscreenVisibility;
6947 mLastDockedStackSysUiFlags = dockedVisibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006948 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006949 mFocusedApp = win.getAppToken();
Jorim Jaggi86905582016-02-09 21:36:09 -08006950 final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds);
6951 final Rect dockedStackBounds = new Rect(mDockedStackBounds);
Dianne Hackborndf89e652011-10-06 22:35:11 -07006952 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006953 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006954 public void run() {
Jorim Jaggi86905582016-02-09 21:36:09 -08006955 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
6956 if (statusbar != null) {
6957 statusbar.setSystemUiVisibility(visibility, fullscreenVisibility,
6958 dockedVisibility, 0xffffffff, fullscreenStackBounds,
6959 dockedStackBounds, win.toString());
6960 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006961 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006962 }
6963 });
6964 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006965 }
6966
Jorim Jaggi86905582016-02-09 21:36:09 -08006967 private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01006968 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6969 ? mStatusBar
Jorim Jaggi86905582016-02-09 21:36:09 -08006970 : opaqueOrDimming;
Adrian Rooscd3884d2015-02-18 17:25:23 +01006971
6972 if (statusColorWin != null) {
Jorim Jaggi86905582016-02-09 21:36:09 -08006973 if (statusColorWin == opaque) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01006974 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6975 // its light flag.
6976 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6977 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6978 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6979 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6980 // Otherwise if it's dimming, clear the light flag.
6981 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6982 }
6983 }
6984 return vis;
6985 }
6986
John Spurlock79da8332013-09-20 12:04:47 -04006987 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006988 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
6989 final boolean freeformStackVisible =
6990 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08006991 final boolean resizing = mWindowManagerInternal.isDockedDividerResizing();
6992
6993 // We need to force system bars when the docked stack is visible, when the freeform stack
6994 // is visible but also when we are resizing for the transitions when docked stack
6995 // visibility changes.
6996 final boolean forceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing;
Jorim Jaggi4fa78922015-11-30 17:13:56 -08006997 final boolean forceOpaqueSystemBars = forceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006998
John Spurlockbd957402013-10-03 11:38:39 -04006999 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01007000 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
7001 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04007002 : mTopFullscreenOpaqueWindowState;
7003 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
7004 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
7005
John Spurlock27735a42013-08-14 17:57:38 -04007006 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07007007 int type = win.getAttrs().type;
7008 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007009 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04007010 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
7011 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04007012 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01007013 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
7014 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007015 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01007016 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
7017 }
John Spurlockbd957402013-10-03 11:38:39 -04007018 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007019 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04007020
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007021 if ((!areTranslucentBarsAllowed() && transWin != mStatusBar)
7022 || forceOpaqueSystemBars) {
Adrian Roosea562512014-05-05 13:33:03 +02007023 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
7024 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007025 }
7026
Jorim Jaggi4fa78922015-11-30 17:13:56 -08007027 if (mForceWindowDrawsStatusBarBackground) {
7028 vis |= View.STATUS_BAR_TRANSPARENT;
7029 vis &= ~View.STATUS_BAR_TRANSLUCENT;
7030 }
7031
John Spurlock27735a42013-08-14 17:57:38 -04007032 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04007033 boolean immersiveSticky =
7034 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007035 final boolean hideStatusBarWM =
7036 mTopFullscreenOpaqueWindowState != null
7037 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04007038 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007039 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04007040 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007041 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04007042 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007043
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007044 final boolean transientStatusBarAllowed = mStatusBar != null
7045 && (statusBarHasFocus || (!forceShowSystemBars
7046 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04007047
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007048 final boolean transientNavBarAllowed = mNavigationBar != null
7049 && !forceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04007050
Adrian Roosddc8b272015-05-21 16:28:27 -07007051 final long now = SystemClock.uptimeMillis();
7052 final boolean pendingPanic = mPendingPanicGestureUptime != 0
7053 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
7054 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
7055 // The user performed the panic gesture recently, we're about to hide the bars,
7056 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
7057 mPendingPanicGestureUptime = 0;
7058 mStatusBarController.showTransient();
7059 mNavigationBarController.showTransient();
7060 }
7061
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007062 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007063 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007064 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007065 && !transientNavBarAllowed;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007066 if (denyTransientStatus || denyTransientNav || forceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04007067 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04007068 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08007069 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007070 }
John Spurlock27735a42013-08-14 17:57:38 -04007071
Selim Cinekf98702e2015-05-20 22:48:40 -07007072 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
7073 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
7074 final boolean navAllowedHidden = immersive || immersiveSticky;
7075
Selim Cinekd6623612015-05-22 18:56:22 -07007076 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
7077 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07007078 // We can't hide the navbar from this window otherwise the input consumer would not get
7079 // the input events.
7080 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
7081 }
7082
John Spurlock27735a42013-08-14 17:57:38 -04007083 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
7084
7085 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04007086 boolean oldImmersiveMode = isImmersiveMode(oldVis);
7087 boolean newImmersiveMode = isImmersiveMode(vis);
7088 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04007089 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07007090 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
7091 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04007092 }
John Spurlock27735a42013-08-14 17:57:38 -04007093
John Spurlockf1a36642013-10-12 17:50:42 -04007094 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
7095
John Spurlocke1f366f2013-08-05 12:22:40 -04007096 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007097 }
7098
John Spurlockf1a36642013-10-12 17:50:42 -04007099 private void clearClearableFlagsLw() {
7100 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
7101 if (newVal != mResettingSystemUiFlags) {
7102 mResettingSystemUiFlags = newVal;
7103 mWindowManagerFuncs.reevaluateStatusBarVisibility();
7104 }
7105 }
7106
7107 private boolean isImmersiveMode(int vis) {
7108 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04007109 return mNavigationBar != null
7110 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04007111 && (vis & flags) != 0
7112 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04007113 }
7114
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007115 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007116 * @return whether the navigation or status bar can be made translucent
7117 *
7118 * This should return true unless touch exploration is not enabled or
7119 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007120 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007121 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04007122 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007123 }
7124
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007125 // Use this instead of checking config_showNavigationBar so that it can be consistently
7126 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07007127 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007128 public boolean hasNavigationBar() {
7129 return mHasNavigationBar;
7130 }
7131
satok1bc0a492012-04-25 22:47:12 +09007132 @Override
7133 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
7134 mLastInputMethodWindow = ime;
7135 mLastInputMethodTargetWindow = target;
7136 }
7137
Craig Mautnerf1b67412012-09-19 13:18:29 -07007138 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09007139 public int getInputMethodWindowVisibleHeightLw() {
7140 return mDockBottom - mCurBottom;
7141 }
7142
7143 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07007144 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07007145 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08007146 if (mKeyguardDelegate != null) {
7147 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007148 }
John Spurlock13451a22012-09-28 14:40:41 -04007149 if (mStatusBarService != null) {
7150 try {
7151 mStatusBarService.setCurrentUser(newUserId);
7152 } catch (RemoteException e) {
7153 // oh well
7154 }
7155 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007156 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007157 }
7158
7159 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08007160 public boolean canMagnifyWindow(int windowType) {
7161 switch (windowType) {
7162 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
7163 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
7164 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
7165 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
7166 return false;
7167 }
7168 }
7169 return true;
7170 }
7171
7172 @Override
7173 public boolean isTopLevelWindow(int windowType) {
7174 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
7175 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
7176 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
7177 }
7178 return true;
7179 }
7180
Jim Miller4eeb4f62012-11-08 00:04:29 -08007181 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07007182 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007183 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007184 pw.print(" mSystemReady="); pw.print(mSystemReady);
7185 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07007186 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007187 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07007188 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007189 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07007190 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
7191 || mForceClearedSystemUiFlags != 0) {
7192 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
7193 pw.print(Integer.toHexString(mLastSystemUiFlags));
7194 pw.print(" mResettingSystemUiFlags=0x");
7195 pw.print(Integer.toHexString(mResettingSystemUiFlags));
7196 pw.print(" mForceClearedSystemUiFlags=0x");
7197 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07007198 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007199 if (mLastFocusNeedsMenu) {
7200 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
7201 pw.println(mLastFocusNeedsMenu);
7202 }
Jeff Browna20dda42014-05-27 20:57:24 -07007203 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
7204 pw.println(mWakeGestureEnabledSetting);
7205
Jeff Brownbcdfc622014-03-06 19:13:04 -08007206 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04007207 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
7208 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07007209 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007210 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
7211 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
7212 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
7213 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007214 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007215 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007216 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
7217 pw.print(mCarDockEnablesAccelerometer);
7218 pw.print(" mDeskDockEnablesAccelerometer=");
7219 pw.println(mDeskDockEnablesAccelerometer);
7220 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
7221 pw.print(mLidKeyboardAccessibility);
7222 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007223 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007224 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007225 pw.print(prefix);
7226 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
7227 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07007228 pw.print(prefix);
7229 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
7230 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007231 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07007232 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
7233 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
7234 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
7235 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
7236 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
7237 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
7238 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08007239 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
7240 pw.print(","); pw.print(mOverscanScreenTop);
7241 pw.print(") "); pw.print(mOverscanScreenWidth);
7242 pw.print("x"); pw.println(mOverscanScreenHeight);
7243 if (mOverscanLeft != 0 || mOverscanTop != 0
7244 || mOverscanRight != 0 || mOverscanBottom != 0) {
7245 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
7246 pw.print(" top="); pw.print(mOverscanTop);
7247 pw.print(" right="); pw.print(mOverscanRight);
7248 pw.print(" bottom="); pw.println(mOverscanBottom);
7249 }
Dianne Hackborn313440842013-02-19 19:22:59 -08007250 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
7251 pw.print(mRestrictedOverscanScreenLeft);
7252 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
7253 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
7254 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007255 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
7256 pw.print(","); pw.print(mUnrestrictedScreenTop);
7257 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
7258 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
7259 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
7260 pw.print(","); pw.print(mRestrictedScreenTop);
7261 pw.print(") "); pw.print(mRestrictedScreenWidth);
7262 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07007263 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
7264 pw.print(","); pw.print(mStableFullscreenTop);
7265 pw.print(")-("); pw.print(mStableFullscreenRight);
7266 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07007267 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
7268 pw.print(","); pw.print(mStableTop);
7269 pw.print(")-("); pw.print(mStableRight);
7270 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007271 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7272 pw.print(","); pw.print(mSystemTop);
7273 pw.print(")-("); pw.print(mSystemRight);
7274 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007275 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
7276 pw.print(","); pw.print(mCurTop);
7277 pw.print(")-("); pw.print(mCurRight);
7278 pw.print(","); pw.print(mCurBottom); pw.println(")");
7279 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
7280 pw.print(","); pw.print(mContentTop);
7281 pw.print(")-("); pw.print(mContentRight);
7282 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07007283 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
7284 pw.print(","); pw.print(mVoiceContentTop);
7285 pw.print(")-("); pw.print(mVoiceContentRight);
7286 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007287 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
7288 pw.print(","); pw.print(mDockTop);
7289 pw.print(")-("); pw.print(mDockRight);
7290 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007291 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
7292 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007293 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
7294 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07007295 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
7296 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007297 if (mLastInputMethodWindow != null) {
7298 pw.print(prefix); pw.print("mLastInputMethodWindow=");
7299 pw.println(mLastInputMethodWindow);
7300 }
7301 if (mLastInputMethodTargetWindow != null) {
7302 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
7303 pw.println(mLastInputMethodTargetWindow);
7304 }
7305 if (mStatusBar != null) {
7306 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08007307 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
7308 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007309 }
7310 if (mNavigationBar != null) {
7311 pw.print(prefix); pw.print("mNavigationBar=");
7312 pw.println(mNavigationBar);
7313 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007314 if (mFocusedWindow != null) {
7315 pw.print(prefix); pw.print("mFocusedWindow=");
7316 pw.println(mFocusedWindow);
7317 }
7318 if (mFocusedApp != null) {
7319 pw.print(prefix); pw.print("mFocusedApp=");
7320 pw.println(mFocusedApp);
7321 }
7322 if (mWinDismissingKeyguard != null) {
7323 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
7324 pw.println(mWinDismissingKeyguard);
7325 }
7326 if (mTopFullscreenOpaqueWindowState != null) {
7327 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7328 pw.println(mTopFullscreenOpaqueWindowState);
7329 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007330 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7331 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7332 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7333 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007334 if (mForcingShowNavBar) {
7335 pw.print(prefix); pw.print("mForcingShowNavBar=");
7336 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7337 pw.println(mForcingShowNavBarLayer);
7338 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007339 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007340 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007341 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7342 pw.print(" mForceStatusBarFromKeyguard=");
7343 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007344 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007345 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007346 pw.print(" mHomePressed="); pw.println(mHomePressed);
7347 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7348 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7349 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7350 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7351 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7352 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7353 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7354 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7355 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7356 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007357 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7358 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7359 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007360
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007361 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007362 mStatusBarController.dump(pw, prefix);
7363 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007364 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007365
Jeff Browna20dda42014-05-27 20:57:24 -07007366 if (mWakeGestureListener != null) {
7367 mWakeGestureListener.dump(pw, prefix);
7368 }
Jeff Brown600f0032014-05-22 17:06:00 -07007369 if (mOrientationListener != null) {
7370 mOrientationListener.dump(pw, prefix);
7371 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007372 if (mBurnInProtectionHelper != null) {
7373 mBurnInProtectionHelper.dump(prefix, pw);
7374 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007375 if (mKeyguardDelegate != null) {
7376 mKeyguardDelegate.dump(prefix, pw);
7377 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007378 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007379}