blob: 44afbcc1052a3fc480718466a7cbe7e19c5e7f25 [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;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070028import static android.view.WindowManager.LayoutParams.*;
Jaewan Kim49117872016-01-19 17:24:08 +090029import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVERED;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070030import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_COVER_ABSENT;
31import static android.view.WindowManagerPolicy.WindowManagerFuncs.CAMERA_LENS_UNCOVERED;
Jaewan Kim49117872016-01-19 17:24:08 +090032import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_ABSENT;
33import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_CLOSED;
34import static android.view.WindowManagerPolicy.WindowManagerFuncs.LID_OPEN;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -070035
Dianne Hackborna4972e92012-03-14 10:38:05 -070036import android.app.ActivityManager;
Jorim Jaggi86905582016-02-09 21:36:09 -080037import android.app.ActivityManager.StackId;
Jeff Brown061ea992015-04-17 19:55:47 -070038import android.app.ActivityManagerInternal;
39import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080040import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080041import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040042import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070043import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070044import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040045import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080046import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070047import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080048import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040049import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080050import android.content.ContentResolver;
51import android.content.Context;
52import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070053import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070054import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080055import android.content.pm.ActivityInfo;
56import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040057import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070058import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080059import android.content.res.Configuration;
60import android.content.res.Resources;
61import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080062import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080063import android.graphics.Rect;
Jinsuk Kime601b712015-07-07 08:01:02 +090064import android.hardware.hdmi.HdmiControlManager;
65import android.hardware.hdmi.HdmiPlaybackClient;
66import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
John Spurlock7b414672014-07-18 13:02:39 -040067import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080068import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050069import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080070import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070071import android.media.Ringtone;
72import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070073import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +010074import android.os.Binder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070075import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080076import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070077import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080078import android.os.Handler;
79import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070080import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080081import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070082import android.os.Message;
83import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080084import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -070085import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +010086import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080087import android.os.RemoteException;
88import android.os.ServiceManager;
89import android.os.SystemClock;
90import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080091import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070092import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080093import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070094import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080095import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070096import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040097import android.service.dreams.DreamService;
98import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -070099import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700100import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700101import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800102import android.util.EventLog;
103import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -0700104import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -0800105import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700106import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800107import android.view.Gravity;
108import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800109import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800110import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -0700111import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -0700112import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -0800113import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800114import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800115import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -0800116import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800117import android.view.KeyEvent;
118import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800119import android.view.Surface;
120import android.view.View;
121import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800122import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800123import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700124import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800125import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800126import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800127import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800128import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200129import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800130import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800131import com.android.internal.R;
Jason Monk8f7f3182015-11-18 16:35:14 -0500132import com.android.internal.logging.MetricsLogger;
133import com.android.internal.policy.PhoneWindow;
Craig Mautnerae446592012-12-06 19:05:05 -0800134import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700135import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800136import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700137import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700138import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100139import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700140import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Jorim Jaggi86905582016-02-09 21:36:09 -0800141import com.android.server.statusbar.StatusBarManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800142
143import java.io.File;
144import java.io.FileReader;
145import java.io.IOException;
146import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700147import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800148import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800149
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800150/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700151 * WindowManagerPolicy implementation for the Android phone UI. This
152 * introduces a new method suffix, Lp, for an internal lock of the
153 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400154 * 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 -0700155 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800156 */
157public class PhoneWindowManager implements WindowManagerPolicy {
158 static final String TAG = "WindowManager";
159 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700160 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700161 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700162 static final boolean DEBUG_KEYGUARD = false;
163 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700164 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700165 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800166 static final boolean SHOW_STARTING_ANIMATIONS = true;
167 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400168
Daniel Sandler6396c722013-04-16 20:19:09 -0400169 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
keunyounga7710492015-09-23 11:33:58 -0700170 // No longer recommended for desk docks;
Daniel Sandler6396c722013-04-16 20:19:09 -0400171 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
172
Jeff Brown6d8fd272014-05-20 21:24:38 -0700173 static final int SHORT_PRESS_POWER_NOTHING = 0;
174 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
175 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
176 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800177 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700178
Joe Onoratod208e702010-10-08 16:22:43 -0400179 static final int LONG_PRESS_POWER_NOTHING = 0;
180 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
181 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700182 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700183
Jeff Brown13f00f02014-10-31 14:45:50 -0700184 static final int MULTI_PRESS_POWER_NOTHING = 0;
185 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
186 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
187
Michael Jurka3b1fc472011-06-13 10:54:40 -0700188 // These need to match the documentation/constant in
189 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800190 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800191 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700192 static final int LONG_PRESS_HOME_ASSIST = 2;
Jaewan Kim76b7d0d2016-02-12 19:01:02 +0900193 static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST;
Jeff Browncaca8812013-05-09 13:34:33 -0700194
195 static final int DOUBLE_TAP_HOME_NOTHING = 0;
196 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800197
Jaewan Kim49117872016-01-19 17:24:08 +0900198 static final int SHORT_PRESS_WINDOW_NOTHING = 0;
199 static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1;
200
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000201 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
202 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
203
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700204 static final int APPLICATION_MEDIA_SUBLAYER = -2;
205 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800206 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800207 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700208 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700209
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800210 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
211 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
212 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500213 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700214 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800215
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700216 /**
217 * These are the system UI flags that, when changing, can cause the layout
218 * of the screen to change.
219 */
220 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400221 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400222 | View.SYSTEM_UI_FLAG_FULLSCREEN
223 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200224 | View.NAVIGATION_BAR_TRANSLUCENT
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800225 | View.STATUS_BAR_TRANSPARENT
226 | View.NAVIGATION_BAR_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700227
John Spurlock7b414672014-07-18 13:02:39 -0400228 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
229 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
230 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
231 .build();
232
Adrian Roosddc8b272015-05-21 16:28:27 -0700233 // The panic gesture may become active only after the keyguard is dismissed and the immersive
234 // app shows again. If that doesn't happen for 30s we drop the gesture.
235 private static final long PANIC_GESTURE_EXPIRATION = 30000;
236
Jim Miller5ecd8112013-01-09 18:50:26 -0800237 /**
238 * Keyguard stuff
239 */
240 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100241 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700242 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800243
Jeff Brown6651a632011-11-28 12:59:11 -0800244 /* Table of Application Launch keys. Maps from key codes to intent categories.
245 *
246 * These are special keys that are used to launch particular kinds of applications,
247 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
248 * usage page. We don't support quite that many yet...
249 */
250 static SparseArray<String> sApplicationLaunchKeyCategories;
251 static {
252 sApplicationLaunchKeyCategories = new SparseArray<String>();
253 sApplicationLaunchKeyCategories.append(
254 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
255 sApplicationLaunchKeyCategories.append(
256 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
257 sApplicationLaunchKeyCategories.append(
258 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
259 sApplicationLaunchKeyCategories.append(
260 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
261 sApplicationLaunchKeyCategories.append(
262 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
263 sApplicationLaunchKeyCategories.append(
264 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
265 }
266
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700267 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700268 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700269
Dianne Hackborndf89e652011-10-06 22:35:11 -0700270 /**
271 * Lock protecting internal state. Must not call out into window
272 * manager with lock held. (This lock will be acquired in places
273 * where the window manager is calling in with its own lock held.)
274 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800275 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700276
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800277 Context mContext;
278 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700279 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700280 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700281 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700282 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700283 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100284 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400285 IStatusBarService mStatusBarService;
Jorim Jaggi86905582016-02-09 21:36:09 -0800286 StatusBarManagerInternal mStatusBarManagerInternal;
Jeff Browncaca8812013-05-09 13:34:33 -0700287 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700288 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800289 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700290 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800291 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000292 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100293 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800294
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700295 // Vibrator pattern for haptic feedback of a long press.
296 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700297
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700298 // Vibrator pattern for haptic feedback of virtual key press.
299 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700300
Amith Yamasanic33cb712010-02-10 15:21:49 -0800301 // Vibrator pattern for a short vibration.
302 long[] mKeyboardTapVibePattern;
303
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700304 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
305 long[] mClockTickVibePattern;
306
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700307 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
308 long[] mCalendarDateVibePattern;
309
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700310 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
311 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700312
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700313 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
314 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700315
Mady Mellore8608912015-06-05 09:02:55 -0700316 // Vibrator pattern for haptic feedback of a context click.
317 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700318
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800319 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
320 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400321
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800322 boolean mSafeMode;
323 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700324 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400325 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400326 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700327 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400328 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
329 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -0800330 int[] mNavigationBarHeightForRotationDefault = new int[4];
331 int[] mNavigationBarWidthForRotationDefault = new int[4];
332 int[] mNavigationBarHeightForRotationInCarMode = new int[4];
333 int[] mNavigationBarWidthForRotationInCarMode = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400334
keunyounga7710492015-09-23 11:33:58 -0700335 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
336 // This is for car dock and this is updated from resource.
337 private boolean mEnableCarDockHomeCapture = true;
338
Craig Mautnera631d492014-08-05 15:16:01 -0700339 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800340 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700341 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700342 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700343 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700344 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
345 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
346 }
347 };
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700348 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700349 @Override
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700350 public void onDrawn() {
351 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700352 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
353 }
354 };
355
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800356 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800357 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900358 WindowState mLastInputMethodWindow = null;
359 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800360
Jeff Brown13f00f02014-10-31 14:45:50 -0700361 // FIXME This state is shared between the input reader and handler thread.
362 // Technically it's broken and buggy but it has been like this for many years
363 // and we have not yet seen any problems. Someday we'll rewrite this logic
364 // so that only one thread is involved in handling input policy. Unfortunately
365 // it's on a critical path for power management so we can't just post the work to the
366 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
367 // to hold wakelocks during dispatch and eliminating the critical path.
368 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800369 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700370 volatile int mPowerKeyPressCounter;
371 volatile boolean mEndCallKeyHandled;
372
Winson Chungd42a6cf2014-06-03 16:24:04 -0700373 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700374 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700375 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800376
Jeff Brown2e7760e2012-04-11 15:14:55 -0700377 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700378 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700379 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800380
Dianne Hackbornc777e072010-02-12 13:07:59 -0800381 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700382 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700383 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800384 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900385 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700386 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400387 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700388 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700389 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400390 int mCarDockRotation;
391 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700392 int mUndockedHdmiRotation;
393 int mDemoHdmiRotation;
394 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800395 int mDemoRotation;
396 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400397
Jeff Browna20dda42014-05-27 20:57:24 -0700398 boolean mWakeGestureEnabledSetting;
399 MyWakeGestureListener mWakeGestureListener;
400
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700401 // Default display does not rotate, apps that require non-default orientation will have to
402 // have the orientation emulated.
403 private boolean mForceDefaultOrientation = false;
404
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400405 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
406 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700407 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400408
Jeff Brownbcdfc622014-03-06 19:13:04 -0800409 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700410 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400411 boolean mCarDockEnablesAccelerometer;
412 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700413 int mLidKeyboardAccessibility;
414 int mLidNavigationAccessibility;
Edward Savage-Jones7def60d2015-11-13 13:27:03 +0100415 boolean mLidControlsScreenLock;
Jeff Brownc458ce92012-04-30 14:58:40 -0700416 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700417 int mShortPressOnPowerBehavior;
418 int mLongPressOnPowerBehavior;
419 int mDoublePressOnPowerBehavior;
420 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000421 int mShortPressOnSleepBehavior;
Jaewan Kim49117872016-01-19 17:24:08 +0900422 int mShortPressWindowBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700423 boolean mAwake;
424 boolean mScreenOnEarly;
425 boolean mScreenOnFully;
426 ScreenOnListener mScreenOnListener;
427 boolean mKeyguardDrawComplete;
428 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800429 boolean mOrientationSensorEnabled = false;
430 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800431 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400432 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800433 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700434
Jeff Brown70825162012-03-28 17:27:48 -0700435 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800436
437 // The last window we were told about in focusChanged.
438 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800439 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800440
Jeff Brown70825162012-03-28 17:27:48 -0700441 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800442
Dianne Hackbornc652de82013-02-15 16:32:56 -0800443 // The current size of the screen; really; extends into the overscan area of
444 // the screen and doesn't account for any system elements like the status bar.
445 int mOverscanScreenLeft, mOverscanScreenTop;
446 int mOverscanScreenWidth, mOverscanScreenHeight;
447 // The current visible size of the screen; really; (ir)regardless of whether the status
448 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800449 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
450 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800451 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
452 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
453 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700454 // The current size of the screen; these may be different than (0,0)-(dw,dh)
455 // if the status bar can't be hidden; in that case it effectively carves out
456 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800457 int mRestrictedScreenLeft, mRestrictedScreenTop;
458 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700459 // During layout, the current screen borders accounting for any currently
460 // visible system UI elements.
461 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700462 // For applications requesting stable content insets, these are them.
463 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700464 // For applications requesting stable content insets but have also set the
465 // fullscreen window flag, these are the stable dimensions without the status bar.
466 int mStableFullscreenLeft, mStableFullscreenTop;
467 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800468 // During layout, the current screen borders with all outer decoration
469 // (status bar, input method dock) accounted for.
470 int mCurLeft, mCurTop, mCurRight, mCurBottom;
471 // During layout, the frame in which content should be displayed
472 // to the user, accounting for all screen decoration except for any
473 // space they deem as available for other content. This is usually
474 // the same as mCur*, but may be larger if the screen decor has supplied
475 // content insets.
476 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700477 // During layout, the frame in which voice content should be displayed
478 // to the user, accounting for all screen decoration except for any
479 // space they deem as available for other content.
480 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800481 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800482 // windows are placed.
483 int mDockLeft, mDockTop, mDockRight, mDockBottom;
484 // During layout, the layer at which the doc window is placed.
485 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700486 // During layout, this is the layer of the status bar.
487 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700488 int mLastSystemUiFlags;
489 // Bits that we are in the process of clearing, so we want to prevent
490 // them from being set by applications until everything has been updated
491 // to have them clear.
492 int mResettingSystemUiFlags = 0;
493 // Bits that we are currently always keeping cleared.
494 int mForceClearedSystemUiFlags = 0;
Jorim Jaggi86905582016-02-09 21:36:09 -0800495 int mLastFullscreenStackSysUiFlags;
496 int mLastDockedStackSysUiFlags;
497 final Rect mNonDockedStackBounds = new Rect();
498 final Rect mDockedStackBounds = new Rect();
499 final Rect mLastNonDockedStackBounds = new Rect();
500 final Rect mLastDockedStackBounds = new Rect();
501
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800502 // What we last reported to system UI about whether the compatibility
503 // menu needs to be displayed.
504 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700505 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
506 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700507
Selim Cinekf83e8242015-05-19 18:08:14 -0700508 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700509
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800510 static final Rect mTmpParentFrame = new Rect();
511 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800512 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800513 static final Rect mTmpContentFrame = new Rect();
514 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400515 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700516 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700517 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700518 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700519
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800520 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100521 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Jorim Jaggi86905582016-02-09 21:36:09 -0800522 WindowState mTopDockedOpaqueWindowState;
523 WindowState mTopDockedOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700524 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200525 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400526 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800527 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700528 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700529 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700530 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800531 boolean mForcingShowNavBar;
532 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700533
534 // States of keyguard dismiss.
535 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
536 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
537 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
538 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
539
540 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
541 * be done once per window. */
542 private WindowState mWinDismissingKeyguard;
543
tingna_sunge785ffa2015-05-12 13:23:15 +0800544 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
545 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
546 * lock SIM card. This variable is used to record the previous keyguard secure state for
547 * monitoring secure state change on window dismissing keyguard. */
548 private boolean mSecureDismissingKeyguard;
549
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700550 /** The window that is currently showing "over" the keyguard. If there is an app window
551 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
552 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
553 * the wallpaper. */
554 private WindowState mWinShowWhenLocked;
555
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700556 boolean mShowingLockscreen;
557 boolean mShowingDream;
558 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700559 boolean mDreamingSleepTokenNeeded;
560 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700561 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700562 boolean mKeyguardSecure;
563 boolean mKeyguardSecureIncludingHidden;
564 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800565 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700566 boolean mHomeConsumed;
567 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800568 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700569 Intent mCarDockIntent;
570 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700571 boolean mSearchKeyShortcutPending;
572 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700573 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700574 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800575
Mike Lockwood28569302010-01-28 11:54:40 -0500576 // support for activating the lock screen while the screen is on
577 boolean mAllowLockscreenWhenOn;
578 int mLockScreenTimeout;
579 boolean mLockScreenTimerActive;
580
David Brownbaf8d092010-03-08 21:52:59 -0800581 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800582 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800583
584 // Behavior of POWER button while in-call and screen on.
585 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
586 int mIncallPowerBehavior;
587
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700588 Display mDisplay;
589
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700590 private int mDisplayRotation;
591
Dianne Hackborn9d132642011-04-21 17:26:39 -0700592 int mLandscapeRotation = 0; // default landscape rotation
593 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
594 int mPortraitRotation = 0; // default portrait rotation
595 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700596
Dianne Hackbornc652de82013-02-15 16:32:56 -0800597 int mOverscanLeft = 0;
598 int mOverscanTop = 0;
599 int mOverscanRight = 0;
600 int mOverscanBottom = 0;
601
Joe Onorato46b0d682010-11-22 17:37:27 -0800602 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700603 private int mLongPressOnHomeBehavior;
604
605 // What we do when the user double-taps on home
606 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800607
Bryce Lee584a4452014-10-21 15:55:55 -0700608 // Allowed theater mode wake actions
609 private boolean mAllowTheaterModeWakeFromKey;
610 private boolean mAllowTheaterModeWakeFromPowerKey;
611 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800612 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700613 private boolean mAllowTheaterModeWakeFromCameraLens;
614 private boolean mAllowTheaterModeWakeFromLidSwitch;
615 private boolean mAllowTheaterModeWakeFromWakeGesture;
616
Bryce Leed3b28402015-03-09 15:49:13 +0000617 // Whether to support long press from power button in non-interactive mode
618 private boolean mSupportLongPressPowerWhenNonInteractive;
619
Bryce Lee55e846d2014-11-04 12:43:44 -0800620 // Whether to go to sleep entering theater mode from power button
621 private boolean mGoToSleepOnButtonPressTheaterMode;
622
Winson Chung9112ec32011-06-27 13:15:32 -0700623 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700624 // Time to volume and power must be pressed within this interval of each other.
625 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700626 // Increase the chord delay when taking a screenshot from the keyguard
627 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800628 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700629 private boolean mScreenshotChordVolumeDownKeyTriggered;
630 private long mScreenshotChordVolumeDownKeyTime;
631 private boolean mScreenshotChordVolumeDownKeyConsumed;
632 private boolean mScreenshotChordVolumeUpKeyTriggered;
633 private boolean mScreenshotChordPowerKeyTriggered;
634 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700635
Michael Wrightb854e242013-02-05 17:54:02 -0800636 /* The number of steps between min and max brightness */
637 private static final int BRIGHTNESS_STEPS = 10;
638
Christopher Tate5e08af02012-09-21 17:17:22 -0700639 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800640 ShortcutManager mShortcutManager;
641 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700642 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700643 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800644
Craig Mautnerd625ab22013-09-06 13:40:31 -0700645 private int mCurrentUserId;
646
Justin Kohd378ad72013-04-01 12:18:26 -0700647 // Maps global key codes to the components that will handle them.
648 private GlobalKeyManager mGlobalKeyManager;
649
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700650 // Fallback actions by key code.
651 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
652 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800653
Jorim Jaggi76a16232014-08-08 17:00:47 +0200654 private final LogDecelerateInterpolator mLogDecelerateInterpolator
655 = new LogDecelerateInterpolator(100, 0);
656
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800657 private boolean mForceWindowDrawsStatusBarBackground;
658
Jeff Brown70825162012-03-28 17:27:48 -0700659 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
660 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700661 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
662 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700663 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
664 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
665 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700666 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700667 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700668 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700669 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700670 private static final int MSG_POWER_DELAYED_PRESS = 13;
671 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700672 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700673 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
Jaewan Kimc552b042016-01-18 16:08:45 +0900674 private static final int MSG_REQUEST_TV_PICTURE_IN_PICTURE = 17;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700675
676 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
677 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700678
679 private class PolicyHandler extends Handler {
680 @Override
681 public void handleMessage(Message msg) {
682 switch (msg.what) {
683 case MSG_ENABLE_POINTER_LOCATION:
684 enablePointerLocation();
685 break;
686 case MSG_DISABLE_POINTER_LOCATION:
687 disablePointerLocation();
688 break;
Jeff Brown40013652012-05-16 21:22:36 -0700689 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
690 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
691 break;
692 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
693 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
694 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700695 case MSG_DISPATCH_SHOW_RECENTS:
696 showRecentApps(false);
697 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700698 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
699 showGlobalActionsInternal();
700 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700701 case MSG_KEYGUARD_DRAWN_COMPLETE:
702 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700703 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700704 break;
705 case MSG_KEYGUARD_DRAWN_TIMEOUT:
706 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700707 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700708 break;
709 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
710 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700711 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700712 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700713 case MSG_HIDE_BOOT_MESSAGE:
714 handleHideBootMessage();
715 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700716 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
717 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
718 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700719 case MSG_POWER_DELAYED_PRESS:
720 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
721 finishPowerKeyPress();
722 break;
723 case MSG_POWER_LONG_PRESS:
724 powerLongPress();
725 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700726 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
727 updateDreamingSleepToken(msg.arg1 != 0);
728 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700729 case MSG_REQUEST_TRANSIENT_BARS:
730 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
731 mStatusBar : mNavigationBar;
732 if (targetBar != null) {
733 requestTransientBars(targetBar);
734 }
735 break;
Jaewan Kimc552b042016-01-18 16:08:45 +0900736 case MSG_REQUEST_TV_PICTURE_IN_PICTURE:
737 requestTvPictureInPictureInternal();
738 break;
Jeff Brown70825162012-03-28 17:27:48 -0700739 }
740 }
741 }
742
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800743 private UEventObserver mHDMIObserver = new UEventObserver() {
744 @Override
745 public void onUEvent(UEventObserver.UEvent event) {
746 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
747 }
748 };
749
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800750 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800751 SettingsObserver(Handler handler) {
752 super(handler);
753 }
David Brownbaf8d092010-03-08 21:52:59 -0800754
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800755 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700756 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800757 ContentResolver resolver = mContext.getContentResolver();
758 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700759 Settings.System.END_BUTTON_BEHAVIOR), false, this,
760 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800761 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700762 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
763 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700764 resolver.registerContentObserver(Settings.Secure.getUriFor(
765 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
766 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800767 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700768 Settings.System.ACCELEROMETER_ROTATION), false, this,
769 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500770 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700771 Settings.System.USER_ROTATION), false, this,
772 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400773 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700774 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
775 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800776 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700777 Settings.System.POINTER_LOCATION), false, this,
778 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800779 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700780 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
781 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500782 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400783 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700784 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500785 resolver.registerContentObserver(Settings.Global.getUriFor(
786 Settings.Global.POLICY_CONTROL), false, this,
787 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800788 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800789 }
790
791 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800792 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700793 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800794 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800795 }
Craig Mautner967212c2013-04-13 21:10:58 -0700796
Jeff Browna20dda42014-05-27 20:57:24 -0700797 class MyWakeGestureListener extends WakeGestureListener {
798 MyWakeGestureListener(Context context, Handler handler) {
799 super(context, handler);
800 }
801
802 @Override
803 public void onWakeUp() {
804 synchronized (mLock) {
805 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700806 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700807 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
808 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700809 }
810 }
811 }
812 }
813
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800814 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700815 private final Runnable mUpdateRotationRunnable = new Runnable() {
816 @Override
817 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700818 // send interaction hint to improve redraw performance
819 mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700820 updateRotation(false);
821 }
822 };
823
Craig Mautnereee29c42013-01-17 14:44:34 -0800824 MyOrientationListener(Context context, Handler handler) {
825 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800826 }
Craig Mautner967212c2013-04-13 21:10:58 -0700827
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800828 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700829 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700830 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700831 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700832 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800833 }
834 MyOrientationListener mOrientationListener;
835
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100836 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400837
John Spurlock27735a42013-08-14 17:57:38 -0400838 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400839 View.NAVIGATION_BAR_TRANSIENT,
840 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400841 View.NAVIGATION_BAR_TRANSLUCENT,
842 StatusBarManager.WINDOW_NAVIGATION_BAR,
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800843 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
844 View.NAVIGATION_BAR_TRANSPARENT);
John Spurlock5b9145b2013-08-20 15:13:47 -0400845
John Spurlockf1a36642013-10-12 17:50:42 -0400846 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400847
Craig Mautner037aa8d2013-06-07 10:35:44 -0700848 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400849
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700850 IStatusBarService getStatusBarService() {
851 synchronized (mServiceAquireLock) {
852 if (mStatusBarService == null) {
853 mStatusBarService = IStatusBarService.Stub.asInterface(
854 ServiceManager.getService("statusbar"));
855 }
856 return mStatusBarService;
857 }
858 }
859
Jorim Jaggi86905582016-02-09 21:36:09 -0800860 StatusBarManagerInternal getStatusBarManagerInternal() {
861 synchronized (mServiceAquireLock) {
862 if (mStatusBarManagerInternal == null) {
863 mStatusBarManagerInternal =
864 LocalServices.getService(StatusBarManagerInternal.class);
865 }
866 return mStatusBarManagerInternal;
867 }
868 }
869
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700870 /*
871 * We always let the sensor be switched on by default except when
872 * the user has explicitly disabled sensor based rotation or when the
873 * screen is switched off.
874 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700875 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800876 if (mSupportAutoRotation) {
877 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
878 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
879 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
880 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
881 // If the application has explicitly requested to follow the
882 // orientation, then we need to turn the sensor on.
883 return true;
884 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800885 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700886 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800887 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
888 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
889 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400890 // enable accelerometer if we are docked in a dock that enables accelerometer
891 // orientation management,
892 return true;
893 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700894 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800895 // If the setting for using the sensor by default is enabled, then
896 // we will always leave it on. Note that the user could go to
897 // a window that forces an orientation that does not use the
898 // sensor and in theory we could turn it off... however, when next
899 // turning it on we won't have a good value for the current
900 // orientation for a little bit, which can cause orientation
901 // changes to lag, so we'd like to keep it always on. (It will
902 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700903 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800904 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800905 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800906 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700907
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800908 /*
909 * Various use cases for invoking this function
910 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700911 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800912 * if not already enabled
913 * screen turned on and current app does not have sensor orientation, disable listeners if
914 * already enabled
915 * screen turning on and current app has sensor based orientation, enable listeners if needed
916 * screen turning on and current app has nosensor based orientation, do nothing
917 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700918 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800919 if (!mOrientationListener.canDetectOrientation()) {
920 // If sensor is turned off or nonexistent for some reason
921 return;
922 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000923 // Could have been invoked due to screen turning on or off or
924 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700925 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
926 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000927 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
928 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
929 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800930 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000931 // Note: We postpone the rotating of the screen until the keyguard as well as the
932 // window manager have reported a draw complete.
933 if (mScreenOnEarly && mAwake &&
934 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700935 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800936 disable = false;
937 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700938 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800939 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700940 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800941 mOrientationSensorEnabled = true;
942 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700943 }
944 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800945 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700946 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800947 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700948 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800949 mOrientationSensorEnabled = false;
950 }
951 }
952
Jeff Brown13f00f02014-10-31 14:45:50 -0700953 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
954 // Hold a wake lock until the power key is released.
955 if (!mPowerKeyWakeLock.isHeld()) {
956 mPowerKeyWakeLock.acquire();
957 }
958
959 // Cancel multi-press detection timeout.
960 if (mPowerKeyPressCounter != 0) {
961 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
962 }
963
964 // Detect user pressing the power button in panic when an application has
965 // taken over the whole screen.
966 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800967 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700968 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700969 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700970 }
971
972 // Latch power key state to detect screenshot chord.
973 if (interactive && !mScreenshotChordPowerKeyTriggered
974 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
975 mScreenshotChordPowerKeyTriggered = true;
976 mScreenshotChordPowerKeyTime = event.getDownTime();
977 interceptScreenshotChord();
978 }
979
980 // Stop ringing or end call if configured to do so when power is pressed.
981 TelecomManager telecomManager = getTelecommService();
982 boolean hungUp = false;
983 if (telecomManager != null) {
984 if (telecomManager.isRinging()) {
985 // Pressing Power while there's a ringing incoming
986 // call should silence the ringer.
987 telecomManager.silenceRinger();
988 } else if ((mIncallPowerBehavior
989 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
990 && telecomManager.isInCall() && interactive) {
991 // Otherwise, if "Power button ends call" is enabled,
992 // the Power button will hang up any current active call.
993 hungUp = telecomManager.endCall();
994 }
995 }
996
Adrian Roos5941c982015-09-03 15:59:49 -0700997 GestureLauncherService gestureService = LocalServices.getService(
998 GestureLauncherService.class);
999 boolean gesturedServiceIntercepted = false;
1000 if (gestureService != null) {
1001 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive);
1002 }
1003
Jeff Brown13f00f02014-10-31 14:45:50 -07001004 // If the power key has still not yet been handled, then detect short
1005 // press, long press, or multi press and decide what to do.
1006 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -07001007 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -07001008 if (!mPowerKeyHandled) {
1009 if (interactive) {
1010 // When interactive, we're already awake.
1011 // Wait for a long press or for the button to be released to decide what to do.
1012 if (hasLongPressOnPowerBehavior()) {
1013 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1014 msg.setAsynchronous(true);
1015 mHandler.sendMessageDelayed(msg,
1016 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1017 }
1018 } else {
Bryce Leed9268e32014-11-17 17:40:59 -08001019 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -08001020
Bryce Leed3b28402015-03-09 15:49:13 +00001021 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
1022 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1023 msg.setAsynchronous(true);
1024 mHandler.sendMessageDelayed(msg,
1025 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -08001026 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +00001027 } else {
1028 final int maxCount = getMaxMultiPressPowerCount();
1029
1030 if (maxCount <= 1) {
1031 mPowerKeyHandled = true;
1032 } else {
1033 mBeganFromNonInteractive = true;
1034 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001035 }
1036 }
Jeff Brown4d396052010-10-29 21:50:21 -07001037 }
1038 }
1039
Jeff Brown13f00f02014-10-31 14:45:50 -07001040 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
1041 final boolean handled = canceled || mPowerKeyHandled;
1042 mScreenshotChordPowerKeyTriggered = false;
1043 cancelPendingScreenshotChordAction();
1044 cancelPendingPowerKeyAction();
1045
1046 if (!handled) {
1047 // Figure out how to handle the key now that it has been released.
1048 mPowerKeyPressCounter += 1;
1049
1050 final int maxCount = getMaxMultiPressPowerCount();
1051 final long eventTime = event.getDownTime();
1052 if (mPowerKeyPressCounter < maxCount) {
1053 // This could be a multi-press. Wait a little bit longer to confirm.
1054 // Continue holding the wake lock.
1055 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1056 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1057 msg.setAsynchronous(true);
1058 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1059 return;
1060 }
1061
1062 // No other actions. Handle it immediately.
1063 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001064 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001065
1066 // Done. Reset our state.
1067 finishPowerKeyPress();
1068 }
1069
1070 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001071 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001072 mPowerKeyPressCounter = 0;
1073 if (mPowerKeyWakeLock.isHeld()) {
1074 mPowerKeyWakeLock.release();
1075 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001076 }
1077
1078 private void cancelPendingPowerKeyAction() {
1079 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001080 mPowerKeyHandled = true;
1081 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001082 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001083 }
1084
1085 private void powerPress(long eventTime, boolean interactive, int count) {
1086 if (mScreenOnEarly && !mScreenOnFully) {
1087 Slog.i(TAG, "Suppressed redundant power key press while "
1088 + "already in the process of turning the screen on.");
1089 return;
Jeff Brownff204712011-10-25 21:27:54 -07001090 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001091
1092 if (count == 2) {
1093 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1094 } else if (count == 3) {
1095 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001096 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001097 switch (mShortPressOnPowerBehavior) {
1098 case SHORT_PRESS_POWER_NOTHING:
1099 break;
1100 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1101 mPowerManager.goToSleep(eventTime,
1102 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1103 break;
1104 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1105 mPowerManager.goToSleep(eventTime,
1106 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1107 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1108 break;
1109 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1110 mPowerManager.goToSleep(eventTime,
1111 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1112 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1113 launchHomeFromHotKey();
1114 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001115 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001116 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001117 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001118 }
1119 }
1120 }
1121
1122 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1123 switch (behavior) {
1124 case MULTI_PRESS_POWER_NOTHING:
1125 break;
1126 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001127 if (!isUserSetupComplete()) {
1128 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1129 break;
1130 }
1131
Jeff Brown13f00f02014-10-31 14:45:50 -07001132 if (isTheaterModeEnabled()) {
1133 Slog.i(TAG, "Toggling theater mode off.");
1134 Settings.Global.putInt(mContext.getContentResolver(),
1135 Settings.Global.THEATER_MODE_ON, 0);
1136 if (!interactive) {
1137 wakeUpFromPowerKey(eventTime);
1138 }
1139 } else {
1140 Slog.i(TAG, "Toggling theater mode on.");
1141 Settings.Global.putInt(mContext.getContentResolver(),
1142 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001143
1144 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001145 mPowerManager.goToSleep(eventTime,
1146 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1147 }
1148 }
1149 break;
1150 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001151 Slog.i(TAG, "Starting brightness boost.");
1152 if (!interactive) {
1153 wakeUpFromPowerKey(eventTime);
1154 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001155 mPowerManager.boostScreenBrightness(eventTime);
1156 break;
1157 }
1158 }
1159
1160 private int getMaxMultiPressPowerCount() {
1161 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1162 return 3;
1163 }
1164 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1165 return 2;
1166 }
1167 return 1;
1168 }
1169
1170 private void powerLongPress() {
1171 final int behavior = getResolvedLongPressOnPowerBehavior();
1172 switch (behavior) {
1173 case LONG_PRESS_POWER_NOTHING:
1174 break;
1175 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1176 mPowerKeyHandled = true;
1177 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1178 performAuditoryFeedbackForAccessibilityIfNeed();
1179 }
1180 showGlobalActionsInternal();
1181 break;
1182 case LONG_PRESS_POWER_SHUT_OFF:
1183 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1184 mPowerKeyHandled = true;
1185 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1186 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1187 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1188 break;
1189 }
1190 }
1191
Nick Vaccarob593a812015-05-15 11:23:05 -07001192 private void sleepPress(long eventTime) {
1193 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1194 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1195 }
1196 }
1197
1198 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001199 switch (mShortPressOnSleepBehavior) {
1200 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001201 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001202 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1203 mPowerManager.goToSleep(eventTime,
1204 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001205 break;
1206 }
1207 }
1208
Jeff Brown13f00f02014-10-31 14:45:50 -07001209 private int getResolvedLongPressOnPowerBehavior() {
1210 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1211 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1212 }
1213 return mLongPressOnPowerBehavior;
1214 }
1215
1216 private boolean hasLongPressOnPowerBehavior() {
1217 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001218 }
1219
1220 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001221 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001222 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1223 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001224 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001225 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1226 && now <= mScreenshotChordPowerKeyTime
1227 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1228 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001229 cancelPendingPowerKeyAction();
1230
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001231 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001232 }
1233 }
1234 }
1235
Winson Chung1cea2f32012-10-08 20:42:01 -07001236 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001237 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001238 // Double the time it takes to take a screenshot from the keyguard
1239 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001240 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001241 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001242 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001243 }
1244
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001245 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001246 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001247 }
1248
Jeff Brown13f00f02014-10-31 14:45:50 -07001249 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001250 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001251 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001252 mEndCallKeyHandled = true;
1253 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1254 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001255 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001256 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001257 }
1258 };
1259
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001260 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001261 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001262 public void run() {
1263 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001264 }
1265 };
1266
Alan Viverettee34560b22014-07-10 14:50:06 -07001267 @Override
1268 public void showGlobalActions() {
1269 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1270 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1271 }
1272
1273 void showGlobalActionsInternal() {
1274 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001275 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001276 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001277 }
Jim Millerab954542014-10-10 18:21:49 -07001278 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001279 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1280 if (keyguardShowing) {
1281 // since it took two seconds of long press to bring this up,
1282 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001283 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001284 }
1285 }
1286
1287 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001288 return Settings.Global.getInt(
1289 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001290 }
1291
Maurice Lam99c6e072014-04-28 18:24:28 -07001292 boolean isUserSetupComplete() {
1293 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1294 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1295 }
1296
Jeff Brown13f00f02014-10-31 14:45:50 -07001297 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001298 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1299 getHdmiControl().turnOnTv();
1300
Jeff Brown13f00f02014-10-31 14:45:50 -07001301 // If there's a dream running then use home to escape the dream
1302 // but don't actually go home.
1303 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1304 mDreamManagerInternal.stopDream(false /*immediate*/);
1305 return;
1306 }
1307
1308 // Go home!
1309 launchHomeFromHotKey();
1310 }
1311
Jinsuk Kime601b712015-07-07 08:01:02 +09001312 /**
1313 * Creates an accessor to HDMI control service that performs the operation of
1314 * turning on TV (optional) and switching input to us. If HDMI control service
1315 * is not available or we're not a HDMI playback device, the operation is no-op.
1316 */
1317 private HdmiControl getHdmiControl() {
1318 if (null == mHdmiControl) {
1319 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1320 Context.HDMI_CONTROL_SERVICE);
1321 HdmiPlaybackClient client = null;
1322 if (manager != null) {
1323 client = manager.getPlaybackClient();
1324 }
1325 mHdmiControl = new HdmiControl(client);
1326 }
1327 return mHdmiControl;
1328 }
1329
1330 private static class HdmiControl {
1331 private final HdmiPlaybackClient mClient;
1332
1333 private HdmiControl(HdmiPlaybackClient client) {
1334 mClient = client;
1335 }
1336
1337 public void turnOnTv() {
1338 if (mClient == null) {
1339 return;
1340 }
1341 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1342 @Override
1343 public void onComplete(int result) {
1344 if (result != HdmiControlManager.RESULT_SUCCESS) {
1345 Log.w(TAG, "One touch play failed: " + result);
1346 }
1347 }
1348 });
1349 }
1350 }
1351
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001352 private void handleLongPressOnHome(int deviceId) {
Jaewan Kim52632e22016-01-14 18:01:52 +09001353 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
1354 return;
1355 }
1356 mHomeConsumed = true;
1357 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001358
Jaewan Kim52632e22016-01-14 18:01:52 +09001359 switch (mLongPressOnHomeBehavior) {
1360 case LONG_PRESS_HOME_RECENT_SYSTEM_UI:
Jeff Browncaca8812013-05-09 13:34:33 -07001361 toggleRecentApps();
Jaewan Kim52632e22016-01-14 18:01:52 +09001362 break;
1363 case LONG_PRESS_HOME_ASSIST:
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001364 launchAssistAction(null, deviceId);
Jaewan Kim52632e22016-01-14 18:01:52 +09001365 break;
Jaewan Kim52632e22016-01-14 18:01:52 +09001366 default:
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001367 Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior);
Jaewan Kim52632e22016-01-14 18:01:52 +09001368 break;
Jim Millere6ad1a82010-08-20 19:25:39 -07001369 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001370 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001371
Jeff Browncaca8812013-05-09 13:34:33 -07001372 private void handleDoubleTapOnHome() {
1373 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1374 mHomeConsumed = true;
1375 toggleRecentApps();
1376 }
1377 }
1378
Jaewan Kimc552b042016-01-18 16:08:45 +09001379 private void requestTvPictureInPicture(KeyEvent event) {
1380 if (DEBUG_INPUT) Log.d(TAG, "requestTvPictureInPicture event=" + event);
1381 mHandler.removeMessages(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1382 Message msg = mHandler.obtainMessage(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1383 msg.setAsynchronous(true);
1384 msg.sendToTarget();
1385 }
1386
1387 private void requestTvPictureInPictureInternal() {
1388 try {
1389 IStatusBarService statusbar = getStatusBarService();
1390 if (statusbar != null) {
1391 statusbar.requestTvPictureInPicture();
1392 }
1393 } catch (RemoteException|IllegalArgumentException e) {
1394 Slog.e(TAG, "Cannot handle picture-in-picture key", e);
1395 // re-acquire status bar service next time it is needed.
1396 mStatusBarService = null;
1397 }
Jaewan Kim52632e22016-01-14 18:01:52 +09001398 }
1399
Jeff Browncaca8812013-05-09 13:34:33 -07001400 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1401 @Override
1402 public void run() {
1403 if (mHomeDoubleTapPending) {
1404 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001405 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001406 }
1407 }
1408 };
1409
Mark Renoufc1256912015-03-11 14:38:23 -04001410 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001411 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001412 }
1413
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001414 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001415 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001416 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001417 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001418 mContext = context;
1419 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001420 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001421 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001422 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001423 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001424 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001425 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001426
1427 // Init display burn-in protection
1428 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1429 com.android.internal.R.bool.config_enableBurnInProtection);
1430 // Allow a system property to override this. Used by developer settings.
1431 boolean burnInProtectionDevMode =
1432 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1433 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1434 final int minHorizontal;
1435 final int maxHorizontal;
1436 final int minVertical;
1437 final int maxVertical;
1438 final int maxRadius;
1439 if (burnInProtectionDevMode) {
1440 minHorizontal = -8;
1441 maxHorizontal = 8;
1442 minVertical = -8;
1443 maxVertical = -4;
1444 maxRadius = (isRoundWindow()) ? 6 : -1;
1445 } else {
1446 Resources resources = context.getResources();
1447 minHorizontal = resources.getInteger(
1448 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1449 maxHorizontal = resources.getInteger(
1450 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1451 minVertical = resources.getInteger(
1452 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1453 maxVertical = resources.getInteger(
1454 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1455 maxRadius = resources.getInteger(
1456 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1457 }
1458 mBurnInProtectionHelper = new BurnInProtectionHelper(
1459 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001460 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001461
Jeff Brown70825162012-03-28 17:27:48 -07001462 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001463 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001464 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001465 try {
1466 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1467 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001468 mSettingsObserver = new SettingsObserver(mHandler);
1469 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001470 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001471 mUiMode = context.getResources().getInteger(
1472 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001473 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1474 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1475 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1476 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001477 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1478 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001479 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1480 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1481 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1482 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1483 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1484 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1485 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1486 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001487
Jeff Brown96307042012-07-27 15:51:34 -07001488 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1489 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001490 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001491 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1492 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001493 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001494 mSupportAutoRotation = mContext.getResources().getBoolean(
1495 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001496 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001497 com.android.internal.R.integer.config_lidOpenRotation);
1498 mCarDockRotation = readRotation(
1499 com.android.internal.R.integer.config_carDockRotation);
1500 mDeskDockRotation = readRotation(
1501 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001502 mUndockedHdmiRotation = readRotation(
1503 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001504 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1505 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1506 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1507 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001508 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1509 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1510 mLidNavigationAccessibility = mContext.getResources().getInteger(
1511 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001512 mLidControlsScreenLock = mContext.getResources().getBoolean(
1513 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001514 mLidControlsSleep = mContext.getResources().getBoolean(
1515 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001516 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1517 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001518
1519 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1520 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1521 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1522 || mContext.getResources().getBoolean(
1523 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1524 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1525 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001526 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1527 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001528 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1529 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1530 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1531 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1532 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1533 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1534
Bryce Lee55e846d2014-11-04 12:43:44 -08001535 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1536 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1537
Bryce Leed3b28402015-03-09 15:49:13 +00001538 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1539 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1540
Jeff Brown13f00f02014-10-31 14:45:50 -07001541 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1542 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1543 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1544 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1545 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1546 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1547 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1548 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001549 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1550 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001551
John Spurlock61560172015-02-06 19:46:04 -05001552 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001553
Jeff Brownf71343d2013-05-31 17:59:11 -07001554 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001555
Svetoslav8e3feb12014-02-24 13:46:47 -08001556 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1557 Context.ACCESSIBILITY_SERVICE);
1558
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001559 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001560 IntentFilter filter = new IntentFilter();
1561 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1562 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1563 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1564 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001565 filter.addAction(Intent.ACTION_DOCK_EVENT);
1566 Intent intent = context.registerReceiver(mDockReceiver, filter);
1567 if (intent != null) {
1568 // Retrieve current sticky dock event broadcast.
1569 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1570 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1571 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001572
Jeff Brown6aaf2952012-10-05 16:01:08 -07001573 // register for dream-related broadcasts
1574 filter = new IntentFilter();
1575 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1576 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1577 context.registerReceiver(mDreamReceiver, filter);
1578
Christopher Tate5e08af02012-09-21 17:17:22 -07001579 // register for multiuser-relevant broadcasts
1580 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1581 context.registerReceiver(mMultiuserReceiver, filter);
1582
John Spurlock57306e62013-04-22 09:48:49 -04001583 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001584 mSystemGestures = new SystemGesturesPointerEventListener(context,
1585 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001586 @Override
1587 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001588 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001589 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001590 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001591 }
1592 @Override
1593 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001594 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001595 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001596 }
1597 }
1598 @Override
1599 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001600 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001601 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001602 }
1603 }
1604 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001605 public void onFling(int duration) {
1606 if (mPowerManagerInternal != null) {
1607 mPowerManagerInternal.powerHint(
1608 PowerManagerInternal.POWER_HINT_INTERACTION, duration);
1609 }
1610 }
1611 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001612 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001613 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001614 }
Adrian Roos3595be42015-03-05 16:31:15 +01001615 @Override
1616 public void onDown() {
1617 mOrientationListener.onTouchStart();
1618 }
1619 @Override
1620 public void onUpOrCancel() {
1621 mOrientationListener.onTouchEnd();
1622 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001623 @Override
1624 public void onMouseHoverAtTop() {
1625 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1626 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1627 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1628 mHandler.sendMessageDelayed(msg, 500);
1629 }
1630 @Override
1631 public void onMouseHoverAtBottom() {
1632 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1633 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1634 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1635 mHandler.sendMessageDelayed(msg, 500);
1636 }
1637 @Override
1638 public void onMouseLeaveFromEdge() {
1639 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1640 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001641 });
John Spurlockf1a36642013-10-12 17:50:42 -04001642 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001643 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001644
Jeff Brownc2346132012-04-13 01:55:38 -07001645 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001646 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1647 com.android.internal.R.array.config_longPressVibePattern);
1648 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1649 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001650 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1651 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001652 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1653 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001654 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1655 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001656 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1657 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1658 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1659 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001660 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1661 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001662
Christopher Tatee90585f2012-03-05 18:56:25 -08001663 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1664 com.android.internal.R.bool.config_enableScreenshotChord);
Jorim Jaggi406585a2015-12-21 10:58:56 +01001665 mForceWindowDrawsStatusBarBackground = mContext.getResources().getBoolean(
1666 R.bool.config_forceWindowDrawsStatusBarBackground);
Christopher Tatee90585f2012-03-05 18:56:25 -08001667
Justin Kohd378ad72013-04-01 12:18:26 -07001668 mGlobalKeyManager = new GlobalKeyManager(mContext);
1669
Joe Onoratoea495d42011-04-06 11:41:11 -07001670 // Controls rotation and the like.
1671 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001672
1673 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001674 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001675 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1676 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001677 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001678
1679 mWindowManagerInternal.registerAppTransitionListener(
1680 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001681 }
1682
Jeff Brownf71343d2013-05-31 17:59:11 -07001683 /**
1684 * Read values from config.xml that may be overridden depending on
1685 * the configuration of the device.
1686 * eg. Disable long press on home goes to recents on sw600dp.
1687 */
1688 private void readConfigurationDependentBehaviors() {
Jaewan Kimc552b042016-01-18 16:08:45 +09001689 final Resources res = mContext.getResources();
1690
1691 mLongPressOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001692 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1693 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Jaewan Kim52632e22016-01-14 18:01:52 +09001694 mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) {
Jeff Brownf71343d2013-05-31 17:59:11 -07001695 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1696 }
1697
Jaewan Kimc552b042016-01-18 16:08:45 +09001698 mDoubleTapOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001699 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1700 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1701 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1702 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1703 }
Jaewan Kim49117872016-01-19 17:24:08 +09001704
1705 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING;
1706 if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) {
1707 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE;
1708 }
Jeff Brownf71343d2013-05-31 17:59:11 -07001709 }
1710
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001711 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001712 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001713 // This method might be called before the policy has been fully initialized
1714 // or for other displays we don't care about.
1715 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1716 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001717 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001718 mDisplay = display;
1719
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001720 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001721 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001722 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001723 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001724 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001725 mLandscapeRotation = Surface.ROTATION_0;
1726 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001727 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001728 mPortraitRotation = Surface.ROTATION_90;
1729 mUpsideDownRotation = Surface.ROTATION_270;
1730 } else {
1731 mPortraitRotation = Surface.ROTATION_270;
1732 mUpsideDownRotation = Surface.ROTATION_90;
1733 }
1734 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001735 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001736 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001737 mPortraitRotation = Surface.ROTATION_0;
1738 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001739 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001740 mLandscapeRotation = Surface.ROTATION_270;
1741 mSeascapeRotation = Surface.ROTATION_90;
1742 } else {
1743 mLandscapeRotation = Surface.ROTATION_90;
1744 mSeascapeRotation = Surface.ROTATION_270;
1745 }
1746 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001747
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001748 mStatusBarHeight =
1749 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001750
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001751 // Height of the navigation bar when presented horizontally at bottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001752 mNavigationBarHeightForRotationDefault[mPortraitRotation] =
1753 mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001754 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001755 mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
1756 mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001757 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001758
1759 // Width of the navigation bar when presented vertically along one side
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001760 mNavigationBarWidthForRotationDefault[mPortraitRotation] =
1761 mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
1762 mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
1763 mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001764 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001765
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001766 // Height of the navigation bar when presented horizontally at bottom
1767 mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
1768 mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
1769 res.getDimensionPixelSize(
1770 com.android.internal.R.dimen.navigation_bar_height_car_mode);
1771 mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
1772 mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
1773 com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
1774
1775 // Width of the navigation bar when presented vertically along one side
1776 mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
1777 mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
1778 mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
1779 mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
1780 res.getDimensionPixelSize(
1781 com.android.internal.R.dimen.navigation_bar_width_car_mode);
1782
Daniel Sandler4a066c52012-04-20 14:49:13 -04001783 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001784 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001785 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001786
Devin Kimd7b12b42014-05-05 14:34:58 -07001787 // Allow the navigation bar to move on non-square small devices (phones).
1788 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001789
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001790 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001791 // Allow a system property to override this. Used by the emulator.
1792 // See also hasNavigationBar().
1793 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1794 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001795 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001796 } else if ("0".equals(navBarOverride)) {
1797 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001798 }
1799
Jeff Brown27f1d672012-10-17 18:32:34 -07001800 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1801 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001802 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001803 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001804 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001805 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001806 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001807 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001808
Chong Zhangae6119ff2014-11-11 18:54:39 -08001809 // For demo purposes, allow the rotation of the remote display to be controlled.
1810 // By default, remote display locks rotation to landscape.
1811 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1812 mDemoRotation = mPortraitRotation;
1813 } else {
1814 mDemoRotation = mLandscapeRotation;
1815 }
1816 mDemoRotationLock = SystemProperties.getBoolean(
1817 "persist.demo.rotationlock", false);
1818
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001819 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1820 // http://developer.android.com/guide/practices/screens_support.html#range
1821 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1822 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1823 // For debug purposes the next line turns this feature off with:
1824 // $ adb shell setprop config.override_forced_orient true
1825 // $ adb shell wm size reset
1826 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1827 }
1828
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001829 /**
1830 * @return whether the navigation bar can be hidden, e.g. the device has a
1831 * navigation bar and touch exploration is not enabled
1832 */
1833 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04001834 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001835 }
1836
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001837 @Override
1838 public boolean isDefaultOrientationForced() {
1839 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001840 }
1841
Dianne Hackbornc652de82013-02-15 16:32:56 -08001842 @Override
1843 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1844 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1845 mOverscanLeft = left;
1846 mOverscanTop = top;
1847 mOverscanRight = right;
1848 mOverscanBottom = bottom;
1849 }
1850 }
1851
Dianne Hackbornc777e072010-02-12 13:07:59 -08001852 public void updateSettings() {
1853 ContentResolver resolver = mContext.getContentResolver();
1854 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001855 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001856 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001857 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001858 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1859 UserHandle.USER_CURRENT);
1860 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001861 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001862 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1863 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001864
Jeff Browna20dda42014-05-27 20:57:24 -07001865 // Configure wake gesture.
1866 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1867 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1868 UserHandle.USER_CURRENT) != 0;
1869 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1870 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1871 updateWakeGestureListenerLp();
1872 }
1873
Jeff Brown207673cd2012-06-05 17:47:11 -07001874 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001875 int userRotation = Settings.System.getIntForUser(resolver,
1876 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1877 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001878 if (mUserRotation != userRotation) {
1879 mUserRotation = userRotation;
1880 updateRotation = true;
1881 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001882 int userRotationMode = Settings.System.getIntForUser(resolver,
1883 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001884 WindowManagerPolicy.USER_ROTATION_FREE :
1885 WindowManagerPolicy.USER_ROTATION_LOCKED;
1886 if (mUserRotationMode != userRotationMode) {
1887 mUserRotationMode = userRotationMode;
1888 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001889 updateOrientationListenerLp();
1890 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001891
Dianne Hackbornc777e072010-02-12 13:07:59 -08001892 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001893 int pointerLocation = Settings.System.getIntForUser(resolver,
1894 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001895 if (mPointerLocationMode != pointerLocation) {
1896 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001897 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1898 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001899 }
1900 }
1901 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001902 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1903 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1904 String imId = Settings.Secure.getStringForUser(resolver,
1905 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001906 boolean hasSoftInput = imId != null && imId.length() > 0;
1907 if (mHasSoftInput != hasSoftInput) {
1908 mHasSoftInput = hasSoftInput;
1909 updateRotation = true;
1910 }
John Spurlockf1a36642013-10-12 17:50:42 -04001911 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001912 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001913 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001914 }
1915 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001916 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001917 }
1918 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001919 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001920 }
Jeff Brown70825162012-03-28 17:27:48 -07001921 }
1922
Jeff Browna20dda42014-05-27 20:57:24 -07001923 private void updateWakeGestureListenerLp() {
1924 if (shouldEnableWakeGestureLp()) {
1925 mWakeGestureListener.requestWakeUpTrigger();
1926 } else {
1927 mWakeGestureListener.cancelWakeUpTrigger();
1928 }
1929 }
1930
1931 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001932 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001933 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1934 && mWakeGestureListener.isSupported();
1935 }
1936
Jeff Brown70825162012-03-28 17:27:48 -07001937 private void enablePointerLocation() {
1938 if (mPointerLocationView == null) {
1939 mPointerLocationView = new PointerLocationView(mContext);
1940 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001941 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1942 WindowManager.LayoutParams.MATCH_PARENT,
1943 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001944 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001945 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1946 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1947 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1948 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001949 if (ActivityManager.isHighEndGfx()) {
1950 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1951 lp.privateFlags |=
1952 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1953 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001954 lp.format = PixelFormat.TRANSLUCENT;
1955 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001956 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001957 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001958 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001959 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001960 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001961 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001962 }
Jeff Brown70825162012-03-28 17:27:48 -07001963
1964 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001965 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001966 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1967 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001968 wm.removeView(mPointerLocationView);
1969 mPointerLocationView = null;
1970 }
1971 }
1972
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001973 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001974 try {
1975 int rotation = mContext.getResources().getInteger(resID);
1976 switch (rotation) {
1977 case 0:
1978 return Surface.ROTATION_0;
1979 case 90:
1980 return Surface.ROTATION_90;
1981 case 180:
1982 return Surface.ROTATION_180;
1983 case 270:
1984 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001985 }
1986 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001987 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001988 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001989 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001990 }
1991
1992 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001993 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001994 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001995 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001996
1997 outAppOp[0] = AppOpsManager.OP_NONE;
1998
Wale Ogunwale74bf0652015-01-12 10:24:36 -08001999 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
2000 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
2001 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
2002 return WindowManagerGlobal.ADD_INVALID_TYPE;
2003 }
2004
2005 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
2006 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07002007 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002008 }
2009 String permission = null;
2010 switch (type) {
2011 case TYPE_TOAST:
2012 // XXX right now the app process has complete control over
2013 // this... should introduce a token to let the system
2014 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04002015 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002016 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05002017 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002018 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002019 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07002020 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002021 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07002022 case TYPE_ACCESSIBILITY_OVERLAY:
Jason Monk8f7f3182015-11-18 16:35:14 -05002023 case TYPE_QS_DIALOG:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002024 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002025 break;
2026 case TYPE_PHONE:
2027 case TYPE_PRIORITY_PHONE:
2028 case TYPE_SYSTEM_ALERT:
2029 case TYPE_SYSTEM_ERROR:
2030 case TYPE_SYSTEM_OVERLAY:
2031 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002032 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002033 break;
2034 default:
2035 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
2036 }
2037 if (permission != null) {
Billy Laucbe540f2015-06-25 01:51:44 +01002038 if (permission == android.Manifest.permission.SYSTEM_ALERT_WINDOW) {
2039 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01002040 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01002041 if (callingUid == Process.SYSTEM_UID) {
2042 return WindowManagerGlobal.ADD_OKAY;
2043 }
2044
Billy Lau060275f2015-07-15 22:29:19 +01002045 // check if user has enabled this operation. SecurityException will be thrown if
2046 // this app has not been allowed by the user
Billy Laucbe540f2015-06-25 01:51:44 +01002047 final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid,
2048 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01002049 switch (mode) {
2050 case AppOpsManager.MODE_ALLOWED:
2051 case AppOpsManager.MODE_IGNORED:
2052 // although we return ADD_OKAY for MODE_IGNORED, the added window will
2053 // actually be hidden in WindowManagerService
2054 return WindowManagerGlobal.ADD_OKAY;
2055 case AppOpsManager.MODE_ERRORED:
Billy Laucbe540f2015-06-25 01:51:44 +01002056 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01002057 default:
2058 // in the default mode, we will make a decision here based on
2059 // checkCallingPermission()
2060 if (mContext.checkCallingPermission(permission) !=
2061 PackageManager.PERMISSION_GRANTED) {
2062 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
2063 } else {
2064 return WindowManagerGlobal.ADD_OKAY;
2065 }
Billy Laucbe540f2015-06-25 01:51:44 +01002066 }
Billy Laucbe540f2015-06-25 01:51:44 +01002067 }
2068
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002069 if (mContext.checkCallingOrSelfPermission(permission)
2070 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07002071 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002072 }
2073 }
Jeff Brown98365d72012-08-19 20:30:52 -07002074 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002075 }
Craig Mautner88400d32012-09-30 12:35:45 -07002076
2077 @Override
2078 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
2079
2080 // If this switch statement is modified, modify the comment in the declarations of
2081 // the type in {@link WindowManager.LayoutParams} as well.
2082 switch (attrs.type) {
2083 default:
2084 // These are the windows that by default are shown only to the user that created
2085 // them. If this needs to be overridden, set
2086 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
2087 // {@link WindowManager.LayoutParams}. Note that permission
2088 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
2089 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
2090 return true;
2091 }
2092 break;
2093
2094 // These are the windows that by default are shown to all users. However, to
2095 // protect against spoofing, check permissions below.
2096 case TYPE_APPLICATION_STARTING:
2097 case TYPE_BOOT_PROGRESS:
2098 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07002099 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08002100 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07002101 case TYPE_KEYGUARD_DIALOG:
2102 case TYPE_MAGNIFICATION_OVERLAY:
2103 case TYPE_NAVIGATION_BAR:
2104 case TYPE_NAVIGATION_BAR_PANEL:
2105 case TYPE_PHONE:
2106 case TYPE_POINTER:
2107 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002108 case TYPE_SEARCH_BAR:
2109 case TYPE_STATUS_BAR:
2110 case TYPE_STATUS_BAR_PANEL:
2111 case TYPE_STATUS_BAR_SUB_PANEL:
2112 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002113 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07002114 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002115 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002116 break;
2117 }
2118
2119 // Check if third party app has set window to system window type.
2120 return mContext.checkCallingOrSelfPermission(
2121 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
2122 != PackageManager.PERMISSION_GRANTED;
2123 }
2124
Craig Mautner967212c2013-04-13 21:10:58 -07002125 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002126 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2127 switch (attrs.type) {
2128 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002129 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002130 // These types of windows can't receive input events.
2131 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2132 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002133 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002134 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002135 case TYPE_STATUS_BAR:
2136
2137 // If the Keyguard is in a hidden state (occluded by another window), we force to
2138 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2139 // the keyguard as occluded wouldn't set these flags again.
2140 // See {@link #processKeyguardSetHiddenResultLw}.
2141 if (mKeyguardHidden) {
2142 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2143 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2144 }
2145 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002146 }
Adrian Roos38502112014-04-09 21:04:11 +02002147
2148 if (attrs.type != TYPE_STATUS_BAR) {
2149 // The status bar is the only window allowed to exhibit keyguard behavior.
2150 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2151 }
Adrian Roosea562512014-05-05 13:33:03 +02002152
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002153 if (ActivityManager.isHighEndGfx()) {
2154 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
2155 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2156 }
2157 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
Jorim Jaggi406585a2015-12-21 10:58:56 +01002158 || (mForceWindowDrawsStatusBarBackground
2159 && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT)) {
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002160 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
2161 }
Adrian Roosea562512014-05-05 13:33:03 +02002162 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002163 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002164
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002165 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002166 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002167 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002168
Michael Wright3818c922014-09-02 13:59:07 -07002169 private void readCameraLensCoverState() {
2170 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2171 }
2172
Jeff Browndaa37532012-05-01 15:54:03 -07002173 private boolean isHidden(int accessibilityMode) {
2174 switch (accessibilityMode) {
2175 case 1:
2176 return mLidState == LID_CLOSED;
2177 case 2:
2178 return mLidState == LID_OPEN;
2179 default:
2180 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002181 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002182 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002183
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002184 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002185 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002186 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2187 int navigationPresence) {
2188 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2189
Jeff Brownf71343d2013-05-31 17:59:11 -07002190 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002191 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07002192 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002193
Jeff Browndaa37532012-05-01 15:54:03 -07002194 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2195 || (keyboardPresence == PRESENCE_INTERNAL
2196 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002197 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002198 if (!mHasSoftInput) {
2199 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2200 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002201 }
2202
Jeff Browndaa37532012-05-01 15:54:03 -07002203 if (config.navigation == Configuration.NAVIGATION_NONAV
2204 || (navigationPresence == PRESENCE_INTERNAL
2205 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002206 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002207 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002208 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002209
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002210 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002211 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002212 public int windowTypeToLayerLw(int type) {
2213 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002214 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002215 }
2216 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07002217 case TYPE_PRIVATE_PRESENTATION:
2218 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002219 case TYPE_WALLPAPER:
2220 // wallpaper is at the bottom, though the window manager may move it.
2221 return 2;
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002222 case TYPE_DOCK_DIVIDER:
2223 return 2;
Jason Monk8f7f3182015-11-18 16:35:14 -05002224 case TYPE_QS_DIALOG:
2225 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002226 case TYPE_PHONE:
2227 return 3;
2228 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002229 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002230 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002231 case TYPE_VOICE_INTERACTION:
2232 // voice interaction layer is almost immediately above apps.
2233 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002234 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002235 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002236 case TYPE_SYSTEM_DIALOG:
2237 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002238 case TYPE_TOAST:
2239 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002240 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002241 case TYPE_PRIORITY_PHONE:
2242 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002243 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002244 case TYPE_DREAM:
2245 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002246 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002247 case TYPE_SYSTEM_ALERT:
2248 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002249 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002250 case TYPE_INPUT_METHOD:
2251 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002252 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002253 case TYPE_INPUT_METHOD_DIALOG:
2254 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002255 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002256 case TYPE_KEYGUARD_SCRIM:
2257 // the safety window that shows behind keyguard while keyguard is starting
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002258 return 14;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002259 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002260 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002261 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002262 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002263 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002264 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002265 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002266 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002267 case TYPE_VOLUME_OVERLAY:
2268 // the on-screen volume indicator and controller shown when the user
2269 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002270 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002271 case TYPE_SYSTEM_OVERLAY:
2272 // the on-screen volume indicator and controller shown when the user
2273 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002274 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002275 case TYPE_NAVIGATION_BAR:
2276 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002277 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002278 case TYPE_NAVIGATION_BAR_PANEL:
2279 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002280 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002281 case TYPE_SYSTEM_ERROR:
2282 // system-level error dialogs
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002283 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002284 case TYPE_MAGNIFICATION_OVERLAY:
2285 // used to highlight the magnified portion of a display
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002286 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002287 case TYPE_DISPLAY_OVERLAY:
2288 // used to simulate secondary display devices
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002289 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002290 case TYPE_DRAG:
2291 // the drag layer: input for drag-and-drop is associated with this window,
2292 // which sits above all other focusable windows
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002293 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002294 case TYPE_ACCESSIBILITY_OVERLAY:
2295 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002296 return 27;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002297 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002298 return 28;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002299 case TYPE_BOOT_PROGRESS:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002300 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002301 case TYPE_POINTER:
2302 // the (mouse) pointer layer
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002303 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002304 }
2305 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002306 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002307 }
2308
2309 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002310 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002311 public int subWindowTypeToLayerLw(int type) {
2312 switch (type) {
2313 case TYPE_APPLICATION_PANEL:
2314 case TYPE_APPLICATION_ATTACHED_DIALOG:
2315 return APPLICATION_PANEL_SUBLAYER;
2316 case TYPE_APPLICATION_MEDIA:
2317 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002318 case TYPE_APPLICATION_MEDIA_OVERLAY:
2319 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002320 case TYPE_APPLICATION_SUB_PANEL:
2321 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002322 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2323 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002324 }
2325 Log.e(TAG, "Unknown sub-window type: " + type);
2326 return 0;
2327 }
2328
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002329 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002330 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002331 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002332 }
2333
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002334 private int getNavigationBarWidth(int rotation, int uiMode) {
2335 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2336 return mNavigationBarWidthForRotationInCarMode[rotation];
2337 } else {
2338 return mNavigationBarWidthForRotationDefault[rotation];
2339 }
2340 }
2341
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002342 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002343 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
2344 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002345 if (mHasNavigationBar) {
2346 // For a basic navigation bar, when we are in landscape mode we place
2347 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002348 if (mNavigationBarCanMove && fullWidth > fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002349 return fullWidth - getNavigationBarWidth(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002350 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002351 }
2352 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002353 }
2354
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002355 private int getNavigationBarHeight(int rotation, int uiMode) {
2356 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2357 return mNavigationBarHeightForRotationInCarMode[rotation];
2358 } else {
2359 return mNavigationBarHeightForRotationDefault[rotation];
2360 }
2361 }
2362
Jose Lima9546b202014-07-02 17:21:51 -07002363 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002364 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
2365 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002366 if (mHasNavigationBar) {
2367 // For a basic navigation bar, when we are in portrait mode we place
2368 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002369 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002370 return fullHeight - getNavigationBarHeight(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002371 }
2372 }
2373 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002374 }
2375
Jose Lima9546b202014-07-02 17:21:51 -07002376 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002377 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) {
2378 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002379 }
2380
Jose Lima9546b202014-07-02 17:21:51 -07002381 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002382 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
John Spurlock80f00c12013-06-13 11:10:51 -04002383 // There is a separate status bar at the top of the display. We don't count that as part
2384 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002385 // we do want to exclude it since applications can't generally use that part
2386 // of the screen.
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002387 return getNonDecorDisplayHeight(
2388 fullWidth, fullHeight, rotation, uiMode) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002389 }
2390
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002391 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002392 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2393 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002394 (isKeyguardHostWindow(attrs) &&
2395 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002396 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002397 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002398
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002399 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002400 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2401 return attrs.type == TYPE_STATUS_BAR;
2402 }
2403
2404 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002405 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002406 switch (attrs.type) {
2407 case TYPE_STATUS_BAR:
2408 case TYPE_NAVIGATION_BAR:
2409 case TYPE_WALLPAPER:
2410 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002411 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002412 return false;
2413 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002414 // Hide only windows below the keyguard host window.
2415 return windowTypeToLayerLw(win.getBaseType())
2416 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002417 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002418 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002419
Craig Mautner7d7808f2014-09-11 18:02:38 -07002420 @Override
2421 public WindowState getWinShowWhenLockedLw() {
2422 return mWinShowWhenLocked;
2423 }
2424
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002425 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002426 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002427 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2428 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002429 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002430 if (!SHOW_STARTING_ANIMATIONS) {
2431 return null;
2432 }
2433 if (packageName == null) {
2434 return null;
2435 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002436
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002437 WindowManager wm = null;
2438 View view = null;
2439
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002440 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002441 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002442 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2443 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2444 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002445 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002446 try {
2447 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002448 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002449 } catch (PackageManager.NameNotFoundException e) {
2450 // Ignore
2451 }
2452 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002453
Jorim Jaggia16cc152015-06-01 16:55:05 -07002454 PhoneWindow win = new PhoneWindow(context);
2455 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002456
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002457 Resources r = context.getResources();
2458 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002459
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002460 win.setType(
2461 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002462
2463 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2464 // Assumes it's safe to show starting windows of launched apps while
2465 // the keyguard is being hidden. This is okay because starting windows never show
2466 // secret information.
2467 if (mKeyguardHidden) {
2468 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2469 }
2470 }
2471
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002472 // Force the window flags: this is a fake window, so it is not really
2473 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2474 // flag because we do know that the next window will take input
2475 // focus, so we want to get the IME window up on top of us right away.
2476 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002477 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002478 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2479 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2480 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002481 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002482 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2483 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2484 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002485
Adam Powell04fe6eb2013-05-31 14:39:48 -07002486 win.setDefaultIcon(icon);
2487 win.setDefaultLogo(logo);
2488
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002489 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002490 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002491
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002492 final WindowManager.LayoutParams params = win.getAttributes();
2493 params.token = appToken;
2494 params.packageName = packageName;
2495 params.windowAnimations = win.getWindowStyle().getResourceId(
2496 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002497 params.privateFlags |=
2498 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002499 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002500
2501 if (!compatInfo.supportsScreen()) {
2502 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2503 }
2504
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002505 params.setTitle("Starting " + packageName);
2506
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002507 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2508 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002509
Craig Mautner6fbda632012-07-03 09:26:39 -07002510 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002511 TAG, "Adding starting window for " + packageName
2512 + " / " + appToken + ": "
2513 + (view.getParent() != null ? view : null));
2514
2515 wm.addView(view, params);
2516
2517 // Only return the view if it was successfully added to the
2518 // window manager... which we can tell by it having a parent.
2519 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002520 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002521 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002522 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2523 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002524 } catch (RuntimeException e) {
2525 // don't crash if something else bad happens, for example a
2526 // failure loading resources because we are loading from an app
2527 // on external storage that has been unmounted.
2528 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002529 } finally {
2530 if (view != null && view.getParent() == null) {
2531 Log.w(TAG, "view not successfully added to wm, removing view");
2532 wm.removeViewImmediate(view);
2533 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002534 }
2535
2536 return null;
2537 }
2538
2539 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002540 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002541 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002542 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2543 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002544
2545 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002546 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002547 wm.removeView(window);
2548 }
2549 }
2550
2551 /**
2552 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002553 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002554 * Currently enforces that three window types are singletons:
2555 * <ul>
2556 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002557 * <li>KEYGUARD_TYPE</li>
2558 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002559 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002560 * @param win The window to be added
2561 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002562 *
Jeff Brown98365d72012-08-19 20:30:52 -07002563 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2564 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002565 */
Jose Lima9546b202014-07-02 17:21:51 -07002566 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002567 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2568 switch (attrs.type) {
2569 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002570 mContext.enforceCallingOrSelfPermission(
2571 android.Manifest.permission.STATUS_BAR_SERVICE,
2572 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002573 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002574 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002575 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002576 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002577 }
2578 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002579 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002580 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002581 case TYPE_NAVIGATION_BAR:
2582 mContext.enforceCallingOrSelfPermission(
2583 android.Manifest.permission.STATUS_BAR_SERVICE,
2584 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002585 if (mNavigationBar != null) {
2586 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002587 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002588 }
2589 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002590 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002591 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002592 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002593 break;
Jim Millere898ac52012-04-06 17:10:57 -07002594 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002595 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002596 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002597 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002598 mContext.enforceCallingOrSelfPermission(
2599 android.Manifest.permission.STATUS_BAR_SERVICE,
2600 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002601 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002602 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002603 if (mKeyguardScrim != null) {
2604 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2605 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002606 mKeyguardScrim = win;
2607 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002608 }
Jeff Brown98365d72012-08-19 20:30:52 -07002609 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002610 }
2611
2612 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002613 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002614 public void removeWindowLw(WindowState win) {
2615 if (mStatusBar == win) {
2616 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002617 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002618 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002619 } else if (mKeyguardScrim == win) {
2620 Log.v(TAG, "Removing keyguard scrim");
2621 mKeyguardScrim = null;
2622 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002623 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002624 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002625 }
2626 }
2627
2628 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002629
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002630 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002631 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002632 public int selectAnimationLw(WindowState win, int transit) {
2633 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2634 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002635 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002636 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002637 if (transit == TRANSIT_EXIT
2638 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002639 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002640 } else if (transit == TRANSIT_ENTER
2641 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002642 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002643 }
2644 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002645 if (win.getAttrs().windowAnimations != 0) {
2646 return 0;
2647 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002648 // This can be on either the bottom or the right.
2649 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002650 if (transit == TRANSIT_EXIT
2651 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002652 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002653 } else if (transit == TRANSIT_ENTER
2654 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002655 return R.anim.dock_bottom_enter;
2656 }
2657 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002658 if (transit == TRANSIT_EXIT
2659 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002660 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002661 } else if (transit == TRANSIT_ENTER
2662 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002663 return R.anim.dock_right_enter;
2664 }
2665 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002666 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002667 return selectDockedDividerAnimationLw(win, transit);
Craig Mautner4b71aa12012-12-27 17:20:01 -08002668 }
2669
2670 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002671 if (win.hasAppShownWindows()) {
2672 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2673 return com.android.internal.R.anim.app_starting_exit;
2674 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002675 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002676 && transit == TRANSIT_ENTER) {
2677 // Special case: we are animating in a dream, while the keyguard
2678 // is shown. We don't want an animation on the dream, because
2679 // we need it shown immediately with the keyguard animating away
2680 // to reveal it.
2681 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002682 }
2683
2684 return 0;
2685 }
2686
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002687 private int selectDockedDividerAnimationLw(WindowState win, int transit) {
2688 int insets = mWindowManagerFuncs.getDockedDividerInsetsLw();
2689
2690 // If the divider is behind the navigation bar, don't animate.
2691 if (mNavigationBar != null
2692 && (win.getFrameLw().top + insets >= mNavigationBar.getFrameLw().top
2693 || win.getFrameLw().left + insets >= mNavigationBar.getFrameLw().left)) {
2694 return 0;
2695 }
2696 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
2697 return R.anim.fade_in;
2698 } else if (transit == TRANSIT_EXIT) {
2699 return R.anim.fade_out;
2700 } else {
2701 return 0;
2702 }
2703 }
2704
Craig Mautner3c174372013-02-21 17:54:37 -08002705 @Override
2706 public void selectRotationAnimationLw(int anim[]) {
2707 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2708 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2709 + (mTopFullscreenOpaqueWindowState == null ?
2710 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2711 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2712 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2713 case ROTATION_ANIMATION_CROSSFADE:
2714 anim[0] = R.anim.rotation_animation_xfade_exit;
2715 anim[1] = R.anim.rotation_animation_enter;
2716 break;
2717 case ROTATION_ANIMATION_JUMPCUT:
2718 anim[0] = R.anim.rotation_animation_jump_exit;
2719 anim[1] = R.anim.rotation_animation_enter;
2720 break;
2721 case ROTATION_ANIMATION_ROTATE:
2722 default:
2723 anim[0] = anim[1] = 0;
2724 break;
2725 }
2726 } else {
2727 anim[0] = anim[1] = 0;
2728 }
2729 }
2730
2731 @Override
2732 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2733 boolean forceDefault) {
2734 switch (exitAnimId) {
2735 case R.anim.rotation_animation_xfade_exit:
2736 case R.anim.rotation_animation_jump_exit:
2737 // These are the only cases that matter.
2738 if (forceDefault) {
2739 return false;
2740 }
2741 int anim[] = new int[2];
2742 selectRotationAnimationLw(anim);
2743 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2744 default:
2745 return true;
2746 }
2747 }
2748
2749 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002750 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2751 boolean goingToNotificationShade) {
2752 if (goingToNotificationShade) {
2753 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002754 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002755
2756 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2757 R.anim.lock_screen_behind_enter_wallpaper :
2758 R.anim.lock_screen_behind_enter);
2759
2760 // TODO: Use XML interpolators when we have log interpolators available in XML.
2761 final List<Animation> animations = set.getAnimations();
2762 for (int i = animations.size() - 1; i >= 0; --i) {
2763 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2764 }
2765
2766 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002767 }
2768
2769
2770 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002771 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2772 if (goingToNotificationShade) {
2773 return null;
2774 } else {
2775 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2776 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002777 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002778
2779 private static void awakenDreams() {
2780 IDreamManager dreamManager = getDreamManager();
2781 if (dreamManager != null) {
2782 try {
2783 dreamManager.awaken();
2784 } catch (RemoteException e) {
2785 // fine, stay asleep then
2786 }
2787 }
2788 }
2789
2790 static IDreamManager getDreamManager() {
2791 return IDreamManager.Stub.asInterface(
2792 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2793 }
2794
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002795 TelecomManager getTelecommService() {
2796 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002797 }
2798
Jeff Brown4d396052010-10-29 21:50:21 -07002799 static IAudioService getAudioService() {
2800 IAudioService audioService = IAudioService.Stub.asInterface(
2801 ServiceManager.checkService(Context.AUDIO_SERVICE));
2802 if (audioService == null) {
2803 Log.w(TAG, "Unable to find IAudioService interface.");
2804 }
2805 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002806 }
2807
2808 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002809 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002810 }
2811
2812 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2813 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2814 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2815 };
2816
2817 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002818 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002819 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002820 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002821 final int keyCode = event.getKeyCode();
2822 final int repeatCount = event.getRepeatCount();
2823 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002824 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002825 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2826 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002827
Jeff Brown40013652012-05-16 21:22:36 -07002828 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002829 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002830 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2831 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002832 }
2833
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002834 // If we think we might have a volume down & power key chord on the way
2835 // but we're not sure, then tell the dispatcher to wait a little while and
2836 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002837 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002838 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002839 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002840 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2841 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002842 if (now < timeoutTime) {
2843 return timeoutTime - now;
2844 }
2845 }
2846 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002847 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002848 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002849 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002850 }
2851 return -1;
2852 }
2853 }
2854
Michael Wright6a62e552014-06-03 19:19:48 -07002855 // Cancel any pending meta actions if we see any other keys being pressed between the down
2856 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002857 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002858 mPendingMetaAction = false;
2859 }
2860
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002861 // First we always handle the home key here, so applications
2862 // can never break it, although if keyguard is on, we do let
2863 // it handle it, because that gives us the correct 5 second
2864 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002865 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002866
Jeff Brown49ed71d2010-12-06 17:13:33 -08002867 // If we have released the home key, and didn't do anything else
2868 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002869 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002870 cancelPreloadRecentApps();
2871
Jeff Brown49ed71d2010-12-06 17:13:33 -08002872 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002873 if (mHomeConsumed) {
2874 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002875 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002876 }
Jeff Browncaca8812013-05-09 13:34:33 -07002877
2878 if (canceled) {
2879 Log.i(TAG, "Ignoring HOME; event canceled.");
2880 return -1;
2881 }
2882
Yorke Lee4f803242014-12-15 23:22:06 +00002883 // If an incoming call is ringing, HOME is totally disabled.
2884 // (The user is already on the InCallUI at this point,
2885 // and his ONLY options are to answer or reject the call.)
2886 TelecomManager telecomManager = getTelecommService();
2887 if (telecomManager != null && telecomManager.isRinging()) {
2888 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2889 return -1;
2890 }
2891
Jeff Browncaca8812013-05-09 13:34:33 -07002892 // Delay handling home if a double-tap is possible.
2893 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2894 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2895 mHomeDoubleTapPending = true;
2896 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2897 ViewConfiguration.getDoubleTapTimeout());
2898 return -1;
2899 }
2900
Jeff Brown13f00f02014-10-31 14:45:50 -07002901 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002902 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002903 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002904
2905 // If a system window has focus, then it doesn't make sense
2906 // right now to interact with applications.
2907 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2908 if (attrs != null) {
2909 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002910 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2911 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2912 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002913 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002914 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002915 }
2916 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2917 for (int i=0; i<typeCount; i++) {
2918 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2919 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002920 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002921 }
2922 }
2923 }
Jeff Browncaca8812013-05-09 13:34:33 -07002924
2925 // Remember that home is pressed and handle special actions.
2926 if (repeatCount == 0) {
2927 mHomePressed = true;
2928 if (mHomeDoubleTapPending) {
2929 mHomeDoubleTapPending = false;
2930 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2931 handleDoubleTapOnHome();
2932 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2933 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2934 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002935 }
Jeff Browncaca8812013-05-09 13:34:33 -07002936 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2937 if (!keyguardOn) {
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09002938 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002939 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002940 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002941 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002942 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002943 // Hijack modified menu keys for debugging features
2944 final int chordBug = KeyEvent.META_SHIFT_ON;
2945
2946 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002947 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002948 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002949 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2950 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002951 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002952 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002953 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002954 Intent service = new Intent();
2955 service.setClassName(mContext, "com.android.server.LoadAverageService");
2956 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002957 boolean shown = Settings.Global.getInt(
2958 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002959 if (!shown) {
2960 mContext.startService(service);
2961 } else {
2962 mContext.stopService(service);
2963 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002964 Settings.Global.putInt(
2965 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002966 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002967 }
2968 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002969 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002970 if (down) {
2971 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002972 mSearchKeyShortcutPending = true;
2973 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002974 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002975 } else {
2976 mSearchKeyShortcutPending = false;
2977 if (mConsumeSearchKeyUp) {
2978 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002979 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002980 }
2981 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002982 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002983 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002984 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002985 if (down && repeatCount == 0) {
2986 preloadRecentApps();
2987 } else if (!down) {
2988 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002989 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002990 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002991 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002992 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2993 if (down) {
2994 IStatusBarService service = getStatusBarService();
2995 if (service != null) {
2996 try {
2997 service.expandNotificationsPanel();
2998 } catch (RemoteException e) {
2999 // do nothing.
3000 }
3001 }
3002 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01003003 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
3004 if (down) {
3005 if (repeatCount == 0) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003006 toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003007 }
3008 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003009 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
3010 if (down) {
3011 if (repeatCount == 0) {
3012 mAssistKeyLongPressed = false;
3013 } else if (repeatCount == 1) {
3014 mAssistKeyLongPressed = true;
3015 if (!keyguardOn) {
3016 launchAssistLongPressAction();
3017 }
3018 }
3019 } else {
3020 if (mAssistKeyLongPressed) {
3021 mAssistKeyLongPressed = false;
3022 } else {
3023 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003024 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003025 }
3026 }
3027 }
3028 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003029 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
3030 if (!down) {
3031 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07003032 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003033 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3034 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07003035 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
3036 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
3037 if (dic != null) {
3038 try {
3039 dic.exitIdle("voice-search");
3040 } catch (RemoteException e) {
3041 }
3042 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003043 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07003044 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003045 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003046 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003047 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003048 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
3049 if (down && repeatCount == 0) {
3050 mHandler.post(mScreenshotRunnable);
3051 }
3052 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003053 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3054 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3055 if (down) {
3056 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3057
3058 // Disable autobrightness if it's on
3059 int auto = Settings.System.getIntForUser(
3060 mContext.getContentResolver(),
3061 Settings.System.SCREEN_BRIGHTNESS_MODE,
3062 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3063 UserHandle.USER_CURRENT_OR_SELF);
3064 if (auto != 0) {
3065 Settings.System.putIntForUser(mContext.getContentResolver(),
3066 Settings.System.SCREEN_BRIGHTNESS_MODE,
3067 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3068 UserHandle.USER_CURRENT_OR_SELF);
3069 }
3070
3071 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3072 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3073 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3074 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3075 Settings.System.SCREEN_BRIGHTNESS,
3076 mPowerManager.getDefaultScreenBrightnessSetting(),
3077 UserHandle.USER_CURRENT_OR_SELF);
3078 brightness += step;
3079 // Make sure we don't go beyond the limits.
3080 brightness = Math.min(max, brightness);
3081 brightness = Math.max(min, brightness);
3082
3083 Settings.System.putIntForUser(mContext.getContentResolver(),
3084 Settings.System.SCREEN_BRIGHTNESS, brightness,
3085 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003086 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003087 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003088 }
3089 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003090 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3091 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3092 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
3093 if (mUseTvRouting) {
3094 // On TVs volume keys never go to the foreground app.
3095 dispatchDirectAudioEvent(event);
3096 return -1;
3097 }
Michael Wrightce0c13a2014-07-30 10:49:21 -07003098 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003099 if (down) {
3100 mPendingMetaAction = true;
3101 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003102 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003103 }
3104 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003105 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003106
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003107 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003108 // Any printing key that is chorded with Search should be consumed
3109 // even if no shortcut was invoked. This prevents text from being
3110 // inadvertently inserted when using a keyboard that has built-in macro
3111 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003112 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003113 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3114 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003115 mConsumeSearchKeyUp = true;
3116 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003117 if (down && repeatCount == 0 && !keyguardOn) {
3118 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3119 if (shortcutIntent != null) {
3120 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003121 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003122 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003123 } catch (ActivityNotFoundException ex) {
3124 Slog.w(TAG, "Dropping shortcut key combination because "
3125 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003126 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003127 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003128 } else {
3129 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003130 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003131 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003132 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003133 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003134 }
3135 }
3136
Jeff Brown68b909d2011-12-07 16:36:01 -08003137 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003138 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003139 && (metaState & KeyEvent.META_META_ON) != 0) {
3140 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003141 if (kcm.isPrintingKey(keyCode)) {
3142 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3143 metaState & ~(KeyEvent.META_META_ON
3144 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3145 if (shortcutIntent != null) {
3146 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3147 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003148 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07003149 } catch (ActivityNotFoundException ex) {
3150 Slog.w(TAG, "Dropping shortcut key combination because "
3151 + "the activity to which it is registered was not found: "
3152 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3153 }
3154 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003155 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003156 }
3157 }
3158
Jeff Brown6651a632011-11-28 12:59:11 -08003159 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003160 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003161 String category = sApplicationLaunchKeyCategories.get(keyCode);
3162 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003163 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003164 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3165 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003166 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003167 } catch (ActivityNotFoundException ex) {
3168 Slog.w(TAG, "Dropping application launch key because "
3169 + "the activity to which it is registered was not found: "
3170 + "keyCode=" + keyCode + ", category=" + category, ex);
3171 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003172 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003173 }
3174 }
3175
Michael Wright61c46752014-08-21 16:57:33 -07003176 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003177 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003178 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003179 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003180 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003181 mRecentAppsHeldModifiers = shiftlessModifiers;
3182 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003183 return -1;
3184 }
3185 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003186 } else if (!down && mRecentAppsHeldModifiers != 0
3187 && (metaState & mRecentAppsHeldModifiers) == 0) {
3188 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003189 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003190 }
3191
Yohei Yukawaae61f712015-12-09 13:00:10 -08003192 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003193 if (down && repeatCount == 0
3194 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3195 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003196 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3197 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3198 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003199 return -1;
3200 }
3201 if (mLanguageSwitchKeyPressed && !down
3202 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3203 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3204 mLanguageSwitchKeyPressed = false;
3205 return -1;
3206 }
3207
Jeff Brown13f00f02014-10-31 14:45:50 -07003208 if (isValidGlobalKey(keyCode)
3209 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003210 return -1;
3211 }
3212
Michael Wright6a62e552014-06-03 19:19:48 -07003213 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003214 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003215 return -1;
3216 }
3217
Jeff Brown68b909d2011-12-07 16:36:01 -08003218 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003219 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003220 }
3221
Jeff Brown3915bb82010-11-05 15:02:16 -07003222 /** {@inheritDoc} */
3223 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003224 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003225 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003226 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003227 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3228 + ", flags=" + event.getFlags()
3229 + ", keyCode=" + event.getKeyCode()
3230 + ", scanCode=" + event.getScanCode()
3231 + ", metaState=" + event.getMetaState()
3232 + ", repeatCount=" + event.getRepeatCount()
3233 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003234 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003235
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003236 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003237 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3238 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003239 final int keyCode = event.getKeyCode();
3240 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003241 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3242 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003243
Jeff Brown54875002011-04-06 15:33:01 -07003244 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003245 final FallbackAction fallbackAction;
3246 if (initialDown) {
3247 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3248 } else {
3249 fallbackAction = mFallbackActions.get(keyCode);
3250 }
3251
3252 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003253 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003254 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3255 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003256 }
3257
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003258 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3259 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003260 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003261 event.getAction(), fallbackAction.keyCode,
3262 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003263 event.getDeviceId(), event.getScanCode(),
3264 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003265
3266 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3267 fallbackEvent.recycle();
3268 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003269 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003270
3271 if (initialDown) {
3272 mFallbackActions.put(keyCode, fallbackAction);
3273 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3274 mFallbackActions.remove(keyCode);
3275 fallbackAction.recycle();
3276 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003277 }
3278 }
3279
Jeff Brown40013652012-05-16 21:22:36 -07003280 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003281 if (fallbackEvent == null) {
3282 Slog.d(TAG, "No fallback.");
3283 } else {
3284 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3285 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003286 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003287 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003288 }
3289
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003290 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003291 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003292 if ((actions & ACTION_PASS_TO_USER) != 0) {
3293 long delayMillis = interceptKeyBeforeDispatching(
3294 win, fallbackEvent, policyFlags);
3295 if (delayMillis == 0) {
3296 return true;
3297 }
3298 }
3299 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003300 }
3301
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003302 private void launchAssistLongPressAction() {
3303 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3304 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3305
3306 // launch the search activity
3307 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3308 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3309 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003310 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003311 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003312 SearchManager searchManager = getSearchManager();
3313 if (searchManager != null) {
3314 searchManager.stopSearch();
3315 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003316 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003317 } catch (ActivityNotFoundException e) {
3318 Slog.w(TAG, "No activity to handle assist long press action.", e);
3319 }
3320 }
3321
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003322 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003323 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003324 if (!isUserSetupComplete()) {
3325 // Disable opening assist window during setup
3326 return;
3327 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003328 Bundle args = null;
3329 if (deviceId > Integer.MIN_VALUE) {
3330 args = new Bundle();
3331 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003332 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003333 if ((mContext.getResources().getConfiguration().uiMode
3334 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3335 // On TV, use legacy handling until assistants are implemented in the proper way.
3336 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3337 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3338 } else {
3339 try {
3340 if (hint != null) {
3341 if (args == null) {
3342 args = new Bundle();
3343 }
3344 args.putBoolean(hint, true);
3345 }
3346 IStatusBarService statusbar = getStatusBarService();
3347 if (statusbar != null) {
3348 statusbar.startAssist(args);
3349 }
3350 } catch (RemoteException e) {
3351 Slog.e(TAG, "RemoteException when starting assist", e);
3352 // re-acquire status bar service next time it is needed.
3353 mStatusBarService = null;
3354 }
3355 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003356 }
3357
Bart Sears8b1c27c2015-03-18 23:51:02 +00003358 private void startActivityAsUser(Intent intent, UserHandle handle) {
3359 if (isUserSetupComplete()) {
3360 mContext.startActivityAsUser(intent, handle);
3361 } else {
3362 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3363 }
3364 }
3365
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003366 private SearchManager getSearchManager() {
3367 if (mSearchManager == null) {
3368 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3369 }
3370 return mSearchManager;
3371 }
3372
Jeff Browncaca8812013-05-09 13:34:33 -07003373 private void preloadRecentApps() {
3374 mPreloadedRecentApps = true;
3375 try {
3376 IStatusBarService statusbar = getStatusBarService();
3377 if (statusbar != null) {
3378 statusbar.preloadRecentApps();
3379 }
3380 } catch (RemoteException e) {
3381 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3382 // re-acquire status bar service next time it is needed.
3383 mStatusBarService = null;
3384 }
3385 }
3386
3387 private void cancelPreloadRecentApps() {
3388 if (mPreloadedRecentApps) {
3389 mPreloadedRecentApps = false;
3390 try {
3391 IStatusBarService statusbar = getStatusBarService();
3392 if (statusbar != null) {
3393 statusbar.cancelPreloadRecentApps();
3394 }
3395 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003396 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003397 // re-acquire status bar service next time it is needed.
3398 mStatusBarService = null;
3399 }
3400 }
3401 }
3402
3403 private void toggleRecentApps() {
3404 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003405 try {
3406 IStatusBarService statusbar = getStatusBarService();
3407 if (statusbar != null) {
3408 statusbar.toggleRecentApps();
3409 }
3410 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003411 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3412 // re-acquire status bar service next time it is needed.
3413 mStatusBarService = null;
3414 }
3415 }
3416
Craig Mautner84984fa2014-06-19 11:19:20 -07003417 @Override
3418 public void showRecentApps() {
3419 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3420 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3421 }
3422
Winson Chung1e8d71b2014-05-16 17:05:22 -07003423 private void showRecentApps(boolean triggeredFromAltTab) {
3424 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3425 try {
3426 IStatusBarService statusbar = getStatusBarService();
3427 if (statusbar != null) {
3428 statusbar.showRecentApps(triggeredFromAltTab);
3429 }
3430 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003431 Slog.e(TAG, "RemoteException when showing recent apps", e);
3432 // re-acquire status bar service next time it is needed.
3433 mStatusBarService = null;
3434 }
3435 }
3436
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003437 private void toggleKeyboardShortcutsMenu() {
Clara Bayarrif2debb12015-07-10 14:47:17 +01003438 try {
3439 IStatusBarService statusbar = getStatusBarService();
3440 if (statusbar != null) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003441 statusbar.toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003442 }
3443 } catch (RemoteException e) {
3444 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3445 }
3446 }
3447
Winson Chungcdcd4872014-08-05 18:00:13 -07003448 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003449 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3450 try {
3451 IStatusBarService statusbar = getStatusBarService();
3452 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003453 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003454 }
3455 } catch (RemoteException e) {
3456 Slog.e(TAG, "RemoteException when closing recent apps", e);
3457 // re-acquire status bar service next time it is needed.
3458 mStatusBarService = null;
3459 }
3460 }
3461
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003462 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003463 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003464 }
3465
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003466 /**
3467 * A home key -> launch home action was detected. Take the appropriate action
3468 * given the situation with the keyguard.
3469 */
Bryce Lee662ed802015-04-10 20:11:39 +00003470 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3471 if (respectKeyguard) {
3472 if (isKeyguardShowingAndNotOccluded()) {
3473 // don't launch home if keyguard showing
3474 return;
3475 }
3476
3477 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3478 // when in keyguard restricted mode, must first verify unlock
3479 // before launching home
3480 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3481 @Override
3482 public void onKeyguardExitResult(boolean success) {
3483 if (success) {
3484 try {
3485 ActivityManagerNative.getDefault().stopAppSwitches();
3486 } catch (RemoteException e) {
3487 }
3488 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3489 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003490 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003491 }
Bryce Lee662ed802015-04-10 20:11:39 +00003492 });
3493 return;
3494 }
3495 }
3496
3497 // no keyguard stuff to worry about, just launch home!
3498 try {
3499 ActivityManagerNative.getDefault().stopAppSwitches();
3500 } catch (RemoteException e) {
3501 }
3502 if (mRecentsVisible) {
3503 // Hide Recents and notify it to launch Home
3504 if (awakenFromDreams) {
3505 awakenDreams();
3506 }
Bryce Lee662ed802015-04-10 20:11:39 +00003507 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003508 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003509 // Otherwise, just launch Home
3510 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3511 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003512 }
3513 }
3514
John Spurlock04db1762013-05-13 12:46:41 -04003515 private final Runnable mClearHideNavigationFlag = new Runnable() {
3516 @Override
3517 public void run() {
3518 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3519 // Clear flags.
3520 mForceClearedSystemUiFlags &=
3521 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3522 }
3523 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003524 }
3525 };
3526
3527 /**
3528 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3529 * to determine when the nav bar should be shown and prevent applications from
3530 * receiving those touches.
3531 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003532 final class HideNavInputEventReceiver extends InputEventReceiver {
3533 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3534 super(inputChannel, looper);
3535 }
3536
Dianne Hackborndf89e652011-10-06 22:35:11 -07003537 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003538 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003539 boolean handled = false;
3540 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003541 if (event instanceof MotionEvent
3542 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3543 final MotionEvent motionEvent = (MotionEvent)event;
3544 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003545 // When the user taps down, we re-show the nav bar.
3546 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003547 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003548 // Any user activity always causes us to show the
3549 // navigation controls, if they had been hidden.
3550 // We also clear the low profile and only content
3551 // flags so that tapping on the screen will atomically
3552 // restore all currently hidden screen decorations.
3553 int newVal = mResettingSystemUiFlags |
3554 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3555 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3556 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003557 if (mResettingSystemUiFlags != newVal) {
3558 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003559 changed = true;
3560 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003561 // We don't allow the system's nav bar to be hidden
3562 // again for 1 second, to prevent applications from
3563 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003564 newVal = mForceClearedSystemUiFlags |
3565 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003566 if (mForceClearedSystemUiFlags != newVal) {
3567 mForceClearedSystemUiFlags = newVal;
3568 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003569 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003570 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003571 }
3572 if (changed) {
3573 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3574 }
3575 }
3576 }
3577 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003578 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003579 }
3580 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003581 }
3582 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3583 new InputEventReceiver.Factory() {
3584 @Override
3585 public InputEventReceiver createInputEventReceiver(
3586 InputChannel inputChannel, Looper looper) {
3587 return new HideNavInputEventReceiver(inputChannel, looper);
3588 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003589 };
3590
3591 @Override
3592 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003593 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3594 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003595 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003596
Dianne Hackborndf89e652011-10-06 22:35:11 -07003597 // Reset any bits in mForceClearingStatusBarVisibility that
3598 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003599 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003600 // Clear any bits in the new visibility that are currently being
3601 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003602 return visibility & ~mResettingSystemUiFlags
3603 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003604 }
3605
Craig Mautner69b08182012-09-05 13:07:13 -07003606 @Override
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003607 public void getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
3608 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003609 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003610 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3611 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003612
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003613 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3614 if (useOutsets) {
3615 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3616 if (outset > 0) {
3617 if (displayRotation == Surface.ROTATION_0) {
3618 outOutsets.bottom += outset;
3619 } else if (displayRotation == Surface.ROTATION_90) {
3620 outOutsets.right += outset;
3621 } else if (displayRotation == Surface.ROTATION_180) {
3622 outOutsets.top += outset;
3623 } else if (displayRotation == Surface.ROTATION_270) {
3624 outOutsets.left += outset;
3625 }
3626 }
3627 }
3628
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003629 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003630 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003631 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003632 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003633 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003634 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3635 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3636 } else {
3637 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3638 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3639 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003640 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3641 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003642 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003643 availRight - mStableFullscreenRight,
3644 availBottom - mStableFullscreenBottom);
3645 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003646 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003647 availRight - mStableRight, availBottom - mStableBottom);
3648 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003649 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003650 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003651 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003652 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003653 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003654 availRight - mCurRight, availBottom - mCurBottom);
3655 } else {
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 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003659
3660 outStableInsets.set(mStableLeft, mStableTop,
3661 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003662 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003663 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003664 outContentInsets.setEmpty();
3665 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003666 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003667
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003668 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3669 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3670 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3671 }
3672
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003673 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003674 @Override
3675 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003676 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003677 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003678 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3679 if (isDefaultDisplay) {
3680 switch (displayRotation) {
3681 case Surface.ROTATION_90:
3682 overscanLeft = mOverscanTop;
3683 overscanTop = mOverscanRight;
3684 overscanRight = mOverscanBottom;
3685 overscanBottom = mOverscanLeft;
3686 break;
3687 case Surface.ROTATION_180:
3688 overscanLeft = mOverscanRight;
3689 overscanTop = mOverscanBottom;
3690 overscanRight = mOverscanLeft;
3691 overscanBottom = mOverscanTop;
3692 break;
3693 case Surface.ROTATION_270:
3694 overscanLeft = mOverscanBottom;
3695 overscanTop = mOverscanLeft;
3696 overscanRight = mOverscanTop;
3697 overscanBottom = mOverscanRight;
3698 break;
3699 default:
3700 overscanLeft = mOverscanLeft;
3701 overscanTop = mOverscanTop;
3702 overscanRight = mOverscanRight;
3703 overscanBottom = mOverscanBottom;
3704 break;
3705 }
3706 } else {
3707 overscanLeft = 0;
3708 overscanTop = 0;
3709 overscanRight = 0;
3710 overscanBottom = 0;
3711 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003712 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3713 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3714 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3715 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003716 mSystemLeft = 0;
3717 mSystemTop = 0;
3718 mSystemRight = displayWidth;
3719 mSystemBottom = displayHeight;
3720 mUnrestrictedScreenLeft = overscanLeft;
3721 mUnrestrictedScreenTop = overscanTop;
3722 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3723 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3724 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3725 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003726 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3727 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003728 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003729 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003730 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003731 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003732 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003733 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003734 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003735 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003736 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003737 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003738
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003739 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3740 final Rect pf = mTmpParentFrame;
3741 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003742 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003743 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003744 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003745 pf.left = df.left = of.left = vf.left = mDockLeft;
3746 pf.top = df.top = of.top = vf.top = mDockTop;
3747 pf.right = df.right = of.right = vf.right = mDockRight;
3748 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003749 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003750
Craig Mautner69b08182012-09-05 13:07:13 -07003751 if (isDefaultDisplay) {
3752 // For purposes of putting out fake window up to steal focus, we will
3753 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003754 final int sysui = mLastSystemUiFlags;
3755 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003756 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003757 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003758 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3759 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3760 boolean navAllowedHidden = immersive || immersiveSticky;
3761 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003762 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3763 if (!isKeyguardShowing) {
3764 navTranslucent &= areTranslucentBarsAllowed();
3765 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003766
Craig Mautner69b08182012-09-05 13:07:13 -07003767 // When the navigation bar isn't visible, we put up a fake
3768 // input window to catch all touch events. This way we can
3769 // detect when the user presses anywhere to bring back the nav
3770 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003771 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003772 if (mInputConsumer != null) {
3773 mInputConsumer.dismiss();
3774 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003775 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003776 } else if (mInputConsumer == null) {
3777 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3778 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003779 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003780
Craig Mautner69b08182012-09-05 13:07:13 -07003781 // For purposes of positioning and showing the nav bar, if we have
3782 // decided that it can't be hidden (because of the screen aspect ratio),
3783 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003784 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003785
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003786 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003787 displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003788 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003789 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003790 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003791 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003792 if (updateSysUiVisibility) {
3793 updateSystemUiVisibilityLw();
3794 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003795 }
3796 }
3797
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003798 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3799 boolean isKeyguardShowing) {
3800 // decide where the status bar goes ahead of time
3801 if (mStatusBar != null) {
3802 // apply any navigation bar insets
3803 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3804 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3805 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3806 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3807 + mUnrestrictedScreenTop;
3808 vf.left = mStableLeft;
3809 vf.top = mStableTop;
3810 vf.right = mStableRight;
3811 vf.bottom = mStableBottom;
3812
3813 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3814
3815 // Let the status bar determine its size.
3816 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3817 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3818 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3819
3820 // For layout, the status bar is always at the top with our fixed height.
3821 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3822
3823 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3824 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003825 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003826 if (!isKeyguardShowing) {
3827 statusBarTranslucent &= areTranslucentBarsAllowed();
3828 }
3829
3830 // If the status bar is hidden, we don't want to cause
3831 // windows behind it to scroll.
3832 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3833 // Status bar may go away, so the screen area it occupies
3834 // is available to apps but just covering them when the
3835 // status bar is visible.
3836 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3837
3838 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3839 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3840 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3841 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3842
3843 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3844 String.format(
3845 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3846 mDockLeft, mDockTop, mDockRight, mDockBottom,
3847 mContentLeft, mContentTop, mContentRight, mContentBottom,
3848 mCurLeft, mCurTop, mCurRight, mCurBottom));
3849 }
3850 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
3851 && !statusBarTransient && !statusBarTranslucent
3852 && !mStatusBarController.wasRecentlyTranslucent()) {
3853 // If the opaque status bar is currently requested to be visible,
3854 // and not in the process of animating on or off, then
3855 // we can tell the app that it is covered by it.
3856 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3857 }
3858 if (mStatusBarController.checkHiddenLw()) {
3859 return true;
3860 }
3861 }
3862 return false;
3863 }
3864
3865 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003866 int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003867 boolean navTranslucent, boolean navAllowedHidden) {
3868 if (mNavigationBar != null) {
3869 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
3870 // Force the navigation bar to its appropriate place and
3871 // size. We need to do this directly, instead of relying on
3872 // it to bubble up from the nav bar, because this needs to
3873 // change atomically with screen rotations.
Jorim Jaggi737af722015-12-31 10:42:27 +01003874 mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003875 if (mNavigationBarOnBottom) {
3876 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
3877 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003878 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003879 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
3880 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
3881 if (transientNavBarShowing) {
3882 mNavigationBarController.setBarShowingLw(true);
3883 } else if (navVisible) {
3884 mNavigationBarController.setBarShowingLw(true);
3885 mDockBottom = mTmpNavigationFrame.top;
3886 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3887 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
3888 } else {
3889 // We currently want to hide the navigation UI.
3890 mNavigationBarController.setBarShowingLw(false);
3891 }
3892 if (navVisible && !navTranslucent && !navAllowedHidden
3893 && !mNavigationBar.isAnimatingLw()
3894 && !mNavigationBarController.wasRecentlyTranslucent()) {
3895 // If the opaque nav bar is currently requested to be visible,
3896 // and not in the process of animating on or off, then
3897 // we can tell the app that it is covered by it.
3898 mSystemBottom = mTmpNavigationFrame.top;
3899 }
3900 } else {
3901 // Landscape screen; nav bar goes to the right.
3902 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003903 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003904 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
3905 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
3906 if (transientNavBarShowing) {
3907 mNavigationBarController.setBarShowingLw(true);
3908 } else if (navVisible) {
3909 mNavigationBarController.setBarShowingLw(true);
3910 mDockRight = mTmpNavigationFrame.left;
3911 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3912 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
3913 } else {
3914 // We currently want to hide the navigation UI.
3915 mNavigationBarController.setBarShowingLw(false);
3916 }
3917 if (navVisible && !navTranslucent && !navAllowedHidden
3918 && !mNavigationBar.isAnimatingLw()
3919 && !mNavigationBarController.wasRecentlyTranslucent()) {
3920 // If the nav bar is currently requested to be visible,
3921 // and not in the process of animating on or off, then
3922 // we can tell the app that it is covered by it.
3923 mSystemRight = mTmpNavigationFrame.left;
3924 }
3925 }
3926 // Make sure the content and current rectangles are updated to
3927 // account for the restrictions from the navigation bar.
3928 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3929 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3930 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3931 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3932 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3933 // And compute the final frame.
3934 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
3935 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3936 mTmpNavigationFrame, mTmpNavigationFrame);
3937 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
3938 if (mNavigationBarController.checkHiddenLw()) {
3939 return true;
3940 }
3941 }
3942 return false;
3943 }
3944
Jorim Jaggi737af722015-12-31 10:42:27 +01003945 private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) {
3946 return !mNavigationBarCanMove || displayWidth < displayHeight;
3947 }
3948
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003949 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003950 @Override
John Spurlock46646232013-09-30 22:32:42 -04003951 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003952 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3953 return mStatusBar.getSurfaceLayer();
3954 }
3955
3956 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3957 return mNavigationBar.getSurfaceLayer();
3958 }
3959
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003960 return 0;
3961 }
3962
Craig Mautner967212c2013-04-13 21:10:58 -07003963 @Override
3964 public void getContentRectLw(Rect r) {
3965 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3966 }
3967
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003968 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3969 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003970 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3971 // Here's a special case: if this attached window is a panel that is
3972 // above the dock window, and the window it is attached to is below
3973 // the dock window, then the frames we computed for the window it is
3974 // attached to can not be used because the dock is effectively part
3975 // of the underlying window and the attached window is floating on top
3976 // of the whole thing. So, we ignore the attached window and explicitly
3977 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003978 df.left = of.left = cf.left = vf.left = mDockLeft;
3979 df.top = of.top = cf.top = vf.top = mDockTop;
3980 df.right = of.right = cf.right = vf.right = mDockRight;
3981 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003982 } else {
3983 // The effective display frame of the attached window depends on
3984 // whether it is taking care of insetting its content. If not,
3985 // we need to use the parent's content frame so that the entire
3986 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003987 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003988 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003989 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003990 // Set the content frame of the attached window to the parent's decor frame
3991 // (same as content frame when IME isn't present) if specifically requested by
3992 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3993 // Otherwise, use the overscan frame.
3994 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3995 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003996 } else {
3997 // If the window is resizing, then we want to base the content
3998 // frame on our attached content frame to resize... however,
3999 // things can be tricky if the attached window is NOT in resize
4000 // mode, in which case its content frame will be larger.
4001 // Ungh. So to deal with that, make sure the content frame
4002 // we end up using is not covering the IM dock.
4003 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004004 if (attached.isVoiceInteraction()) {
4005 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
4006 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
4007 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
4008 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
4009 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004010 if (cf.left < mContentLeft) cf.left = mContentLeft;
4011 if (cf.top < mContentTop) cf.top = mContentTop;
4012 if (cf.right > mContentRight) cf.right = mContentRight;
4013 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
4014 }
4015 }
4016 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004017 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004018 vf.set(attached.getVisibleFrameLw());
4019 }
4020 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
4021 // window should be positioned relative to its parent or the entire
4022 // screen.
4023 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
4024 ? attached.getFrameLw() : df);
4025 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004026
4027 private void applyStableConstraints(int sysui, int fl, Rect r) {
4028 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4029 // If app is requesting a stable layout, don't let the
4030 // content insets go below the stable values.
4031 if ((fl & FLAG_FULLSCREEN) != 0) {
4032 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
4033 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
4034 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
4035 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
4036 } else {
4037 if (r.left < mStableLeft) r.left = mStableLeft;
4038 if (r.top < mStableTop) r.top = mStableTop;
4039 if (r.right > mStableRight) r.right = mStableRight;
4040 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
4041 }
4042 }
4043 }
4044
Jorim Jaggiaa806142015-05-20 18:04:16 -07004045 private boolean canReceiveInput(WindowState win) {
4046 boolean notFocusable =
4047 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4048 boolean altFocusableIm =
4049 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4050 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4051 return !notFocusableForIm;
4052 }
4053
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004054 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004055 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004056 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004057 // We've already done the navigation bar and status bar. If the status bar can receive
4058 // input, we need to layout it again to accomodate for the IME window.
4059 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004060 return;
4061 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004062 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004063 final boolean isDefaultDisplay = win.isDefaultDisplay();
4064 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004065 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4066 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004067 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004068 offsetInputMethodWindowLw(mLastInputMethodWindow);
4069 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004070
John Spurlockc6d1c602014-01-17 15:22:06 -05004071 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004072 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004073 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004074
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004075 final Rect pf = mTmpParentFrame;
4076 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004077 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004078 final Rect cf = mTmpContentFrame;
4079 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004080 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004081 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004082 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004083 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004084
4085 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004086 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004087
Craig Mautnerf683b562012-10-02 11:10:57 -07004088 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4089
Adrian Roosfa104232014-06-20 16:10:14 -07004090 if (isDefaultDisplay) {
4091 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4092 } else {
4093 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4094 }
4095
Craig Mautner69b08182012-09-05 13:07:13 -07004096 if (!isDefaultDisplay) {
4097 if (attached != null) {
4098 // If this window is attached to another, our display
4099 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004100 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004101 } else {
4102 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004103 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4104 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4105 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004106 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004107 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004108 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004109 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004110 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004111 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4112 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4113 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004114 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004115 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004116 // ...with content insets above the nav bar
4117 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004118 // IM dock windows always go to the bottom of the screen.
4119 attrs.gravity = Gravity.BOTTOM;
4120 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004121 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004122 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004123 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004124 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4125 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004126 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004127 // Note: In Phone landscape mode, the button bar should also be excluded.
4128 cf.right = vf.right = mStableRight;
4129 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004130 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07004131 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004132 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4133 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4134 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4135 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4136 cf.left = vf.left = mStableLeft;
4137 cf.top = vf.top = mStableTop;
4138 cf.right = vf.right = mStableRight;
4139 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004140
4141 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4142 cf.bottom = mContentBottom;
4143 } else {
4144 cf.bottom = mDockBottom;
4145 vf.bottom = mContentBottom;
4146 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004147 } else {
John Spurlock46646232013-09-30 22:32:42 -04004148
4149 // Default policy decor for the default display
4150 dcf.left = mSystemLeft;
4151 dcf.top = mSystemTop;
4152 dcf.right = mSystemRight;
4153 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004154 final boolean inheritTranslucentDecor = (attrs.privateFlags
4155 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004156 final boolean isAppWindow =
4157 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4158 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4159 final boolean topAtRest =
4160 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4161 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004162 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4163 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004164 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4165 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004166 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
4167 && !mForceWindowDrawsStatusBarBackground) {
John Spurlock46646232013-09-30 22:32:42 -04004168 // Ensure policy decor includes status bar
4169 dcf.top = mStableTop;
4170 }
John Spurlockbd957402013-10-03 11:38:39 -04004171 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004172 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4173 && (fl & WindowManager.LayoutParams.
4174 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004175 // Ensure policy decor includes navigation bar
4176 dcf.bottom = mStableBottom;
4177 dcf.right = mStableRight;
4178 }
4179 }
4180
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004181 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4182 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004183 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004184 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004185 // This is the case for a normal activity window: we want it
4186 // to cover all of the screen space, and it can take care of
4187 // moving its contents to account for screen decorations that
4188 // intrude into that space.
4189 if (attached != null) {
4190 // If this window is attached to another, our display
4191 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004192 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004193 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004194 if (attrs.type == TYPE_STATUS_BAR_PANEL
4195 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004196 // Status bar panels are the only windows who can go on top of
4197 // the status bar. They are protected by the STATUS_BAR_SERVICE
4198 // permission, so they have the same privileges as the status
4199 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004200 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004201 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004202
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004203 pf.left = df.left = of.left = hasNavBar
4204 ? mDockLeft : mUnrestrictedScreenLeft;
4205 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4206 pf.right = df.right = of.right = hasNavBar
4207 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4208 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4209 pf.bottom = df.bottom = of.bottom = hasNavBar
4210 ? mRestrictedScreenTop+mRestrictedScreenHeight
4211 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004212
Craig Mautnereda67292013-04-28 13:50:14 -07004213 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004214 "Laying out status bar window: (%d,%d - %d,%d)",
4215 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004216 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004217 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4218 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4219 // Asking to layout into the overscan region, so give it that pure
4220 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004221 pf.left = df.left = of.left = mOverscanScreenLeft;
4222 pf.top = df.top = of.top = mOverscanScreenTop;
4223 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4224 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4225 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004226 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004227 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004228 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4229 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004230 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004231 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004232 // only do this for application windows to ensure no window that
4233 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004234 pf.left = df.left = mOverscanScreenLeft;
4235 pf.top = df.top = mOverscanScreenTop;
4236 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4237 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004238 // We need to tell the app about where the frame inside the overscan
4239 // is, so it can inset its content by that amount -- it didn't ask
4240 // to actually extend itself into the overscan region.
4241 of.left = mUnrestrictedScreenLeft;
4242 of.top = mUnrestrictedScreenTop;
4243 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4244 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004245 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004246 pf.left = df.left = mRestrictedOverscanScreenLeft;
4247 pf.top = df.top = mRestrictedOverscanScreenTop;
4248 pf.right = df.right = mRestrictedOverscanScreenLeft
4249 + mRestrictedOverscanScreenWidth;
4250 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4251 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004252 // We need to tell the app about where the frame inside the overscan
4253 // is, so it can inset its content by that amount -- it didn't ask
4254 // to actually extend itself into the overscan region.
4255 of.left = mUnrestrictedScreenLeft;
4256 of.top = mUnrestrictedScreenTop;
4257 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4258 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004259 }
Craig Mautner69b08182012-09-05 13:07:13 -07004260
John Spurlock46646232013-09-30 22:32:42 -04004261 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004262 if (win.isVoiceInteraction()) {
4263 cf.left = mVoiceContentLeft;
4264 cf.top = mVoiceContentTop;
4265 cf.right = mVoiceContentRight;
4266 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004267 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004268 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4269 cf.left = mDockLeft;
4270 cf.top = mDockTop;
4271 cf.right = mDockRight;
4272 cf.bottom = mDockBottom;
4273 } else {
4274 cf.left = mContentLeft;
4275 cf.top = mContentTop;
4276 cf.right = mContentRight;
4277 cf.bottom = mContentBottom;
4278 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004279 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004280 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004281 // Full screen windows are always given a layout that is as if the
4282 // status bar and other transient decors are gone. This is to avoid
4283 // bad states when moving from a window that is not hding the
4284 // status bar to one that is.
4285 cf.left = mRestrictedScreenLeft;
4286 cf.top = mRestrictedScreenTop;
4287 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4288 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004289 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004290 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004291 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4292 vf.left = mCurLeft;
4293 vf.top = mCurTop;
4294 vf.right = mCurRight;
4295 vf.bottom = mCurBottom;
4296 } else {
4297 vf.set(cf);
4298 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004299 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004300 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4301 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4302 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004303 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4304 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004305 // A window that has requested to fill the entire screen just
4306 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004307 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004308 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4309 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004310 pf.left = df.left = of.left = cf.left = hasNavBar
4311 ? mDockLeft : mUnrestrictedScreenLeft;
4312 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4313 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004314 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004315 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004316 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004317 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004318 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004319 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004320 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4321 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004322 } else if (attrs.type == TYPE_NAVIGATION_BAR
4323 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004324 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004325 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4326 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4327 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4328 + mUnrestrictedScreenWidth;
4329 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4330 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004331 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004332 "Laying out navigation bar window: (%d,%d - %d,%d)",
4333 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004334 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4335 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004336 && ((fl & FLAG_FULLSCREEN) != 0)) {
4337 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004338 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4339 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4340 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4341 + mOverscanScreenWidth;
4342 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4343 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004344 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004345 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004346 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4347 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4348 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4349 + mOverscanScreenWidth;
4350 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4351 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004352 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004353 // The wallpaper also has Real Ultimate Power, but we want to tell
4354 // it about the overscan area.
4355 pf.left = df.left = mOverscanScreenLeft;
4356 pf.top = df.top = mOverscanScreenTop;
4357 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4358 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4359 of.left = cf.left = mUnrestrictedScreenLeft;
4360 of.top = cf.top = mUnrestrictedScreenTop;
4361 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4362 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004363 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004364 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4365 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4366 // Asking to layout into the overscan region, so give it that pure
4367 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004368 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4369 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4370 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004371 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004372 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004373 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004374 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004375 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004376 && (attrs.type == TYPE_STATUS_BAR
4377 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01004378 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004379 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004380 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4381 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004382 // Asking for layout as if the nav bar is hidden, lets the
4383 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004384 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004385 // can be above the nav bar can do this.
4386 // XXX This assumes that an app asking for this will also
4387 // ask for layout in only content. We can't currently figure out
4388 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004389 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4390 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4391 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4392 + mUnrestrictedScreenWidth;
4393 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4394 + mUnrestrictedScreenHeight;
Jorim Jaggi9f6798a2016-02-10 22:16:06 -08004395 } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) {
4396 pf.left = df.left = of.left = mRestrictedScreenLeft;
4397 pf.top = df.top = of.top = mRestrictedScreenTop;
4398 pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4399 pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop
4400 + mRestrictedScreenHeight;
4401 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4402 cf.left = mDockLeft;
4403 cf.top = mDockTop;
4404 cf.right = mDockRight;
4405 cf.bottom = mDockBottom;
4406 } else {
4407 cf.left = mContentLeft;
4408 cf.top = mContentTop;
4409 cf.right = mContentRight;
4410 cf.bottom = mContentBottom;
4411 }
Joe Onorato29fc2c92010-11-24 10:26:50 -08004412 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004413 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4414 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4415 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4416 + mRestrictedScreenWidth;
4417 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4418 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004419 }
Craig Mautner69b08182012-09-05 13:07:13 -07004420
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004421 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004422
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004423 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4424 vf.left = mCurLeft;
4425 vf.top = mCurTop;
4426 vf.right = mCurRight;
4427 vf.bottom = mCurBottom;
4428 } else {
4429 vf.set(cf);
4430 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004431 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004432 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4433 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004434 // A child window should be placed inside of the same visible
4435 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004436 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004437 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004438 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4439 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004440 // Otherwise, a normal window must be placed inside the content
4441 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004442 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4443 // Status bar panels and the volume dialog are the only windows who can go on
4444 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004445 // permission, so they have the same privileges as the status
4446 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004447 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4448 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4449 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4450 + mRestrictedScreenWidth;
4451 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4452 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004453 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004454 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004455 pf.left = df.left = of.left = cf.left = mStableLeft;
4456 pf.top = df.top = of.top = cf.top = mStableTop;
4457 pf.right = df.right = of.right = cf.right = mStableRight;
4458 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004459 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004460 pf.left = mContentLeft;
4461 pf.top = mContentTop;
4462 pf.right = mContentRight;
4463 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004464 if (win.isVoiceInteraction()) {
4465 df.left = of.left = cf.left = mVoiceContentLeft;
4466 df.top = of.top = cf.top = mVoiceContentTop;
4467 df.right = of.right = cf.right = mVoiceContentRight;
4468 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4469 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004470 df.left = of.left = cf.left = mDockLeft;
4471 df.top = of.top = cf.top = mDockTop;
4472 df.right = of.right = cf.right = mDockRight;
4473 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004474 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004475 df.left = of.left = cf.left = mContentLeft;
4476 df.top = of.top = cf.top = mContentTop;
4477 df.right = of.right = cf.right = mContentRight;
4478 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004479 }
4480 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4481 vf.left = mCurLeft;
4482 vf.top = mCurTop;
4483 vf.right = mCurRight;
4484 vf.bottom = mCurBottom;
4485 } else {
4486 vf.set(cf);
4487 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004488 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004489 }
4490 }
Craig Mautner69b08182012-09-05 13:07:13 -07004491
Craig Mautnerb816bed2013-07-23 10:26:17 -07004492 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4493 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004494 df.left = df.top = -10000;
4495 df.right = df.bottom = 10000;
4496 if (attrs.type != TYPE_WALLPAPER) {
4497 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4498 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4499 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004500 }
4501
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004502 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4503 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004504 // We only want to apply outsets to certain types of windows. For example, we never want to
4505 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004506 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004507 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004508 osf = mTmpOutsetFrame;
4509 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4510 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4511 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004512 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004513 if (rotation == Surface.ROTATION_0) {
4514 osf.bottom += outset;
4515 } else if (rotation == Surface.ROTATION_90) {
4516 osf.right += outset;
4517 } else if (rotation == Surface.ROTATION_180) {
4518 osf.top -= outset;
4519 } else if (rotation == Surface.ROTATION_270) {
4520 osf.left -= outset;
4521 }
4522 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4523 + " with rotation " + rotation + ", result: " + osf);
4524 }
4525 }
4526
Craig Mautnereda67292013-04-28 13:50:14 -07004527 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004528 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004529 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004530 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004531 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004532 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004533 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004534 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004535 + " sf=" + sf.toShortString()
4536 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004537
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004538 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004539
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004540 // Dock windows carve out the bottom of the screen, so normal windows
4541 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004542 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4543 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004544 setLastInputMethodWindowLw(null, null);
4545 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004546 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004547 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4548 && !win.getGivenInsetsPendingLw()) {
4549 offsetVoiceInputWindowLw(win);
4550 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004551 }
4552
satok1bc0a492012-04-25 22:47:12 +09004553 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004554 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004555 top += win.getGivenContentInsetsLw().top;
4556 if (mContentBottom > top) {
4557 mContentBottom = top;
4558 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004559 if (mVoiceContentBottom > top) {
4560 mVoiceContentBottom = top;
4561 }
satok1bc0a492012-04-25 22:47:12 +09004562 top = win.getVisibleFrameLw().top;
4563 top += win.getGivenVisibleInsetsLw().top;
4564 if (mCurBottom > top) {
4565 mCurBottom = top;
4566 }
Craig Mautnereda67292013-04-28 13:50:14 -07004567 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004568 + mDockBottom + " mContentBottom="
4569 + mContentBottom + " mCurBottom=" + mCurBottom);
4570 }
4571
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004572 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004573 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004574 top += win.getGivenContentInsetsLw().top;
4575 if (mVoiceContentBottom > top) {
4576 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004577 }
4578 }
4579
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004580 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004581 @Override
4582 public void finishLayoutLw() {
4583 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004584 }
4585
4586 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004587 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004588 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004589 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004590 mTopFullscreenOpaqueOrDimmingWindowState = null;
Jorim Jaggi86905582016-02-09 21:36:09 -08004591 mTopDockedOpaqueWindowState = null;
4592 mTopDockedOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004593 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004594 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004595 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004596 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004597 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004598 mForcingShowNavBar = false;
4599 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004600
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004601 mHideLockScreen = false;
4602 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004603 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004604 mShowingLockscreen = false;
4605 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004606 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004607 mKeyguardSecure = isKeyguardSecure();
4608 mKeyguardSecureIncludingHidden = mKeyguardSecure
4609 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004610 }
4611
4612 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004613 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004614 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4615 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004616 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4617 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004618 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004619 if (mTopFullscreenOpaqueWindowState == null
4620 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4621 mForcingShowNavBar = true;
4622 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004623 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004624 if (attrs.type == TYPE_STATUS_BAR) {
4625 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4626 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004627 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004628 }
4629 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4630 mForceStatusBarTransparent = true;
4631 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004632 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004633
4634 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4635 && attrs.type < FIRST_SYSTEM_WINDOW;
4636 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4637 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Jorim Jaggi86905582016-02-09 21:36:09 -08004638 final int stackId = win.getStackId();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004639 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004640 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004641 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004642 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004643 mForceStatusBarFromKeyguard = true;
4644 } else {
4645 mForceStatusBar = true;
4646 }
4647 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004648 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004649 // If the lockscreen was showing when the dream started then wait
4650 // for the dream to draw before hiding the lockscreen.
4651 if (!mDreamingLockscreen
4652 || (win.isVisibleLw() && win.hasDrawnLw())) {
4653 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004654 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004655 }
4656 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004657
Yohei Yukawad1a09222015-06-30 16:22:05 -07004658 final IApplicationToken appToken = win.getAppToken();
4659
4660 // For app windows that are not attached, we decide if all windows in the app they
4661 // represent should be hidden or if we should hide the lockscreen. For attached app
4662 // windows we defer the decision to the window it is attached to.
4663 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004664 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004665 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004666 mAppsToBeHidden.remove(appToken);
4667 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004668 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004669 if (dismissKeyguard && !mKeyguardSecure) {
4670 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004671 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004672 mWinShowWhenLocked = win;
4673 mHideLockScreen = true;
4674 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004675 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004676 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004677 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004678 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004679 mAppsToBeHidden.add(appToken);
4680 } else {
4681 mAppsToBeHidden.remove(appToken);
4682 }
4683 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004684 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004685 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004686 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004687 if (isFullscreen(attrs) && StackId.normallyFullscreenWindows(stackId)) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004688 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4689 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004690 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4691 mTopFullscreenOpaqueOrDimmingWindowState = win;
4692 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004693 if (!mAppsThatDismissKeyguard.isEmpty() &&
4694 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4695 if (DEBUG_LAYOUT) Slog.v(TAG,
4696 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004697 mDismissKeyguard = (mWinDismissingKeyguard == win
4698 && mSecureDismissingKeyguard == mKeyguardSecure)
4699 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004700 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004701 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004702 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004703 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4704 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004705 if (DEBUG_LAYOUT) Slog.v(TAG,
4706 "Setting mHideLockScreen to true by win " + win);
4707 mHideLockScreen = true;
4708 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004709 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004710 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004711 mAllowLockscreenWhenOn = true;
4712 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004713 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004714
4715 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004716 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4717 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004718 win.hideLw(false);
4719 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004720 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004721 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4722 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4723 // that is being hidden in an animation - keep the
4724 // keyguard hidden until the new window shows up and
4725 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004726 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004727 mHideLockScreen = true;
4728 mWinShowWhenLocked = win;
4729 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004730 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004731
4732 // Keep track of the window if it's dimming but not necessarily fullscreen.
4733 final boolean reallyVisible = win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw();
4734 if (mTopFullscreenOpaqueOrDimmingWindowState == null && reallyVisible
4735 && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01004736 mTopFullscreenOpaqueOrDimmingWindowState = win;
4737 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004738
4739 // We need to keep track of the top "fullscreen" opaque window for the docked stack
4740 // separately, because both the "real fullscreen" opaque window and the one for the docked
4741 // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.
4742 if (mTopDockedOpaqueWindowState == null && reallyVisible && appWindow && attached == null
4743 && isFullscreen(attrs) && stackId == DOCKED_STACK_ID) {
4744 mTopDockedOpaqueWindowState = win;
4745 if (mTopDockedOpaqueOrDimmingWindowState == null) {
4746 mTopDockedOpaqueOrDimmingWindowState = win;
4747 }
4748 }
4749
4750 // Also keep track of any windows that are dimming but not necessarily fullscreen in the
4751 // docked stack.
4752 if (mTopDockedOpaqueOrDimmingWindowState == null && reallyVisible && win.isDimming()
4753 && stackId == DOCKED_STACK_ID) {
4754 mTopDockedOpaqueOrDimmingWindowState = win;
4755 }
4756 }
4757
4758 private boolean isFullscreen(WindowManager.LayoutParams attrs) {
4759 return attrs.x == 0 && attrs.y == 0
4760 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4761 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004762 }
4763
4764 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004765 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004766 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004767 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4768 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4769 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004770 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4771 // fullscreen window.
4772 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4773 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4774 mTopFullscreenOpaqueWindowState.hideLw(false);
4775 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4776 }
4777
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004778 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004779 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004780
4781 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4782 ? mTopFullscreenOpaqueWindowState.getAttrs()
4783 : null;
4784
Jeff Brownc8018eb2012-10-29 21:33:27 -07004785 // If we are not currently showing a dream then remember the current
4786 // lockscreen state. We will use this to determine whether the dream
4787 // started while the lockscreen was showing and remember this state
4788 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004789 if (!mShowingDream) {
4790 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004791 if (mDreamingSleepTokenNeeded) {
4792 mDreamingSleepTokenNeeded = false;
4793 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4794 }
4795 } else {
4796 if (!mDreamingSleepTokenNeeded) {
4797 mDreamingSleepTokenNeeded = true;
4798 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4799 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004800 }
4801
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004802 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004803 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004804 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004805 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004806 boolean shouldBeTransparent = mForceStatusBarTransparent
4807 && !mForceStatusBar
4808 && !mForceStatusBarFromKeyguard;
4809 if (!shouldBeTransparent) {
4810 mStatusBarController.setShowTransparent(false /* transparent */);
4811 } else if (!mStatusBar.isVisibleLw()) {
4812 mStatusBarController.setShowTransparent(true /* transparent */);
4813 }
4814 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004815 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004816 if (mStatusBarController.setBarShowingLw(true)) {
4817 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4818 }
Craig Mautner81defc72013-10-29 11:10:42 -07004819 // Maintain fullscreen layout until incoming animation is complete.
4820 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004821 // Transient status bar on the lockscreen is not allowed
4822 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4823 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4824 mLastSystemUiFlags, mLastSystemUiFlags);
4825 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004826 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004827 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004828 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004829 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004830 + " shown position: "
4831 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004832 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004833 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004834 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004835 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004836 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004837 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004838 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004839 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4840 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004841 if (mStatusBarController.isTransientShowing()) {
4842 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004843 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4844 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07004845 } else if (topIsFullscreen
4846 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
4847 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07004848 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004849 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004850 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004851 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004852 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004853 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004854 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004855 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004856 if (mStatusBarController.setBarShowingLw(true)) {
4857 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4858 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004859 }
4860 }
4861 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004862
Craig Mautner81defc72013-10-29 11:10:42 -07004863 if (mTopIsFullscreen != topIsFullscreen) {
4864 if (!topIsFullscreen) {
4865 // Force another layout when status bar becomes fully shown.
4866 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4867 }
4868 mTopIsFullscreen = topIsFullscreen;
4869 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004870
Craig Mautner39834192012-09-02 07:47:24 -07004871 // Hide the key guard if a visible window explicitly specifies that it wants to be
4872 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004873 if (mKeyguardDelegate != null && mStatusBar != null) {
4874 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4875 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004876 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004877 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004878 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004879 changes |= FINISH_LAYOUT_REDO_LAYOUT
4880 | FINISH_LAYOUT_REDO_CONFIG
4881 | FINISH_LAYOUT_REDO_WALLPAPER;
4882 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004883 if (mKeyguardDelegate.isShowing()) {
4884 mHandler.post(new Runnable() {
4885 @Override
4886 public void run() {
4887 mKeyguardDelegate.keyguardDone(false, false);
4888 }
4889 });
4890 }
4891 } else if (mHideLockScreen) {
4892 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004893 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004894 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004895 changes |= FINISH_LAYOUT_REDO_LAYOUT
4896 | FINISH_LAYOUT_REDO_CONFIG
4897 | FINISH_LAYOUT_REDO_WALLPAPER;
4898 }
4899 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004900 mKeyguardHidden = false;
4901 if (setKeyguardOccludedLw(false)) {
4902 changes |= FINISH_LAYOUT_REDO_LAYOUT
4903 | FINISH_LAYOUT_REDO_CONFIG
4904 | FINISH_LAYOUT_REDO_WALLPAPER;
4905 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004906 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4907 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004908 mHandler.post(new Runnable() {
4909 @Override
4910 public void run() {
4911 mKeyguardDelegate.dismiss();
4912 }
4913 });
4914 }
4915 } else {
4916 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004917 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004918 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004919 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004920 changes |= FINISH_LAYOUT_REDO_LAYOUT
4921 | FINISH_LAYOUT_REDO_CONFIG
4922 | FINISH_LAYOUT_REDO_WALLPAPER;
4923 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004924 }
4925 }
Joe Onorato664644d2011-01-23 17:53:23 -08004926
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004927 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004928 // If the navigation bar has been hidden or shown, we need to do another
4929 // layout pass to update that window.
4930 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4931 }
Joe Onorato664644d2011-01-23 17:53:23 -08004932
Mike Lockwood28569302010-01-28 11:54:40 -05004933 // update since mAllowLockscreenWhenOn might have changed
4934 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004935 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004936 }
4937
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004938 /**
Jim Millerab954542014-10-10 18:21:49 -07004939 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004940 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004941 * @return Whether the flags have changed and we have to redo the layout.
4942 */
Jim Millerab954542014-10-10 18:21:49 -07004943 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4944 boolean wasOccluded = mKeyguardOccluded;
4945 boolean showing = mKeyguardDelegate.isShowing();
4946 if (wasOccluded && !isOccluded && showing) {
4947 mKeyguardOccluded = false;
4948 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004949 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4950 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4951 return true;
Jim Millerab954542014-10-10 18:21:49 -07004952 } else if (!wasOccluded && isOccluded && showing) {
4953 mKeyguardOccluded = true;
4954 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004955 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4956 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4957 return true;
4958 } else {
4959 return false;
4960 }
4961 }
4962
4963 private boolean isStatusBarKeyguard() {
4964 return mStatusBar != null
4965 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4966 }
4967
Jose Lima9546b202014-07-02 17:21:51 -07004968 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004969 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004970 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004971 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004972 return false;
4973 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004974 return true;
4975 }
4976
Jose Lima9546b202014-07-02 17:21:51 -07004977 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004978 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004979 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004980 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004981 // If the navigation bar has been hidden or shown, we need to do another
4982 // layout pass to update that window.
4983 return FINISH_LAYOUT_REDO_LAYOUT;
4984 }
4985 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004986 }
4987
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004988 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004989 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004990 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4991 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004992 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4993 if (newLidState == mLidState) {
4994 return;
4995 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004996
Jeff Brownc458ce92012-04-30 14:58:40 -07004997 mLidState = newLidState;
4998 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07004999 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07005000
5001 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005002 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
5003 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07005004 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07005005 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005006 }
5007 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005008
Michael Wright3818c922014-09-02 13:59:07 -07005009 @Override
5010 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
5011 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
5012 if (mCameraLensCoverState == lensCoverState) {
5013 return;
5014 }
5015 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
5016 lensCoverState == CAMERA_LENS_UNCOVERED) {
5017 Intent intent;
5018 final boolean keyguardActive = mKeyguardDelegate == null ? false :
5019 mKeyguardDelegate.isShowing();
5020 if (keyguardActive) {
5021 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
5022 } else {
5023 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
5024 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005025 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
5026 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00005027 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07005028 }
5029 mCameraLensCoverState = lensCoverState;
5030 }
5031
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005032 void setHdmiPlugged(boolean plugged) {
5033 if (mHdmiPlugged != plugged) {
5034 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005035 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005036 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08005037 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005038 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07005039 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005040 }
5041 }
5042
Joe Onoratoea495d42011-04-06 11:41:11 -07005043 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07005044 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07005045 // watch for HDMI plug messages if the hdmi switch exists
5046 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
5047 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
5048
Joe Onoratoea495d42011-04-06 11:41:11 -07005049 final String filename = "/sys/class/switch/hdmi/state";
5050 FileReader reader = null;
5051 try {
5052 reader = new FileReader(filename);
5053 char[] buf = new char[15];
5054 int n = reader.read(buf);
5055 if (n > 1) {
5056 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
5057 }
5058 } catch (IOException ex) {
5059 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5060 } catch (NumberFormatException ex) {
5061 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5062 } finally {
5063 if (reader != null) {
5064 try {
5065 reader.close();
5066 } catch (IOException ex) {
5067 }
Joe Onoratodc100302011-01-11 17:07:41 -08005068 }
5069 }
5070 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07005071 // This dance forces the code in setHdmiPlugged to run.
5072 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
5073 mHdmiPlugged = !plugged;
5074 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08005075 }
5076
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07005077 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005078 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005079
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005080 final Runnable mScreenshotTimeout = new Runnable() {
5081 @Override public void run() {
5082 synchronized (mScreenshotLock) {
5083 if (mScreenshotConnection != null) {
5084 mContext.unbindService(mScreenshotConnection);
5085 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005086 }
Winson Chung9112ec32011-06-27 13:15:32 -07005087 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005088 }
5089 };
5090
5091 // Assume this is called from the Handler thread.
5092 private void takeScreenshot() {
5093 synchronized (mScreenshotLock) {
5094 if (mScreenshotConnection != null) {
5095 return;
5096 }
5097 ComponentName cn = new ComponentName("com.android.systemui",
5098 "com.android.systemui.screenshot.TakeScreenshotService");
5099 Intent intent = new Intent();
5100 intent.setComponent(cn);
5101 ServiceConnection conn = new ServiceConnection() {
5102 @Override
5103 public void onServiceConnected(ComponentName name, IBinder service) {
5104 synchronized (mScreenshotLock) {
5105 if (mScreenshotConnection != this) {
5106 return;
5107 }
5108 Messenger messenger = new Messenger(service);
5109 Message msg = Message.obtain(null, 1);
5110 final ServiceConnection myConn = this;
5111 Handler h = new Handler(mHandler.getLooper()) {
5112 @Override
5113 public void handleMessage(Message msg) {
5114 synchronized (mScreenshotLock) {
5115 if (mScreenshotConnection == myConn) {
5116 mContext.unbindService(mScreenshotConnection);
5117 mScreenshotConnection = null;
5118 mHandler.removeCallbacks(mScreenshotTimeout);
5119 }
5120 }
5121 }
5122 };
5123 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005124 msg.arg1 = msg.arg2 = 0;
5125 if (mStatusBar != null && mStatusBar.isVisibleLw())
5126 msg.arg1 = 1;
5127 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5128 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005129 try {
5130 messenger.send(msg);
5131 } catch (RemoteException e) {
5132 }
5133 }
5134 }
5135 @Override
5136 public void onServiceDisconnected(ComponentName name) {}
5137 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08005138 if (mContext.bindServiceAsUser(
5139 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005140 mScreenshotConnection = conn;
5141 mHandler.postDelayed(mScreenshotTimeout, 10000);
5142 }
5143 }
Winson Chung9112ec32011-06-27 13:15:32 -07005144 }
5145
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005146 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005147 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005148 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005149 if (!mSystemBooted) {
5150 // If we have not yet booted, don't let key events do anything.
5151 return 0;
5152 }
5153
Jeff Brown037c33e2014-04-09 00:31:55 -07005154 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005155 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5156 final boolean canceled = event.isCanceled();
5157 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005158
Jeff Brown3122e442010-10-11 23:32:49 -07005159 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005160
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005161 // If screen is off then we treat the case where the keyguard is open but hidden
5162 // the same as if it were open and in front.
5163 // This will prevent any keys other than the power button from waking the screen
5164 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005165 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005166 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005167 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005168 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005169
Jeff Brown40013652012-05-16 21:22:36 -07005170 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005171 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005172 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005173 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005174 }
5175
Jeff Brown037c33e2014-04-09 00:31:55 -07005176 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005177 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005178 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5179 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005180 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005181 // When the device is interactive or the key is injected pass the
5182 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005183 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005184 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07005185 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
5186 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5187 // to the application but preserve its wake key status to make sure we still move
5188 // from dozing to fully interactive if we would normally go from off to fully
5189 // interactive.
5190 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07005191 } else {
5192 // When the screen is off and the key is not injected, determine whether
5193 // to wake the device but don't pass the key to the application.
5194 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005195 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5196 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005197 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005198 }
5199
Justin Kohd378ad72013-04-01 12:18:26 -07005200 // If the key would be handled globally, just return the result, don't worry about special
5201 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005202 if (isValidGlobalKey(keyCode)
5203 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005204 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005205 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005206 }
Justin Kohd378ad72013-04-01 12:18:26 -07005207 return result;
5208 }
5209
Jeff Brownbae8e772014-06-12 19:59:45 -07005210 boolean useHapticFeedback = down
5211 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5212 && event.getRepeatCount() == 0;
5213
Jeff Brown4d396052010-10-29 21:50:21 -07005214 // Handle special keys.
5215 switch (keyCode) {
5216 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005217 case KeyEvent.KEYCODE_VOLUME_UP:
5218 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005219 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5220 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005221 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005222 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005223 mScreenshotChordVolumeDownKeyTriggered = true;
5224 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5225 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005226 cancelPendingPowerKeyAction();
5227 interceptScreenshotChord();
5228 }
5229 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005230 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005231 cancelPendingScreenshotChordAction();
5232 }
5233 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5234 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005235 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005236 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005237 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005238 cancelPendingPowerKeyAction();
5239 cancelPendingScreenshotChordAction();
5240 }
5241 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005242 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005243 cancelPendingScreenshotChordAction();
5244 }
5245 }
Jeff Brown4d396052010-10-29 21:50:21 -07005246 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005247 TelecomManager telecomManager = getTelecommService();
5248 if (telecomManager != null) {
5249 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005250 // If an incoming call is ringing, either VOLUME key means
5251 // "silence ringer". We handle these keys here, rather than
5252 // in the InCallScreen, to make sure we'll respond to them
5253 // even if the InCallScreen hasn't come to the foreground yet.
5254 // Look for the DOWN event here, to agree with the "fallback"
5255 // behavior in the InCallScreen.
5256 Log.i(TAG, "interceptKeyBeforeQueueing:"
5257 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005258
Santos Cordon6848f722014-05-21 15:22:12 -07005259 // Silence the ringer. (It's safe to call this
5260 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005261 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005262
Santos Cordon6848f722014-05-21 15:22:12 -07005263 // And *don't* pass this key thru to the current activity
5264 // (which is probably the InCallScreen.)
5265 result &= ~ACTION_PASS_TO_USER;
5266 break;
5267 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005268 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005269 && (result & ACTION_PASS_TO_USER) == 0) {
5270 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005271 // the application, just pass it to the session service.
5272
5273 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005274 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005275 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005276 }
5277 }
Jaewan Kim765487f2016-01-12 14:45:42 +09005278 }
5279 if (mUseTvRouting) {
5280 // On TVs, defer special key handlings to
5281 // {@link interceptKeyBeforeDispatching()}.
5282 result |= ACTION_PASS_TO_USER;
5283 } else if ((result & ACTION_PASS_TO_USER) == 0) {
5284 // If we aren't passing to the user and no one else
5285 // handled it send it to the session manager to
5286 // figure out.
5287 MediaSessionLegacyHelper.getHelper(mContext)
5288 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07005289 }
5290 break;
5291 }
5292
5293 case KeyEvent.KEYCODE_ENDCALL: {
5294 result &= ~ACTION_PASS_TO_USER;
5295 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005296 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005297 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005298 if (telecomManager != null) {
5299 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005300 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005301 if (interactive && !hungUp) {
5302 mEndCallKeyHandled = false;
5303 mHandler.postDelayed(mEndCallLongPress,
5304 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5305 } else {
5306 mEndCallKeyHandled = true;
5307 }
Jeff Brown4d396052010-10-29 21:50:21 -07005308 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005309 if (!mEndCallKeyHandled) {
5310 mHandler.removeCallbacks(mEndCallLongPress);
5311 if (!canceled) {
5312 if ((mEndcallBehavior
5313 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5314 if (goHome()) {
5315 break;
5316 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005317 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005318 if ((mEndcallBehavior
5319 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5320 mPowerManager.goToSleep(event.getEventTime(),
5321 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5322 isWakeKey = false;
5323 }
Jeff Brown4d396052010-10-29 21:50:21 -07005324 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005325 }
Jeff Brown4d396052010-10-29 21:50:21 -07005326 }
5327 break;
5328 }
5329
5330 case KeyEvent.KEYCODE_POWER: {
5331 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005332 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005333 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005334 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005335 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005336 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005337 }
5338 break;
5339 }
5340
Jeff Brown6212a492014-03-07 13:58:47 -08005341 case KeyEvent.KEYCODE_SLEEP: {
5342 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005343 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005344 if (!mPowerManager.isInteractive()) {
5345 useHapticFeedback = false; // suppress feedback if already non-interactive
5346 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005347 if (down) {
5348 sleepPress(event.getEventTime());
5349 } else {
5350 sleepRelease(event.getEventTime());
5351 }
Jeff Brown6212a492014-03-07 13:58:47 -08005352 break;
5353 }
5354
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005355 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5356 result &= ~ACTION_PASS_TO_USER;
5357 isWakeKey = false;
5358 if (!down) {
5359 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5360 }
5361 break;
5362 }
5363
Jeff Brown6212a492014-03-07 13:58:47 -08005364 case KeyEvent.KEYCODE_WAKEUP: {
5365 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005366 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005367 break;
5368 }
5369
Jeff Brown4d396052010-10-29 21:50:21 -07005370 case KeyEvent.KEYCODE_MEDIA_PLAY:
5371 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5372 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005373 case KeyEvent.KEYCODE_HEADSETHOOK:
5374 case KeyEvent.KEYCODE_MUTE:
5375 case KeyEvent.KEYCODE_MEDIA_STOP:
5376 case KeyEvent.KEYCODE_MEDIA_NEXT:
5377 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5378 case KeyEvent.KEYCODE_MEDIA_REWIND:
5379 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005380 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5381 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005382 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5383 // If the global session is active pass all media keys to it
5384 // instead of the active window.
5385 result &= ~ACTION_PASS_TO_USER;
5386 }
Jeff Brown4d396052010-10-29 21:50:21 -07005387 if ((result & ACTION_PASS_TO_USER) == 0) {
5388 // Only do this if we would otherwise not pass it to the user. In that
5389 // case, the PhoneWindow class will do the same thing, except it will
5390 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005391 // Note that we need to make a copy of the key event here because the
5392 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005393 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005394 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5395 new KeyEvent(event));
5396 msg.setAsynchronous(true);
5397 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005398 }
5399 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005400 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005401
Jeff Brown4d396052010-10-29 21:50:21 -07005402 case KeyEvent.KEYCODE_CALL: {
5403 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005404 TelecomManager telecomManager = getTelecommService();
5405 if (telecomManager != null) {
5406 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005407 Log.i(TAG, "interceptKeyBeforeQueueing:"
5408 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005409 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005410
Santos Cordon6848f722014-05-21 15:22:12 -07005411 // And *don't* pass this key thru to the current activity
5412 // (which is presumably the InCallScreen.)
5413 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005414 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005415 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005416 }
Jeff Brown4d396052010-10-29 21:50:21 -07005417 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005418 }
Michael Wright869a67c2014-08-26 19:33:06 -07005419 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5420 // Only do this if we would otherwise not pass it to the user. In that case,
5421 // interceptKeyBeforeDispatching would apply a similar but different policy in
5422 // order to invoke voice assist actions. Note that we need to make a copy of the
5423 // key event here because the original key event will be recycled when we return.
5424 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5425 mBroadcastWakeLock.acquire();
5426 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5427 keyguardActive ? 1 : 0, 0);
5428 msg.setAsynchronous(true);
5429 msg.sendToTarget();
5430 }
Jaewan Kim49117872016-01-19 17:24:08 +09005431 break;
5432 }
5433 case KeyEvent.KEYCODE_WINDOW: {
5434 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
5435 if (!down) {
Jaewan Kimc552b042016-01-18 16:08:45 +09005436 requestTvPictureInPicture(event);
Jaewan Kim49117872016-01-19 17:24:08 +09005437 }
5438 result &= ~ACTION_PASS_TO_USER;
5439 }
5440 break;
Michael Wright869a67c2014-08-26 19:33:06 -07005441 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005442 }
Jeff Brown26875502014-01-30 21:47:47 -08005443
Jeff Brownbae8e772014-06-12 19:59:45 -07005444 if (useHapticFeedback) {
5445 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5446 }
5447
Jeff Brown26875502014-01-30 21:47:47 -08005448 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005449 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005450 }
Bryce Lee584a4452014-10-21 15:55:55 -07005451
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005452 return result;
5453 }
5454
Jeff Brown1c2e4942012-11-06 16:32:01 -08005455 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005456 * Returns true if the key can have global actions attached to it.
5457 * We reserve all power management keys for the system since they require
5458 * very careful handling.
5459 */
5460 private static boolean isValidGlobalKey(int keyCode) {
5461 switch (keyCode) {
5462 case KeyEvent.KEYCODE_POWER:
5463 case KeyEvent.KEYCODE_WAKEUP:
5464 case KeyEvent.KEYCODE_SLEEP:
5465 return false;
5466 default:
5467 return true;
5468 }
5469 }
5470
5471 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005472 * When the screen is off we ignore some keys that might otherwise typically
5473 * be considered wake keys. We filter them out here.
5474 *
5475 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5476 * is always considered a wake key.
5477 */
5478 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5479 switch (keyCode) {
5480 // ignore volume keys unless docked
5481 case KeyEvent.KEYCODE_VOLUME_UP:
5482 case KeyEvent.KEYCODE_VOLUME_DOWN:
5483 case KeyEvent.KEYCODE_VOLUME_MUTE:
5484 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5485
5486 // ignore media and camera keys
5487 case KeyEvent.KEYCODE_MUTE:
5488 case KeyEvent.KEYCODE_HEADSETHOOK:
5489 case KeyEvent.KEYCODE_MEDIA_PLAY:
5490 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5491 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5492 case KeyEvent.KEYCODE_MEDIA_STOP:
5493 case KeyEvent.KEYCODE_MEDIA_NEXT:
5494 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5495 case KeyEvent.KEYCODE_MEDIA_REWIND:
5496 case KeyEvent.KEYCODE_MEDIA_RECORD:
5497 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005498 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005499 case KeyEvent.KEYCODE_CAMERA:
5500 return false;
5501 }
5502 return true;
5503 }
5504
5505
Jeff Brown56194eb2011-03-02 19:23:13 -08005506 /** {@inheritDoc} */
5507 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005508 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5509 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005510 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5511 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005512 return 0;
5513 }
Michael Wright70af00a2014-09-03 19:30:20 -07005514 }
Bryce Lee5c138322014-11-03 08:26:09 -08005515
Michael Wright70af00a2014-09-03 19:30:20 -07005516 if (shouldDispatchInputWhenNonInteractive()) {
5517 return ACTION_PASS_TO_USER;
5518 }
Bryce Lee5c138322014-11-03 08:26:09 -08005519
Bryce Lee812d7022014-11-10 13:33:28 -08005520 // If we have not passed the action up and we are in theater mode without dreaming,
5521 // there will be no dream to intercept the touch and wake into ambient. The device should
5522 // wake up in this case.
5523 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005524 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5525 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005526 }
5527
Jeff Brown037c33e2014-04-09 00:31:55 -07005528 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005529 }
5530
Michael Wright70af00a2014-09-03 19:30:20 -07005531 private boolean shouldDispatchInputWhenNonInteractive() {
Joe LaPennaf2b9b2d2015-11-17 22:22:37 +00005532 // Send events to keyguard while the screen is on.
5533 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5534 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005535 return true;
5536 }
5537
5538 // Send events to a dozing dream even if the screen is off since the dream
5539 // is in control of the state of the screen.
5540 IDreamManager dreamManager = getDreamManager();
5541
5542 try {
5543 if (dreamManager != null && dreamManager.isDreaming()) {
5544 return true;
5545 }
5546 } catch (RemoteException e) {
5547 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5548 }
5549
5550 // Otherwise, consume events since the user can't see what is being
5551 // interacted with.
5552 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005553 }
5554
RoboErik001c59c2015-01-26 15:53:51 -08005555 private void dispatchDirectAudioEvent(KeyEvent event) {
5556 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5557 return;
5558 }
5559 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005560 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5561 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005562 String pkgName = mContext.getOpPackageName();
5563 switch (keyCode) {
5564 case KeyEvent.KEYCODE_VOLUME_UP:
5565 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005566 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005567 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005568 } catch (RemoteException e) {
5569 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5570 }
5571 break;
5572 case KeyEvent.KEYCODE_VOLUME_DOWN:
5573 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005574 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005575 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005576 } catch (RemoteException e) {
5577 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5578 }
5579 break;
5580 case KeyEvent.KEYCODE_VOLUME_MUTE:
5581 try {
5582 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005583 getAudioService().adjustSuggestedStreamVolume(
5584 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005585 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005586 }
5587 } catch (RemoteException e) {
5588 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5589 }
5590 break;
5591 }
5592 }
5593
Jeff Brown40013652012-05-16 21:22:36 -07005594 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5595 if (DEBUG_INPUT) {
5596 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005597 }
5598
Jeff Brown40013652012-05-16 21:22:36 -07005599 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5600 if (DEBUG_INPUT) {
5601 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5602 }
5603
5604 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5605 mHavePendingMediaKeyRepeatWithWakeLock = false;
5606 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5607 }
5608
5609 dispatchMediaKeyWithWakeLockToAudioService(event);
5610
5611 if (event.getAction() == KeyEvent.ACTION_DOWN
5612 && event.getRepeatCount() == 0) {
5613 mHavePendingMediaKeyRepeatWithWakeLock = true;
5614
5615 Message msg = mHandler.obtainMessage(
5616 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5617 msg.setAsynchronous(true);
5618 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5619 } else {
5620 mBroadcastWakeLock.release();
5621 }
5622 }
5623
5624 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5625 mHavePendingMediaKeyRepeatWithWakeLock = false;
5626
5627 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5628 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5629 if (DEBUG_INPUT) {
5630 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5631 }
5632
5633 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5634 mBroadcastWakeLock.release();
5635 }
5636
5637 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5638 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005639 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005640 }
5641 }
5642
Michael Wright869a67c2014-08-26 19:33:06 -07005643 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005644 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5645 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5646 if (dic != null) {
5647 try {
5648 dic.exitIdle("voice-search");
5649 } catch (RemoteException e) {
5650 }
5651 }
Michael Wright869a67c2014-08-26 19:33:06 -07005652 Intent voiceIntent =
5653 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5654 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005655 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005656 mBroadcastWakeLock.release();
5657 }
5658
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005659 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005660 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005661 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005662 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5663 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5664 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005665 } else {
5666 try {
5667 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5668 ServiceManager.getService(Context.UI_MODE_SERVICE));
5669 mUiMode = uiModeService.getCurrentModeType();
5670 } catch (RemoteException e) {
5671 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005672 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005673 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005674 synchronized (mLock) {
5675 updateOrientationListenerLp();
5676 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005677 }
5678 };
5679
Jeff Brown6aaf2952012-10-05 16:01:08 -07005680 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5681 @Override
5682 public void onReceive(Context context, Intent intent) {
5683 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005684 if (mKeyguardDelegate != null) {
5685 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005686 }
5687 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005688 if (mKeyguardDelegate != null) {
5689 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005690 }
5691 }
5692 }
5693 };
5694
Christopher Tate5e08af02012-09-21 17:17:22 -07005695 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5696 @Override
5697 public void onReceive(Context context, Intent intent) {
5698 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5699 // tickle the settings observer: this first ensures that we're
5700 // observing the relevant settings for the newly-active user,
5701 // and then updates our own bookkeeping based on the now-
5702 // current user.
5703 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005704
5705 // force a re-application of focused window sysui visibility.
5706 // the window may never have been shown for this user
5707 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005708 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005709 mLastSystemUiFlags = 0;
5710 updateSystemUiVisibilityLw();
5711 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005712 }
5713 }
5714 };
5715
Adrian Roosddc8b272015-05-21 16:28:27 -07005716 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005717 @Override
5718 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005719 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5720 if (!isUserSetupComplete()) {
5721 // Swipe-up for navigation bar is disabled during setup
5722 return;
5723 }
5724 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5725 mNavigationBarController.showTransient();
5726 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005727 }
5728 };
5729
John Spurlocke1f366f2013-08-05 12:22:40 -04005730 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005731 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005732 if (!isUserSetupComplete()) {
5733 // Swipe-up for navigation bar is disabled during setup
5734 return;
5735 }
John Spurlock27735a42013-08-14 17:57:38 -04005736 boolean sb = mStatusBarController.checkShowTransientBarLw();
5737 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005738 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005739 // Don't show status bar when swiping on already visible navigation bar
5740 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005741 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005742 return;
5743 }
John Spurlock27735a42013-08-14 17:57:38 -04005744 if (sb) mStatusBarController.showTransient();
5745 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005746 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005747 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005748 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005749 }
5750 }
5751
Jeff Brown3ee549c2014-09-22 20:14:39 -07005752 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005753 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005754 public void startedGoingToSleep(int why) {
5755 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005756 if (mKeyguardDelegate != null) {
5757 mKeyguardDelegate.onStartedGoingToSleep(why);
5758 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005759 }
5760
5761 // Called on the PowerManager's Notifier thread.
5762 @Override
5763 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005764 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005765 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005766 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005767
5768 // We must get this work done here because the power manager will drop
5769 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005770 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005771 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005772 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005773 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005774 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005775 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005776 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005777 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005778 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005779 }
5780
Jeff Brown3ee549c2014-09-22 20:14:39 -07005781 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005782 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005783 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005784 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005785 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005786
Jeff Brown3ee549c2014-09-22 20:14:39 -07005787 // Since goToSleep performs these functions synchronously, we must
5788 // do the same here. We cannot post this work to a handler because
5789 // that might cause it to become reordered with respect to what
5790 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005791 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005792 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005793
Jeff Browna20dda42014-05-27 20:57:24 -07005794 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005795 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005796 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005797 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005798
Jim Miller5ecd8112013-01-09 18:50:26 -08005799 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005800 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005801 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005802 }
5803
Jeff Brown416c49c2015-05-26 19:50:18 -07005804 // Called on the PowerManager's Notifier thread.
5805 @Override
5806 public void finishedWakingUp() {
5807 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5808 }
5809
5810 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005811 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07005812 }
5813
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005814 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07005815 final boolean theaterModeEnabled = isTheaterModeEnabled();
5816 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005817 return false;
5818 }
5819
Bryce Leed3896842015-06-23 17:06:51 -07005820 if (theaterModeEnabled) {
5821 Settings.Global.putInt(mContext.getContentResolver(),
5822 Settings.Global.THEATER_MODE_ON, 0);
5823 }
5824
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005825 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07005826 return true;
5827 }
5828
Jeff Brown36c4db82014-09-19 12:05:31 -07005829 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005830 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07005831 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005832 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005833 }
5834
Jeff Brown36c4db82014-09-19 12:05:31 -07005835 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005836 if (mKeyguardDelegate != null) {
5837 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5838 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005839 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005840 }
5841
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005842 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5843 // as well as enabling the orientation change logic/sensor.
5844 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5845 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005846 }
5847
5848 // Called on the DisplayManager's DisplayPowerController thread.
5849 @Override
5850 public void screenTurnedOff() {
5851 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5852
Jeff Brown48d1b142015-06-10 16:36:03 -07005853 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005854 synchronized (mLock) {
5855 mScreenOnEarly = false;
5856 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005857 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005858 mWindowManagerDrawComplete = false;
5859 mScreenOnListener = null;
5860 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005861
5862 if (mKeyguardDelegate != null) {
5863 mKeyguardDelegate.onScreenTurnedOff();
5864 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005865 }
5866 }
5867
Jeff Brown3ee549c2014-09-22 20:14:39 -07005868 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005869 @Override
5870 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005871 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005872
Jeff Brown48d1b142015-06-10 16:36:03 -07005873 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005874 synchronized (mLock) {
5875 mScreenOnEarly = true;
5876 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005877 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005878 mWindowManagerDrawComplete = false;
5879 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07005880
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005881 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07005882 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5883 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005884 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
5885 } else {
5886 if (DEBUG_WAKEUP) Slog.d(TAG,
5887 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
5888 finishKeyguardDrawn();
5889 }
5890 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005891 }
5892
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005893 // Called on the DisplayManager's DisplayPowerController thread.
5894 @Override
5895 public void screenTurnedOn() {
5896 synchronized (mLock) {
5897 if (mKeyguardDelegate != null) {
5898 mKeyguardDelegate.onScreenTurnedOn();
5899 }
5900 }
5901 }
5902
Jeff Brown36c4db82014-09-19 12:05:31 -07005903 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005904 synchronized (mLock) {
5905 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005906 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005907 }
5908
Jeff Brown36c4db82014-09-19 12:05:31 -07005909 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005910 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005911
5912 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005913 }
5914
Craig Mautner8a0da012014-05-31 15:13:37 -07005915 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005916 synchronized (mLock) {
5917 // We have just finished drawing screen content. Since the orientation listener
5918 // gets only installed when all windows are drawn, we try to install it again.
5919 updateOrientationListenerLp();
5920 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005921 final ScreenOnListener listener;
5922 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005923 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005924 if (DEBUG_WAKEUP) Slog.d(TAG,
5925 "finishScreenTurningOn: mAwake=" + mAwake
5926 + ", mScreenOnEarly=" + mScreenOnEarly
5927 + ", mScreenOnFully=" + mScreenOnFully
5928 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5929 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5930
5931 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5932 || (mAwake && !mKeyguardDrawComplete)) {
5933 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005934 }
5935
Jeff Brown3ee549c2014-09-22 20:14:39 -07005936 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5937 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005938 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005939 mScreenOnFully = true;
5940
5941 // Remember the first time we draw the keyguard so we know when we're done with
5942 // the main part of booting and can enable the screen and hide boot messages.
5943 if (!mKeyguardDrawnOnce && mAwake) {
5944 mKeyguardDrawnOnce = true;
5945 enableScreen = true;
5946 if (mBootMessageNeedsHiding) {
5947 mBootMessageNeedsHiding = false;
5948 hideBootMessages();
5949 }
5950 } else {
5951 enableScreen = false;
5952 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005953 }
5954
Jeff Brown3ee549c2014-09-22 20:14:39 -07005955 if (listener != null) {
5956 listener.onScreenOn();
5957 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005958
Jeff Brown3ee549c2014-09-22 20:14:39 -07005959 if (enableScreen) {
5960 try {
5961 mWindowManager.enableScreenIfNeeded();
5962 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005963 }
Craig Mautnera631d492014-08-05 15:16:01 -07005964 }
5965 }
5966
5967 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005968 synchronized (mLock) {
5969 if (!mKeyguardDrawnOnce) {
5970 mBootMessageNeedsHiding = true;
5971 return; // keyguard hasn't drawn the first time yet, not done booting
5972 }
Craig Mautnera631d492014-08-05 15:16:01 -07005973 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005974
5975 if (mBootMsgDialog != null) {
5976 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5977 mBootMsgDialog.dismiss();
5978 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005979 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005980 }
5981
5982 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005983 public boolean isScreenOn() {
5984 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005985 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005986
Dianne Hackborn08743722009-12-21 12:16:51 -08005987 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005988 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005989 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005990 if (mKeyguardDelegate != null) {
5991 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005992 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005993 }
5994
5995 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005996 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005997 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005998 if (mKeyguardDelegate != null) {
5999 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006000 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006001 }
6002
Jim Millerab954542014-10-10 18:21:49 -07006003 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006004 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07006005 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006006 }
6007
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006008 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006009 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006010 public boolean isKeyguardLocked() {
6011 return keyguardOn();
6012 }
6013
6014 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006015 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006016 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006017 if (mKeyguardDelegate == null) return false;
6018 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006019 }
6020
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006021 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006022 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07006023 public boolean isKeyguardShowingOrOccluded() {
6024 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
6025 }
6026
6027 /** {@inheritDoc} */
6028 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006029 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006030 if (mKeyguardDelegate == null) return false;
6031 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006032 }
6033
Jose Lima9546b202014-07-02 17:21:51 -07006034 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006035 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07006036 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006037 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05006038 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07006039 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05006040 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02006041 // ask the keyguard to prompt the user to authenticate if necessary
6042 mKeyguardDelegate.dismiss();
6043 }
6044 });
6045 }
6046 }
6047
6048 public void notifyActivityDrawnForKeyguardLw() {
6049 if (mKeyguardDelegate != null) {
6050 mHandler.post(new Runnable() {
6051 @Override
6052 public void run() {
6053 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05006054 }
6055 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006056 }
6057 }
6058
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006059 @Override
6060 public boolean isKeyguardDrawnLw() {
6061 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006062 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006063 }
6064 }
6065
Jorim Jaggi0d674622014-05-21 01:34:15 +02006066 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006067 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02006068 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006069 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006070 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02006071 }
6072 }
6073
Jorim Jaggi737af722015-12-31 10:42:27 +01006074 @Override
6075 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6076 Rect outInsets) {
6077 outInsets.setEmpty();
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006078
6079 // Navigation bar and status bar.
6080 getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets);
Jorim Jaggi737af722015-12-31 10:42:27 +01006081 if (mStatusBar != null) {
6082 outInsets.top = mStatusBarHeight;
6083 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006084 }
6085
6086 @Override
6087 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6088 Rect outInsets) {
6089 outInsets.setEmpty();
6090
6091 // Only navigation bar
Jorim Jaggi737af722015-12-31 10:42:27 +01006092 if (mNavigationBar != null) {
6093 if (isNavigationBarOnBottom(displayWidth, displayHeight)) {
6094 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
6095 } else {
6096 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
6097 }
6098 }
6099 }
6100
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006101 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006102 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006103 }
6104
6105 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006106 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006107 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006108
Jeff Brown01a98dd2011-09-20 15:08:29 -07006109 @Override
6110 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006111 if (false) {
6112 Slog.v(TAG, "rotationForOrientationLw(orient="
6113 + orientation + ", last=" + lastRotation
6114 + "); user=" + mUserRotation + " "
6115 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
6116 ? "USER_ROTATION_LOCKED" : "")
6117 );
6118 }
6119
Craig Mautner46ac6fa2013-08-01 10:06:34 -07006120 if (mForceDefaultOrientation) {
6121 return Surface.ROTATION_0;
6122 }
6123
The Android Open Source Project0727d222009-03-11 12:11:58 -07006124 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07006125 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
6126 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07006127 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07006128 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006129
Jeff Browndec6cf42011-11-15 14:08:20 -08006130 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07006131 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006132 // Ignore sensor when lid switch is open and rotation is forced.
6133 preferredRotation = mLidOpenRotation;
6134 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07006135 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006136 // Ignore sensor when in car dock unless explicitly enabled.
6137 // This case can override the behavior of NOSENSOR, and can also
6138 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006139 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006140 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08006141 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6142 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
6143 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07006144 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006145 // Ignore sensor when in desk dock unless explicitly enabled.
6146 // This case can override the behavior of NOSENSOR, and can also
6147 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006148 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006149 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006150 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
6151 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08006152 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006153 preferredRotation = mDemoHdmiRotation;
6154 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
6155 && mUndockedHdmiRotation >= 0) {
6156 // Ignore sensor when plugged into HDMI and an undocked orientation has
6157 // been specified in the configuration (only for legacy devices without
6158 // full multi-display support).
6159 // Note that the dock orientation overrides the HDMI orientation.
6160 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08006161 } else if (mDemoRotationLock) {
6162 // Ignore sensor when demo rotation lock is enabled.
6163 // Note that the dock orientation and HDMI rotation lock override this.
6164 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006165 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
6166 // Application just wants to remain locked in the last rotation.
6167 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08006168 } else if (!mSupportAutoRotation) {
6169 // If we don't support auto-rotation then bail out here and ignore
6170 // the sensor and any rotation lock settings.
6171 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07006172 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07006173 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006174 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6175 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
6176 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
6177 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07006178 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
6179 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6180 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
6181 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
6182 // Otherwise, use sensor only if requested by the application or enabled
6183 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07006184 if (mAllowAllRotations < 0) {
6185 // Can't read this during init() because the context doesn't
6186 // have display metrics at that time so we cannot determine
6187 // tablet vs. phone then.
6188 mAllowAllRotations = mContext.getResources().getBoolean(
6189 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
6190 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006191 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07006192 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006193 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6194 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006195 preferredRotation = sensorRotation;
6196 } else {
6197 preferredRotation = lastRotation;
6198 }
Jeff Brown207673cd2012-06-05 17:47:11 -07006199 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
6200 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
6201 // Apply rotation lock. Does not apply to NOSENSOR.
6202 // The idea is that the user rotation expresses a weak preference for the direction
6203 // of gravity and as NOSENSOR is never affected by gravity, then neither should
6204 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07006205 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08006206 } else {
6207 // No overriding preference.
6208 // We will do exactly what the application asked us to do.
6209 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07006210 }
6211
Dianne Hackborne5439f22010-10-02 16:53:50 -07006212 switch (orientation) {
6213 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006214 // Return portrait unless overridden.
6215 if (isAnyPortrait(preferredRotation)) {
6216 return preferredRotation;
6217 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07006218 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006219
Jeff Brown01a98dd2011-09-20 15:08:29 -07006220 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006221 // Return landscape unless overridden.
6222 if (isLandscapeOrSeascape(preferredRotation)) {
6223 return preferredRotation;
6224 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006225 return mLandscapeRotation;
6226
6227 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006228 // Return reverse portrait unless overridden.
6229 if (isAnyPortrait(preferredRotation)) {
6230 return preferredRotation;
6231 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006232 return mUpsideDownRotation;
6233
6234 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006235 // Return seascape unless overridden.
6236 if (isLandscapeOrSeascape(preferredRotation)) {
6237 return preferredRotation;
6238 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006239 return mSeascapeRotation;
6240
6241 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006242 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006243 // Return either landscape rotation.
6244 if (isLandscapeOrSeascape(preferredRotation)) {
6245 return preferredRotation;
6246 }
6247 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006248 return lastRotation;
6249 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006250 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006251
Jeff Brown01a98dd2011-09-20 15:08:29 -07006252 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006253 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006254 // Return either portrait rotation.
6255 if (isAnyPortrait(preferredRotation)) {
6256 return preferredRotation;
6257 }
6258 if (isAnyPortrait(lastRotation)) {
6259 return lastRotation;
6260 }
6261 return mPortraitRotation;
6262
6263 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006264 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6265 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006266 if (preferredRotation >= 0) {
6267 return preferredRotation;
6268 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006269 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006270 }
6271 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006272 }
6273
Jeff Brown01a98dd2011-09-20 15:08:29 -07006274 @Override
6275 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6276 switch (orientation) {
6277 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6278 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6279 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6280 return isAnyPortrait(rotation);
6281
6282 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6283 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6284 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6285 return isLandscapeOrSeascape(rotation);
6286
6287 default:
6288 return true;
6289 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006290 }
6291
Jeff Brownc0347aa2011-09-23 17:26:09 -07006292 @Override
6293 public void setRotationLw(int rotation) {
6294 mOrientationListener.setCurrentRotation(rotation);
6295 }
6296
Jeff Brown01a98dd2011-09-20 15:08:29 -07006297 private boolean isLandscapeOrSeascape(int rotation) {
6298 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006299 }
6300
Jeff Brown01a98dd2011-09-20 15:08:29 -07006301 private boolean isAnyPortrait(int rotation) {
6302 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006303 }
6304
Jose Lima9546b202014-07-02 17:21:51 -07006305 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006306 public int getUserRotationMode() {
6307 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006308 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6309 WindowManagerPolicy.USER_ROTATION_FREE :
6310 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006311 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006312
6313 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006314 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006315 public void setUserRotationMode(int mode, int rot) {
6316 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006317
6318 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006319 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006320 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006321 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006322 rot,
6323 UserHandle.USER_CURRENT);
6324 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006325 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006326 0,
6327 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006328 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006329 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006330 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006331 1,
6332 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006333 }
6334 }
6335
Jose Lima9546b202014-07-02 17:21:51 -07006336 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006337 public void setSafeMode(boolean safeMode) {
6338 mSafeMode = safeMode;
6339 performHapticFeedbackLw(null, safeMode
6340 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6341 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006342 }
Craig Mautnereda67292013-04-28 13:50:14 -07006343
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006344 static long[] getLongIntArray(Resources r, int resid) {
6345 int[] ar = r.getIntArray(resid);
6346 if (ar == null) {
6347 return null;
6348 }
6349 long[] out = new long[ar.length];
6350 for (int i=0; i<ar.length; i++) {
6351 out[i] = ar[i];
6352 }
6353 return out;
6354 }
Craig Mautnereda67292013-04-28 13:50:14 -07006355
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006356 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006357 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006358 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006359 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006360 mKeyguardDelegate.onSystemReady();
6361
Michael Wright3818c922014-09-02 13:59:07 -07006362 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006363 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006364 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006365 synchronized (mLock) {
6366 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006367 mSystemReady = true;
6368 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006369 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006370 public void run() {
6371 updateSettings();
6372 }
6373 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006374
6375 bindKeyguardNow = mDeferBindKeyguard;
6376 if (bindKeyguardNow) {
6377 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6378 mDeferBindKeyguard = false;
6379 }
6380 }
6381
6382 if (bindKeyguardNow) {
6383 mKeyguardDelegate.bindService(mContext);
6384 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006385 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006386 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006387 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006388
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006389 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006390 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006391 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006392 boolean bindKeyguardNow = false;
6393 synchronized (mLock) {
6394 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6395 // in systemReady if not.
6396 if (mKeyguardDelegate != null) {
6397 bindKeyguardNow = true;
6398 } else {
6399 // Because mKeyguardDelegate is null, we know that the synchronized block in
6400 // systemReady didn't run yet and setting this will actually have an effect.
6401 mDeferBindKeyguard = true;
6402 }
6403 }
6404 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006405 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006406 mKeyguardDelegate.onBootCompleted();
6407 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006408 synchronized (mLock) {
6409 mSystemBooted = true;
6410 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006411 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006412 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006413 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006414 }
6415
Dianne Hackborn661cd522011-08-22 00:26:20 -07006416 ProgressDialog mBootMsgDialog = null;
6417
6418 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006419 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006420 public void showBootMessage(final CharSequence msg, final boolean always) {
6421 mHandler.post(new Runnable() {
6422 @Override public void run() {
6423 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006424 int theme;
Jaewan Kim49117872016-01-19 17:24:08 +09006425 if (mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006426 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
Jaewan Kim49117872016-01-19 17:24:08 +09006427 } else if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006428 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6429 } else {
6430 theme = 0;
6431 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006432
6433 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006434 // This dialog will consume all events coming in to
6435 // it, to avoid it trying to do things too early in boot.
6436 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6437 return true;
6438 }
6439 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6440 return true;
6441 }
6442 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6443 return true;
6444 }
6445 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6446 return true;
6447 }
6448 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6449 return true;
6450 }
6451 @Override public boolean dispatchPopulateAccessibilityEvent(
6452 AccessibilityEvent event) {
6453 return true;
6454 }
6455 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006456 if (mContext.getPackageManager().isUpgrade()) {
6457 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6458 } else {
6459 mBootMsgDialog.setTitle(R.string.android_start_title);
6460 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006461 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6462 mBootMsgDialog.setIndeterminate(true);
6463 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006464 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006465 mBootMsgDialog.getWindow().addFlags(
6466 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6467 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6468 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006469 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6470 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6471 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006472 mBootMsgDialog.setCancelable(false);
6473 mBootMsgDialog.show();
6474 }
6475 mBootMsgDialog.setMessage(msg);
6476 }
6477 });
6478 }
6479
6480 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006481 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006482 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006483 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006484 }
6485
Mike Lockwood28569302010-01-28 11:54:40 -05006486 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006487 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006488 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006489 // ***************************************
6490 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6491 // ***************************************
6492 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6493 // WITH ITS LOCKS HELD.
6494 //
6495 // This code must be VERY careful about the locks
6496 // it acquires.
6497 // In fact, the current code acquires way too many,
6498 // and probably has lurking deadlocks.
6499
Mike Lockwood28569302010-01-28 11:54:40 -05006500 synchronized (mScreenLockTimeout) {
6501 if (mLockScreenTimerActive) {
6502 // reset the timer
6503 mHandler.removeCallbacks(mScreenLockTimeout);
6504 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6505 }
6506 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006507 }
6508
Adam Cohenf7522022012-10-03 20:03:18 -07006509 class ScreenLockTimeout implements Runnable {
6510 Bundle options;
6511
6512 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006513 public void run() {
6514 synchronized (this) {
6515 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006516 if (mKeyguardDelegate != null) {
6517 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006518 }
Mike Lockwood28569302010-01-28 11:54:40 -05006519 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006520 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006521 }
6522 }
Mike Lockwood28569302010-01-28 11:54:40 -05006523
Adam Cohenf7522022012-10-03 20:03:18 -07006524 public void setLockOptions(Bundle options) {
6525 this.options = options;
6526 }
6527 }
6528
6529 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6530
Jose Lima9546b202014-07-02 17:21:51 -07006531 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006532 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006533 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6534 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006535 if (options != null) {
6536 // In case multiple calls are made to lockNow, we don't wipe out the options
6537 // until the runnable actually executes.
6538 mScreenLockTimeout.setLockOptions(options);
6539 }
Jim Miller93c518e2012-01-17 15:55:31 -08006540 mHandler.post(mScreenLockTimeout);
6541 }
6542
Mike Lockwood28569302010-01-28 11:54:40 -05006543 private void updateLockScreenTimeout() {
6544 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006545 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006546 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006547 if (mLockScreenTimerActive != enable) {
6548 if (enable) {
6549 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08006550 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05006551 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6552 } else {
6553 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6554 mHandler.removeCallbacks(mScreenLockTimeout);
6555 }
6556 mLockScreenTimerActive = enable;
6557 }
6558 }
6559 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006560
Jeff Brown061ea992015-04-17 19:55:47 -07006561 private void updateDreamingSleepToken(boolean acquire) {
6562 if (acquire) {
6563 if (mDreamingSleepToken == null) {
6564 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6565 }
6566 } else {
6567 if (mDreamingSleepToken != null) {
6568 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006569 mDreamingSleepToken = null;
6570 }
6571 }
6572 }
6573
6574 private void updateScreenOffSleepToken(boolean acquire) {
6575 if (acquire) {
6576 if (mScreenOffSleepToken == null) {
6577 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6578 }
6579 } else {
6580 if (mScreenOffSleepToken != null) {
6581 mScreenOffSleepToken.release();
6582 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006583 }
6584 }
6585 }
6586
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006587 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006588 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006589 public void enableScreenAfterBoot() {
6590 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006591 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006592 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006593 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006594
Jeff Brownc458ce92012-04-30 14:58:40 -07006595 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006596 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006597 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006598 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006599 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01006600 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
6601 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07006602 }
Jeff Browna20dda42014-05-27 20:57:24 -07006603
6604 synchronized (mLock) {
6605 updateWakeGestureListenerLp();
6606 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006607 }
6608
Jeff Brown4f5fa282014-06-12 19:19:15 -07006609 void updateUiMode() {
6610 if (mUiModeManager == null) {
6611 mUiModeManager = IUiModeManager.Stub.asInterface(
6612 ServiceManager.getService(Context.UI_MODE_SERVICE));
6613 }
6614 try {
6615 mUiMode = mUiModeManager.getCurrentModeType();
6616 } catch (RemoteException e) {
6617 }
6618 }
6619
Jeff Brown01a98dd2011-09-20 15:08:29 -07006620 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006621 try {
6622 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006623 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6624 } catch (RemoteException e) {
6625 // Ignore
6626 }
6627 }
6628
6629 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6630 try {
6631 //set orientation on WindowManager
6632 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006633 } catch (RemoteException e) {
6634 // Ignore
6635 }
6636 }
6637
Daniel Sandler6396c722013-04-16 20:19:09 -04006638 /**
6639 * Return an Intent to launch the currently active dock app as home. Returns
6640 * null if the standard home should be launched, which is the case if any of the following is
6641 * true:
6642 * <ul>
6643 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07006644 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04006645 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6646 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6647 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6648 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006649 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006650 */
6651 Intent createHomeDockIntent() {
6652 Intent intent = null;
6653
6654 // What home does is based on the mode, not the dock state. That
6655 // is, when in car mode you should be taken to car home regardless
6656 // of whether we are actually in a car dock.
6657 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07006658 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04006659 intent = mCarDockIntent;
6660 }
6661 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6662 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6663 intent = mDeskDockIntent;
6664 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006665 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6666 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6667 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6668 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6669 // Always launch dock home from home when watch is docked, if it exists.
6670 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006671 }
6672
6673 if (intent == null) {
6674 return null;
6675 }
6676
6677 ActivityInfo ai = null;
6678 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6679 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006680 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006681 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006682 if (info != null) {
6683 ai = info.activityInfo;
6684 }
6685 if (ai != null
6686 && ai.metaData != null
6687 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6688 intent = new Intent(intent);
6689 intent.setClassName(ai.packageName, ai.name);
6690 return intent;
6691 }
6692
6693 return null;
6694 }
6695
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006696 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6697 if (awakenFromDreams) {
6698 awakenDreams();
6699 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006700
6701 Intent dock = createHomeDockIntent();
6702 if (dock != null) {
6703 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006704 if (fromHomeKey) {
6705 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6706 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006707 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006708 return;
6709 } catch (ActivityNotFoundException e) {
6710 }
6711 }
6712
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006713 Intent intent;
6714
6715 if (fromHomeKey) {
6716 intent = new Intent(mHomeIntent);
6717 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6718 } else {
6719 intent = mHomeIntent;
6720 }
6721
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006722 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006723 }
Craig Mautnereda67292013-04-28 13:50:14 -07006724
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006725 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006726 * goes to the home screen
6727 * @return whether it did anything
6728 */
6729 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006730 if (!isUserSetupComplete()) {
6731 Slog.i(TAG, "Not going home because user setup is in progress.");
6732 return false;
6733 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006734 if (false) {
6735 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006736 try {
6737 ActivityManagerNative.getDefault().stopAppSwitches();
6738 } catch (RemoteException e) {
6739 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006740 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006741 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006742 } else {
6743 // This code brings home to the front or, if it is already
6744 // at the front, puts the device to sleep.
6745 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006746 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6747 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6748 Log.d(TAG, "UTS-TEST-MODE");
6749 } else {
6750 ActivityManagerNative.getDefault().stopAppSwitches();
6751 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006752 Intent dock = createHomeDockIntent();
6753 if (dock != null) {
6754 int result = ActivityManagerNative.getDefault()
6755 .startActivityAsUser(null, null, dock,
6756 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6757 null, null, 0,
6758 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006759 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006760 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6761 return false;
6762 }
6763 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006764 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006765 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006766 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006767 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006768 null, null, 0,
6769 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006770 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006771 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006772 return false;
6773 }
6774 } catch (RemoteException ex) {
6775 // bummer, the activity manager, which is in this process, is dead
6776 }
6777 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006778 return true;
6779 }
Craig Mautnereda67292013-04-28 13:50:14 -07006780
6781 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006782 public void setCurrentOrientationLw(int newOrientation) {
6783 synchronized (mLock) {
6784 if (newOrientation != mCurrentAppOrientation) {
6785 mCurrentAppOrientation = newOrientation;
6786 updateOrientationListenerLp();
6787 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006788 }
6789 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006790
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006791 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6792 if (!isGlobalAccessibilityGestureEnabled()) {
6793 return;
6794 }
6795 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6796 Context.AUDIO_SERVICE);
6797 if (audioManager.isSilentMode()) {
6798 return;
6799 }
6800 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6801 Settings.System.DEFAULT_NOTIFICATION_URI);
6802 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6803 ringTone.play();
6804 }
Craig Mautnereda67292013-04-28 13:50:14 -07006805
Bryce Lee584a4452014-10-21 15:55:55 -07006806 private boolean isTheaterModeEnabled() {
6807 return Settings.Global.getInt(mContext.getContentResolver(),
6808 Settings.Global.THEATER_MODE_ON, 0) == 1;
6809 }
6810
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006811 private boolean isGlobalAccessibilityGestureEnabled() {
6812 return Settings.Global.getInt(mContext.getContentResolver(),
6813 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6814 }
6815
Craig Mautnereda67292013-04-28 13:50:14 -07006816 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006817 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006818 if (!mVibrator.hasVibrator()) {
6819 return false;
6820 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006821 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6822 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006823 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006824 return false;
6825 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006826 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006827 switch (effectId) {
6828 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006829 pattern = mLongPressVibePattern;
6830 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006831 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006832 pattern = mVirtualKeyVibePattern;
6833 break;
6834 case HapticFeedbackConstants.KEYBOARD_TAP:
6835 pattern = mKeyboardTapVibePattern;
6836 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006837 case HapticFeedbackConstants.CLOCK_TICK:
6838 pattern = mClockTickVibePattern;
6839 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006840 case HapticFeedbackConstants.CALENDAR_DATE:
6841 pattern = mCalendarDateVibePattern;
6842 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006843 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006844 pattern = mSafeModeDisabledVibePattern;
6845 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006846 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006847 pattern = mSafeModeEnabledVibePattern;
6848 break;
Mady Mellore8608912015-06-05 09:02:55 -07006849 case HapticFeedbackConstants.CONTEXT_CLICK:
6850 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006851 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006852 default:
6853 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006854 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006855 int owningUid;
6856 String owningPackage;
6857 if (win != null) {
6858 owningUid = win.getOwningUid();
6859 owningPackage = win.getOwningPackage();
6860 } else {
6861 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006862 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006863 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006864 if (pattern.length == 1) {
6865 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006866 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006867 } else {
6868 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006869 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006870 }
6871 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006872 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006873
6874 @Override
6875 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006876 }
6877
Jeff Brownc38c9be2012-10-04 13:16:19 -07006878 @Override
6879 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006880 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006881 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006882 }
6883 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006884
Dianne Hackborndf89e652011-10-06 22:35:11 -07006885 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006886 // If there is no window focused, there will be nobody to handle the events
6887 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006888 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6889 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006890 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006891 return 0;
6892 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006893 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006894 // We are updating at a point where the keyguard has gotten
6895 // focus, but we were last in a state where the top window is
6896 // hiding it. This is probably because the keyguard as been
6897 // shown while the top window was displayed, so we want to ignore
6898 // it here because this is just a very transient change and it
6899 // will quickly lose focus once it correctly gets hidden.
6900 return 0;
6901 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006902
John Spurlock1db8b682014-02-18 11:18:59 -05006903 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006904 & ~mResettingSystemUiFlags
6905 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006906 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006907 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006908 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07006909
6910 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6911 tmpVisibility |= StatusBarManager.DISABLE_RECENT;
6912 }
6913
Jorim Jaggi86905582016-02-09 21:36:09 -08006914 final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */,
6915 mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState);
6916 final int dockedVisibility = updateLightStatusBarLw(0 /* vis */,
6917 mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState);
6918 mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds);
6919 mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds);
John Spurlock79da8332013-09-20 12:04:47 -04006920 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006921 final int diff = visibility ^ mLastSystemUiFlags;
Jorim Jaggi86905582016-02-09 21:36:09 -08006922 final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags;
6923 final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006924 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Jorim Jaggi86905582016-02-09 21:36:09 -08006925 if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu
6926 && mFocusedApp == win.getAppToken()
6927 && mLastNonDockedStackBounds.equals(mNonDockedStackBounds)
6928 && mLastDockedStackBounds.equals(mDockedStackBounds)) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006929 return 0;
6930 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006931 mLastSystemUiFlags = visibility;
Jorim Jaggi86905582016-02-09 21:36:09 -08006932 mLastFullscreenStackSysUiFlags = fullscreenVisibility;
6933 mLastDockedStackSysUiFlags = dockedVisibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006934 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006935 mFocusedApp = win.getAppToken();
Jorim Jaggi86905582016-02-09 21:36:09 -08006936 final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds);
6937 final Rect dockedStackBounds = new Rect(mDockedStackBounds);
Dianne Hackborndf89e652011-10-06 22:35:11 -07006938 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006939 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006940 public void run() {
Jorim Jaggi86905582016-02-09 21:36:09 -08006941 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
6942 if (statusbar != null) {
6943 statusbar.setSystemUiVisibility(visibility, fullscreenVisibility,
6944 dockedVisibility, 0xffffffff, fullscreenStackBounds,
6945 dockedStackBounds, win.toString());
6946 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006947 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006948 }
6949 });
6950 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006951 }
6952
Jorim Jaggi86905582016-02-09 21:36:09 -08006953 private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01006954 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6955 ? mStatusBar
Jorim Jaggi86905582016-02-09 21:36:09 -08006956 : opaqueOrDimming;
Adrian Rooscd3884d2015-02-18 17:25:23 +01006957
6958 if (statusColorWin != null) {
Jorim Jaggi86905582016-02-09 21:36:09 -08006959 if (statusColorWin == opaque) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01006960 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6961 // its light flag.
6962 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6963 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6964 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6965 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6966 // Otherwise if it's dimming, clear the light flag.
6967 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6968 }
6969 }
6970 return vis;
6971 }
6972
John Spurlock79da8332013-09-20 12:04:47 -04006973 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006974 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
6975 final boolean freeformStackVisible =
6976 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08006977 final boolean resizing = mWindowManagerInternal.isDockedDividerResizing();
6978
6979 // We need to force system bars when the docked stack is visible, when the freeform stack
6980 // is visible but also when we are resizing for the transitions when docked stack
6981 // visibility changes.
6982 final boolean forceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing;
Jorim Jaggi4fa78922015-11-30 17:13:56 -08006983 final boolean forceOpaqueSystemBars = forceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006984
John Spurlockbd957402013-10-03 11:38:39 -04006985 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006986 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6987 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006988 : mTopFullscreenOpaqueWindowState;
6989 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6990 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6991
John Spurlock27735a42013-08-14 17:57:38 -04006992 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006993 int type = win.getAttrs().type;
6994 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006995 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006996 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6997 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006998 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01006999 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
7000 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007001 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01007002 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
7003 }
John Spurlockbd957402013-10-03 11:38:39 -04007004 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007005 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04007006
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007007 if ((!areTranslucentBarsAllowed() && transWin != mStatusBar)
7008 || forceOpaqueSystemBars) {
Adrian Roosea562512014-05-05 13:33:03 +02007009 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
7010 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007011 }
7012
Jorim Jaggi4fa78922015-11-30 17:13:56 -08007013 if (mForceWindowDrawsStatusBarBackground) {
7014 vis |= View.STATUS_BAR_TRANSPARENT;
7015 vis &= ~View.STATUS_BAR_TRANSLUCENT;
7016 }
7017
John Spurlock27735a42013-08-14 17:57:38 -04007018 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04007019 boolean immersiveSticky =
7020 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007021 final boolean hideStatusBarWM =
7022 mTopFullscreenOpaqueWindowState != null
7023 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04007024 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007025 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04007026 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007027 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04007028 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007029
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007030 final boolean transientStatusBarAllowed = mStatusBar != null
7031 && (statusBarHasFocus || (!forceShowSystemBars
7032 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04007033
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007034 final boolean transientNavBarAllowed = mNavigationBar != null
7035 && !forceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04007036
Adrian Roosddc8b272015-05-21 16:28:27 -07007037 final long now = SystemClock.uptimeMillis();
7038 final boolean pendingPanic = mPendingPanicGestureUptime != 0
7039 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
7040 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
7041 // The user performed the panic gesture recently, we're about to hide the bars,
7042 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
7043 mPendingPanicGestureUptime = 0;
7044 mStatusBarController.showTransient();
7045 mNavigationBarController.showTransient();
7046 }
7047
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007048 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007049 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007050 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007051 && !transientNavBarAllowed;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007052 if (denyTransientStatus || denyTransientNav || forceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04007053 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04007054 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08007055 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007056 }
John Spurlock27735a42013-08-14 17:57:38 -04007057
Selim Cinekf98702e2015-05-20 22:48:40 -07007058 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
7059 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
7060 final boolean navAllowedHidden = immersive || immersiveSticky;
7061
Selim Cinekd6623612015-05-22 18:56:22 -07007062 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
7063 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07007064 // We can't hide the navbar from this window otherwise the input consumer would not get
7065 // the input events.
7066 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
7067 }
7068
John Spurlock27735a42013-08-14 17:57:38 -04007069 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
7070
7071 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04007072 boolean oldImmersiveMode = isImmersiveMode(oldVis);
7073 boolean newImmersiveMode = isImmersiveMode(vis);
7074 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04007075 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07007076 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
7077 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04007078 }
John Spurlock27735a42013-08-14 17:57:38 -04007079
John Spurlockf1a36642013-10-12 17:50:42 -04007080 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
7081
John Spurlocke1f366f2013-08-05 12:22:40 -04007082 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007083 }
7084
John Spurlockf1a36642013-10-12 17:50:42 -04007085 private void clearClearableFlagsLw() {
7086 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
7087 if (newVal != mResettingSystemUiFlags) {
7088 mResettingSystemUiFlags = newVal;
7089 mWindowManagerFuncs.reevaluateStatusBarVisibility();
7090 }
7091 }
7092
7093 private boolean isImmersiveMode(int vis) {
7094 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04007095 return mNavigationBar != null
7096 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04007097 && (vis & flags) != 0
7098 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04007099 }
7100
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007101 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007102 * @return whether the navigation or status bar can be made translucent
7103 *
7104 * This should return true unless touch exploration is not enabled or
7105 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007106 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007107 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04007108 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007109 }
7110
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007111 // Use this instead of checking config_showNavigationBar so that it can be consistently
7112 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07007113 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007114 public boolean hasNavigationBar() {
7115 return mHasNavigationBar;
7116 }
7117
satok1bc0a492012-04-25 22:47:12 +09007118 @Override
7119 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
7120 mLastInputMethodWindow = ime;
7121 mLastInputMethodTargetWindow = target;
7122 }
7123
Craig Mautnerf1b67412012-09-19 13:18:29 -07007124 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09007125 public int getInputMethodWindowVisibleHeightLw() {
7126 return mDockBottom - mCurBottom;
7127 }
7128
7129 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07007130 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07007131 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08007132 if (mKeyguardDelegate != null) {
7133 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007134 }
John Spurlock13451a22012-09-28 14:40:41 -04007135 if (mStatusBarService != null) {
7136 try {
7137 mStatusBarService.setCurrentUser(newUserId);
7138 } catch (RemoteException e) {
7139 // oh well
7140 }
7141 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007142 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007143 }
7144
7145 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08007146 public boolean canMagnifyWindow(int windowType) {
7147 switch (windowType) {
7148 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
7149 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
7150 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
7151 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
7152 return false;
7153 }
7154 }
7155 return true;
7156 }
7157
7158 @Override
7159 public boolean isTopLevelWindow(int windowType) {
7160 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
7161 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
7162 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
7163 }
7164 return true;
7165 }
7166
Jim Miller4eeb4f62012-11-08 00:04:29 -08007167 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07007168 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007169 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007170 pw.print(" mSystemReady="); pw.print(mSystemReady);
7171 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07007172 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007173 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07007174 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007175 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07007176 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
7177 || mForceClearedSystemUiFlags != 0) {
7178 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
7179 pw.print(Integer.toHexString(mLastSystemUiFlags));
7180 pw.print(" mResettingSystemUiFlags=0x");
7181 pw.print(Integer.toHexString(mResettingSystemUiFlags));
7182 pw.print(" mForceClearedSystemUiFlags=0x");
7183 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07007184 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007185 if (mLastFocusNeedsMenu) {
7186 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
7187 pw.println(mLastFocusNeedsMenu);
7188 }
Jeff Browna20dda42014-05-27 20:57:24 -07007189 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
7190 pw.println(mWakeGestureEnabledSetting);
7191
Jeff Brownbcdfc622014-03-06 19:13:04 -08007192 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04007193 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
7194 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07007195 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007196 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
7197 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
7198 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
7199 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007200 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007201 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007202 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
7203 pw.print(mCarDockEnablesAccelerometer);
7204 pw.print(" mDeskDockEnablesAccelerometer=");
7205 pw.println(mDeskDockEnablesAccelerometer);
7206 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
7207 pw.print(mLidKeyboardAccessibility);
7208 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007209 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007210 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007211 pw.print(prefix);
7212 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
7213 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07007214 pw.print(prefix);
7215 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
7216 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007217 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07007218 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
7219 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
7220 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
7221 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
7222 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
7223 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
7224 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08007225 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
7226 pw.print(","); pw.print(mOverscanScreenTop);
7227 pw.print(") "); pw.print(mOverscanScreenWidth);
7228 pw.print("x"); pw.println(mOverscanScreenHeight);
7229 if (mOverscanLeft != 0 || mOverscanTop != 0
7230 || mOverscanRight != 0 || mOverscanBottom != 0) {
7231 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
7232 pw.print(" top="); pw.print(mOverscanTop);
7233 pw.print(" right="); pw.print(mOverscanRight);
7234 pw.print(" bottom="); pw.println(mOverscanBottom);
7235 }
Dianne Hackborn313440842013-02-19 19:22:59 -08007236 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
7237 pw.print(mRestrictedOverscanScreenLeft);
7238 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
7239 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
7240 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007241 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
7242 pw.print(","); pw.print(mUnrestrictedScreenTop);
7243 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
7244 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
7245 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
7246 pw.print(","); pw.print(mRestrictedScreenTop);
7247 pw.print(") "); pw.print(mRestrictedScreenWidth);
7248 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07007249 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
7250 pw.print(","); pw.print(mStableFullscreenTop);
7251 pw.print(")-("); pw.print(mStableFullscreenRight);
7252 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07007253 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
7254 pw.print(","); pw.print(mStableTop);
7255 pw.print(")-("); pw.print(mStableRight);
7256 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007257 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7258 pw.print(","); pw.print(mSystemTop);
7259 pw.print(")-("); pw.print(mSystemRight);
7260 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007261 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
7262 pw.print(","); pw.print(mCurTop);
7263 pw.print(")-("); pw.print(mCurRight);
7264 pw.print(","); pw.print(mCurBottom); pw.println(")");
7265 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
7266 pw.print(","); pw.print(mContentTop);
7267 pw.print(")-("); pw.print(mContentRight);
7268 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07007269 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
7270 pw.print(","); pw.print(mVoiceContentTop);
7271 pw.print(")-("); pw.print(mVoiceContentRight);
7272 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007273 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
7274 pw.print(","); pw.print(mDockTop);
7275 pw.print(")-("); pw.print(mDockRight);
7276 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007277 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
7278 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007279 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
7280 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07007281 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
7282 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007283 if (mLastInputMethodWindow != null) {
7284 pw.print(prefix); pw.print("mLastInputMethodWindow=");
7285 pw.println(mLastInputMethodWindow);
7286 }
7287 if (mLastInputMethodTargetWindow != null) {
7288 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
7289 pw.println(mLastInputMethodTargetWindow);
7290 }
7291 if (mStatusBar != null) {
7292 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08007293 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
7294 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007295 }
7296 if (mNavigationBar != null) {
7297 pw.print(prefix); pw.print("mNavigationBar=");
7298 pw.println(mNavigationBar);
7299 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007300 if (mFocusedWindow != null) {
7301 pw.print(prefix); pw.print("mFocusedWindow=");
7302 pw.println(mFocusedWindow);
7303 }
7304 if (mFocusedApp != null) {
7305 pw.print(prefix); pw.print("mFocusedApp=");
7306 pw.println(mFocusedApp);
7307 }
7308 if (mWinDismissingKeyguard != null) {
7309 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
7310 pw.println(mWinDismissingKeyguard);
7311 }
7312 if (mTopFullscreenOpaqueWindowState != null) {
7313 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7314 pw.println(mTopFullscreenOpaqueWindowState);
7315 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007316 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7317 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7318 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7319 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007320 if (mForcingShowNavBar) {
7321 pw.print(prefix); pw.print("mForcingShowNavBar=");
7322 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7323 pw.println(mForcingShowNavBarLayer);
7324 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007325 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007326 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007327 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7328 pw.print(" mForceStatusBarFromKeyguard=");
7329 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007330 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007331 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007332 pw.print(" mHomePressed="); pw.println(mHomePressed);
7333 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7334 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7335 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7336 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7337 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7338 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7339 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7340 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7341 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7342 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007343 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7344 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7345 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007346
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007347 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007348 mStatusBarController.dump(pw, prefix);
7349 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007350 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007351
Jeff Browna20dda42014-05-27 20:57:24 -07007352 if (mWakeGestureListener != null) {
7353 mWakeGestureListener.dump(pw, prefix);
7354 }
Jeff Brown600f0032014-05-22 17:06:00 -07007355 if (mOrientationListener != null) {
7356 mOrientationListener.dump(pw, prefix);
7357 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007358 if (mBurnInProtectionHelper != null) {
7359 mBurnInProtectionHelper.dump(prefix, pw);
7360 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007361 if (mKeyguardDelegate != null) {
7362 mKeyguardDelegate.dump(prefix, pw);
7363 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007364 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007365}