blob: 716b96fb4791ac3a1609d0f428f6904c1c482263 [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
Svet Ganov9cea80cd2016-02-16 11:47:00 -080036import android.Manifest;
Dianne Hackborna4972e92012-03-14 10:38:05 -070037import android.app.ActivityManager;
Jorim Jaggi86905582016-02-09 21:36:09 -080038import android.app.ActivityManager.StackId;
Jeff Brown061ea992015-04-17 19:55:47 -070039import android.app.ActivityManagerInternal;
40import android.app.ActivityManagerInternal.SleepToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080041import android.app.ActivityManagerNative;
Dianne Hackbornc2293022013-02-06 23:14:49 -080042import android.app.AppOpsManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040043import android.app.IUiModeManager;
Dianne Hackborn661cd522011-08-22 00:26:20 -070044import android.app.ProgressDialog;
Jeff Brownde7a8ea2012-06-13 18:28:57 -070045import android.app.SearchManager;
John Spurlock97642182013-07-29 17:58:39 -040046import android.app.StatusBarManager;
Dianne Hackborn78968392010-03-04 20:47:56 -080047import android.app.UiModeManager;
Dianne Hackborn39c2d712009-09-22 11:41:31 -070048import android.content.ActivityNotFoundException;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080049import android.content.BroadcastReceiver;
Daniel Sandler0601eb72011-04-13 01:01:32 -040050import android.content.ComponentName;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080051import android.content.ContentResolver;
52import android.content.Context;
53import android.content.Intent;
Mike Lockwood1753f7f2009-08-24 14:49:07 -070054import android.content.IntentFilter;
Winson Chung9112ec32011-06-27 13:15:32 -070055import android.content.ServiceConnection;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080056import android.content.pm.ActivityInfo;
57import android.content.pm.PackageManager;
Daniel Sandler6396c722013-04-16 20:19:09 -040058import android.content.pm.ResolveInfo;
Dianne Hackborn2f0b1752011-05-31 17:59:49 -070059import android.content.res.CompatibilityInfo;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080060import android.content.res.Configuration;
61import android.content.res.Resources;
62import android.database.ContentObserver;
Dianne Hackbornc777e072010-02-12 13:07:59 -080063import android.graphics.PixelFormat;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080064import android.graphics.Rect;
Jinsuk Kime601b712015-07-07 08:01:02 +090065import android.hardware.hdmi.HdmiControlManager;
66import android.hardware.hdmi.HdmiPlaybackClient;
67import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
John Spurlock7b414672014-07-18 13:02:39 -040068import android.media.AudioAttributes;
Michael Jurka7a348952012-02-27 13:07:58 -080069import android.media.AudioManager;
John Spurlock61560172015-02-06 19:46:04 -050070import android.media.AudioSystem;
Michael Jurka7a348952012-02-27 13:07:58 -080071import android.media.IAudioService;
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -070072import android.media.Ringtone;
73import android.media.RingtoneManager;
RoboErik8a2cfc32014-05-16 11:19:38 -070074import android.media.session.MediaSessionLegacyHelper;
Billy Laucbe540f2015-06-25 01:51:44 +010075import android.os.Binder;
Dianne Hackborn38e29a62011-09-18 14:43:08 -070076import android.os.Bundle;
Craig Mautner276a6eb2014-11-04 15:32:57 -080077import android.os.Debug;
Jeff Brown9a538ee2012-08-20 14:56:57 -070078import android.os.FactoryTest;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080079import android.os.Handler;
80import android.os.IBinder;
Dianne Hackbornb6683c42015-06-18 17:40:33 -070081import android.os.IDeviceIdleController;
Jeff Brown32cbc38552011-12-01 14:01:49 -080082import android.os.Looper;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -070083import android.os.Message;
84import android.os.Messenger;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080085import android.os.PowerManager;
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -070086import android.os.PowerManagerInternal;
Billy Laucbe540f2015-06-25 01:51:44 +010087import android.os.Process;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080088import android.os.RemoteException;
89import android.os.ServiceManager;
90import android.os.SystemClock;
91import android.os.SystemProperties;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -080092import android.os.UEventObserver;
Dianne Hackbornf02b60a2012-08-16 10:48:27 -070093import android.os.UserHandle;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080094import android.os.Vibrator;
Michael Wright3818c922014-09-02 13:59:07 -070095import android.provider.MediaStore;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -080096import android.provider.Settings;
Jose Lima9546b202014-07-02 17:21:51 -070097import android.service.dreams.DreamManagerInternal;
John Spurlockc8b46ca2013-04-08 12:59:26 -040098import android.service.dreams.DreamService;
99import android.service.dreams.IDreamManager;
Michael Wrightdc63f7b2014-08-21 19:05:21 -0700100import android.speech.RecognizerIntent;
Tyler Gunnef9f6f92014-09-12 22:16:17 -0700101import android.telecom.TelecomManager;
Dianne Hackborn81e56d52011-05-26 00:55:58 -0700102import android.util.DisplayMetrics;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800103import android.util.EventLog;
104import android.util.Log;
Jeff Browna41ca772010-08-11 14:46:32 -0700105import android.util.Slog;
Jeff Brown6651a632011-11-28 12:59:11 -0800106import android.util.SparseArray;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700107import android.view.Display;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800108import android.view.Gravity;
109import android.view.HapticFeedbackConstants;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800110import android.view.IApplicationToken;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800111import android.view.IWindowManager;
Jeff Browna41ca772010-08-11 14:46:32 -0700112import android.view.InputChannel;
Jeff Brown4d396052010-10-29 21:50:21 -0700113import android.view.InputDevice;
Jeff Brown4952dfd2011-11-30 19:23:22 -0800114import android.view.InputEvent;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800115import android.view.InputEventReceiver;
Jeff Brown6b53e8d2010-11-10 16:03:06 -0800116import android.view.KeyCharacterMap;
Craig Mautnerae446592012-12-06 19:05:05 -0800117import android.view.KeyCharacterMap.FallbackAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800118import android.view.KeyEvent;
119import android.view.MotionEvent;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800120import android.view.Surface;
121import android.view.View;
122import android.view.ViewConfiguration;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800123import android.view.WindowManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800124import android.view.WindowManagerGlobal;
Craig Mautner8a0da012014-05-31 15:13:37 -0700125import android.view.WindowManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800126import android.view.WindowManagerPolicy;
Craig Mautnerae446592012-12-06 19:05:05 -0800127import android.view.accessibility.AccessibilityEvent;
Svetoslav8e3feb12014-02-24 13:46:47 -0800128import android.view.accessibility.AccessibilityManager;
Craig Mautnerae446592012-12-06 19:05:05 -0800129import android.view.animation.Animation;
Jorim Jaggi76a16232014-08-08 17:00:47 +0200130import android.view.animation.AnimationSet;
Craig Mautnerae446592012-12-06 19:05:05 -0800131import android.view.animation.AnimationUtils;
Craig Mautnerae446592012-12-06 19:05:05 -0800132import com.android.internal.R;
Jason Monk8f7f3182015-11-18 16:35:14 -0500133import com.android.internal.logging.MetricsLogger;
134import com.android.internal.policy.PhoneWindow;
Craig Mautnerae446592012-12-06 19:05:05 -0800135import com.android.internal.statusbar.IStatusBarService;
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700136import com.android.internal.util.ScreenShapeHelper;
Craig Mautnerae446592012-12-06 19:05:05 -0800137import com.android.internal.widget.PointerLocationView;
Adrian Roos5941c982015-09-03 15:59:49 -0700138import com.android.server.GestureLauncherService;
Craig Mautner8a0da012014-05-31 15:13:37 -0700139import com.android.server.LocalServices;
Jorim Jaggib10e33f2015-02-04 21:57:40 +0100140import com.android.server.policy.keyguard.KeyguardServiceDelegate;
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700141import com.android.server.policy.keyguard.KeyguardServiceDelegate.DrawnListener;
Jorim Jaggi86905582016-02-09 21:36:09 -0800142import com.android.server.statusbar.StatusBarManagerInternal;
Craig Mautnerae446592012-12-06 19:05:05 -0800143
144import java.io.File;
145import java.io.FileReader;
146import java.io.IOException;
147import java.io.PrintWriter;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700148import java.util.HashSet;
Craig Mautner276a6eb2014-11-04 15:32:57 -0800149import java.util.List;
Craig Mautnerae446592012-12-06 19:05:05 -0800150
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800151/**
The Android Open Source Project0727d222009-03-11 12:11:58 -0700152 * WindowManagerPolicy implementation for the Android phone UI. This
153 * introduces a new method suffix, Lp, for an internal lock of the
154 * PhoneWindowManager. This is used to protect some internal state, and
John Spurlock04db1762013-05-13 12:46:41 -0400155 * 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 -0700156 * of both of those when held.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800157 */
158public class PhoneWindowManager implements WindowManagerPolicy {
159 static final String TAG = "WindowManager";
160 static final boolean DEBUG = false;
Joe Onorato43a17652011-04-06 19:22:23 -0700161 static final boolean localLOGV = false;
Jeff Brown40013652012-05-16 21:22:36 -0700162 static final boolean DEBUG_INPUT = false;
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -0700163 static final boolean DEBUG_KEYGUARD = false;
164 static final boolean DEBUG_LAYOUT = false;
Craig Mautner6fbda632012-07-03 09:26:39 -0700165 static final boolean DEBUG_STARTING_WINDOW = false;
Craig Mautner8a0da012014-05-31 15:13:37 -0700166 static final boolean DEBUG_WAKEUP = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800167 static final boolean SHOW_STARTING_ANIMATIONS = true;
168 static final boolean SHOW_PROCESSES_ON_ALT_MENU = false;
Joe Onoratod208e702010-10-08 16:22:43 -0400169
Daniel Sandler6396c722013-04-16 20:19:09 -0400170 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
keunyounga7710492015-09-23 11:33:58 -0700171 // No longer recommended for desk docks;
Daniel Sandler6396c722013-04-16 20:19:09 -0400172 static final boolean ENABLE_DESK_DOCK_HOME_CAPTURE = false;
173
Jeff Brown6d8fd272014-05-20 21:24:38 -0700174 static final int SHORT_PRESS_POWER_NOTHING = 0;
175 static final int SHORT_PRESS_POWER_GO_TO_SLEEP = 1;
176 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP = 2;
177 static final int SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME = 3;
Bryce Lee01b0c5f2015-02-05 18:24:04 -0800178 static final int SHORT_PRESS_POWER_GO_HOME = 4;
Jeff Brown6d8fd272014-05-20 21:24:38 -0700179
Joe Onoratod208e702010-10-08 16:22:43 -0400180 static final int LONG_PRESS_POWER_NOTHING = 0;
181 static final int LONG_PRESS_POWER_GLOBAL_ACTIONS = 1;
182 static final int LONG_PRESS_POWER_SHUT_OFF = 2;
Jeff Brown9a538ee2012-08-20 14:56:57 -0700183 static final int LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM = 3;
Michael Jurka3b1fc472011-06-13 10:54:40 -0700184
Jeff Brown13f00f02014-10-31 14:45:50 -0700185 static final int MULTI_PRESS_POWER_NOTHING = 0;
186 static final int MULTI_PRESS_POWER_THEATER_MODE = 1;
187 static final int MULTI_PRESS_POWER_BRIGHTNESS_BOOST = 2;
188
Michael Jurka3b1fc472011-06-13 10:54:40 -0700189 // These need to match the documentation/constant in
190 // core/res/res/values/config.xml
Joe Onorato46b0d682010-11-22 17:37:27 -0800191 static final int LONG_PRESS_HOME_NOTHING = 0;
Michael Wrightc9ebea72013-01-16 19:25:02 -0800192 static final int LONG_PRESS_HOME_RECENT_SYSTEM_UI = 1;
Jeff Browncaca8812013-05-09 13:34:33 -0700193 static final int LONG_PRESS_HOME_ASSIST = 2;
Jaewan Kim76b7d0d2016-02-12 19:01:02 +0900194 static final int LAST_LONG_PRESS_HOME_BEHAVIOR = LONG_PRESS_HOME_ASSIST;
Jeff Browncaca8812013-05-09 13:34:33 -0700195
196 static final int DOUBLE_TAP_HOME_NOTHING = 0;
197 static final int DOUBLE_TAP_HOME_RECENT_SYSTEM_UI = 1;
Joe Onorato46b0d682010-11-22 17:37:27 -0800198
Jaewan Kim49117872016-01-19 17:24:08 +0900199 static final int SHORT_PRESS_WINDOW_NOTHING = 0;
200 static final int SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE = 1;
201
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000202 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP = 0;
203 static final int SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME = 1;
204
Dianne Hackborn5cb8d792009-05-21 17:34:15 -0700205 static final int APPLICATION_MEDIA_SUBLAYER = -2;
206 static final int APPLICATION_MEDIA_OVERLAY_SUBLAYER = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800207 static final int APPLICATION_PANEL_SUBLAYER = 1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800208 static final int APPLICATION_SUB_PANEL_SUBLAYER = 2;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -0700209 static final int APPLICATION_ABOVE_SUB_PANEL_SUBLAYER = 3;
Craig Mautner88400d32012-09-30 12:35:45 -0700210
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800211 static public final String SYSTEM_DIALOG_REASON_KEY = "reason";
212 static public final String SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS = "globalactions";
213 static public final String SYSTEM_DIALOG_REASON_RECENT_APPS = "recentapps";
Joe Onoratof275f0c2009-11-24 16:11:13 -0500214 static public final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey";
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700215 static public final String SYSTEM_DIALOG_REASON_ASSIST = "assist";
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800216
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700217 /**
218 * These are the system UI flags that, when changing, can cause the layout
219 * of the screen to change.
220 */
221 static final int SYSTEM_UI_CHANGING_LAYOUT =
John Spurlocke1f366f2013-08-05 12:22:40 -0400222 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlock7f4820a2013-10-08 12:54:35 -0400223 | View.SYSTEM_UI_FLAG_FULLSCREEN
224 | View.STATUS_BAR_TRANSLUCENT
Adrian Roosea562512014-05-05 13:33:03 +0200225 | View.NAVIGATION_BAR_TRANSLUCENT
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800226 | View.STATUS_BAR_TRANSPARENT
227 | View.NAVIGATION_BAR_TRANSPARENT;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700228
John Spurlock7b414672014-07-18 13:02:39 -0400229 private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder()
230 .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
231 .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
232 .build();
233
Adrian Roosddc8b272015-05-21 16:28:27 -0700234 // The panic gesture may become active only after the keyguard is dismissed and the immersive
235 // app shows again. If that doesn't happen for 30s we drop the gesture.
236 private static final long PANIC_GESTURE_EXPIRATION = 30000;
237
Jim Miller5ecd8112013-01-09 18:50:26 -0800238 /**
239 * Keyguard stuff
240 */
241 private WindowState mKeyguardScrim;
Jorim Jaggi380ecb82014-03-14 17:25:20 +0100242 private boolean mKeyguardHidden;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700243 private boolean mKeyguardDrawnOnce;
Jim Miller5ecd8112013-01-09 18:50:26 -0800244
Jeff Brown6651a632011-11-28 12:59:11 -0800245 /* Table of Application Launch keys. Maps from key codes to intent categories.
246 *
247 * These are special keys that are used to launch particular kinds of applications,
248 * such as a web browser. HID defines nearly a hundred of them in the Consumer (0x0C)
249 * usage page. We don't support quite that many yet...
250 */
251 static SparseArray<String> sApplicationLaunchKeyCategories;
252 static {
253 sApplicationLaunchKeyCategories = new SparseArray<String>();
254 sApplicationLaunchKeyCategories.append(
255 KeyEvent.KEYCODE_EXPLORER, Intent.CATEGORY_APP_BROWSER);
256 sApplicationLaunchKeyCategories.append(
257 KeyEvent.KEYCODE_ENVELOPE, Intent.CATEGORY_APP_EMAIL);
258 sApplicationLaunchKeyCategories.append(
259 KeyEvent.KEYCODE_CONTACTS, Intent.CATEGORY_APP_CONTACTS);
260 sApplicationLaunchKeyCategories.append(
261 KeyEvent.KEYCODE_CALENDAR, Intent.CATEGORY_APP_CALENDAR);
262 sApplicationLaunchKeyCategories.append(
263 KeyEvent.KEYCODE_MUSIC, Intent.CATEGORY_APP_MUSIC);
264 sApplicationLaunchKeyCategories.append(
265 KeyEvent.KEYCODE_CALCULATOR, Intent.CATEGORY_APP_CALCULATOR);
266 }
267
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700268 /** Amount of time (in milliseconds) to wait for windows drawn before powering on. */
Jorim Jaggi0d210f62015-07-10 14:24:44 -0700269 static final int WAITING_FOR_DRAWN_TIMEOUT = 1000;
Craig Mautnerc3daedd2014-09-13 11:17:23 -0700270
Dianne Hackborndf89e652011-10-06 22:35:11 -0700271 /**
272 * Lock protecting internal state. Must not call out into window
273 * manager with lock held. (This lock will be acquired in places
274 * where the window manager is calling in with its own lock held.)
275 */
Craig Mautner0bf6ec92012-12-18 08:33:27 -0800276 private final Object mLock = new Object();
Dianne Hackborndf89e652011-10-06 22:35:11 -0700277
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800278 Context mContext;
279 IWindowManager mWindowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700280 WindowManagerFuncs mWindowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -0700281 WindowManagerInternal mWindowManagerInternal;
Jeff Brown96307042012-07-27 15:51:34 -0700282 PowerManager mPowerManager;
Jeff Brown061ea992015-04-17 19:55:47 -0700283 ActivityManagerInternal mActivityManagerInternal;
Jose Lima9546b202014-07-02 17:21:51 -0700284 DreamManagerInternal mDreamManagerInternal;
Michael Wrighta4d22d72015-09-16 23:19:26 +0100285 PowerManagerInternal mPowerManagerInternal;
Joe Onorato93056472010-09-10 10:30:46 -0400286 IStatusBarService mStatusBarService;
Jorim Jaggi86905582016-02-09 21:36:09 -0800287 StatusBarManagerInternal mStatusBarManagerInternal;
Jeff Browncaca8812013-05-09 13:34:33 -0700288 boolean mPreloadedRecentApps;
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700289 final Object mServiceAquireLock = new Object();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800290 Vibrator mVibrator; // Vibrator for giving feedback of orientation changes
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700291 SearchManager mSearchManager;
Svetoslav8e3feb12014-02-24 13:46:47 -0800292 AccessibilityManager mAccessibilityManager;
Filip Gruszczynskicfb31852015-02-25 21:47:12 +0000293 BurnInProtectionHelper mBurnInProtectionHelper;
Billy Laucbe540f2015-06-25 01:51:44 +0100294 AppOpsManager mAppOpsManager;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800295
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700296 // Vibrator pattern for haptic feedback of a long press.
297 long[] mLongPressVibePattern;
Craig Mautner88400d32012-09-30 12:35:45 -0700298
Dianne Hackborn181ceb52009-08-27 22:16:40 -0700299 // Vibrator pattern for haptic feedback of virtual key press.
300 long[] mVirtualKeyVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700301
Amith Yamasanic33cb712010-02-10 15:21:49 -0800302 // Vibrator pattern for a short vibration.
303 long[] mKeyboardTapVibePattern;
304
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -0700305 // Vibrator pattern for a short vibration when tapping on an hour/minute tick of a Clock.
306 long[] mClockTickVibePattern;
307
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -0700308 // Vibrator pattern for a short vibration when tapping on a day/month/year date of a Calendar.
309 long[] mCalendarDateVibePattern;
310
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700311 // Vibrator pattern for haptic feedback during boot when safe mode is disabled.
312 long[] mSafeModeDisabledVibePattern;
Craig Mautner967212c2013-04-13 21:10:58 -0700313
Dianne Hackbornb1a79802009-09-29 15:18:31 -0700314 // Vibrator pattern for haptic feedback during boot when safe mode is enabled.
315 long[] mSafeModeEnabledVibePattern;
Romain Guy8154cd32010-03-29 14:41:15 -0700316
Mady Mellore8608912015-06-05 09:02:55 -0700317 // Vibrator pattern for haptic feedback of a context click.
318 long[] mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -0700319
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800320 /** If true, hitting shift & menu will broadcast Intent.ACTION_BUG_REPORT */
321 boolean mEnableShiftMenuBugReports = false;
Mike Lockwoodd747dc82011-09-13 16:28:22 -0400322
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800323 boolean mSafeMode;
324 WindowState mStatusBar = null;
Dianne Hackborn69cb8752011-05-19 18:13:32 -0700325 int mStatusBarHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400326 WindowState mNavigationBar = null;
Daniel Sandler36412a72011-08-04 09:35:13 -0400327 boolean mHasNavigationBar = false;
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700328 boolean mCanHideNavigationBar = false;
Daniel Sandler4a066c52012-04-20 14:49:13 -0400329 boolean mNavigationBarCanMove = false; // can the navigation bar ever move to the side?
330 boolean mNavigationBarOnBottom = true; // is the navigation bar on the bottom *right now*?
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -0800331 int[] mNavigationBarHeightForRotationDefault = new int[4];
332 int[] mNavigationBarWidthForRotationDefault = new int[4];
333 int[] mNavigationBarHeightForRotationInCarMode = new int[4];
334 int[] mNavigationBarWidthForRotationInCarMode = new int[4];
Daniel Sandler8956dbb2011-04-22 07:55:02 -0400335
keunyounga7710492015-09-23 11:33:58 -0700336 // Whether to allow dock apps with METADATA_DOCK_HOME to temporarily take over the Home key.
337 // This is for car dock and this is updated from resource.
338 private boolean mEnableCarDockHomeCapture = true;
339
Craig Mautnera631d492014-08-05 15:16:01 -0700340 boolean mBootMessageNeedsHiding;
Jim Miller5ecd8112013-01-09 18:50:26 -0800341 KeyguardServiceDelegate mKeyguardDelegate;
Craig Mautner13f6ea72014-06-23 14:57:02 -0700342 final Runnable mWindowManagerDrawCallback = new Runnable() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700343 @Override
Craig Mautner13f6ea72014-06-23 14:57:02 -0700344 public void run() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700345 if (DEBUG_WAKEUP) Slog.i(TAG, "All windows ready for display!");
346 mHandler.sendEmptyMessage(MSG_WINDOW_MANAGER_DRAWN_COMPLETE);
347 }
348 };
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700349 final DrawnListener mKeyguardDrawnCallback = new DrawnListener() {
Craig Mautner8a0da012014-05-31 15:13:37 -0700350 @Override
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -0700351 public void onDrawn() {
352 if (DEBUG_WAKEUP) Slog.d(TAG, "mKeyguardDelegate.ShowListener.onDrawn.");
Craig Mautner8a0da012014-05-31 15:13:37 -0700353 mHandler.sendEmptyMessage(MSG_KEYGUARD_DRAWN_COMPLETE);
354 }
355 };
356
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800357 GlobalActions mGlobalActions;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800358 Handler mHandler;
satok1bc0a492012-04-25 22:47:12 +0900359 WindowState mLastInputMethodWindow = null;
360 WindowState mLastInputMethodTargetWindow = null;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800361
Jeff Brown13f00f02014-10-31 14:45:50 -0700362 // FIXME This state is shared between the input reader and handler thread.
363 // Technically it's broken and buggy but it has been like this for many years
364 // and we have not yet seen any problems. Someday we'll rewrite this logic
365 // so that only one thread is involved in handling input policy. Unfortunately
366 // it's on a critical path for power management so we can't just post the work to the
367 // handler thread. We'll need to resolve this someday by teaching the input dispatcher
368 // to hold wakelocks during dispatch and eliminating the critical path.
369 volatile boolean mPowerKeyHandled;
Bryce Leed9268e32014-11-17 17:40:59 -0800370 volatile boolean mBeganFromNonInteractive;
Jeff Brown13f00f02014-10-31 14:45:50 -0700371 volatile int mPowerKeyPressCounter;
372 volatile boolean mEndCallKeyHandled;
373
Winson Chungd42a6cf2014-06-03 16:24:04 -0700374 boolean mRecentsVisible;
Winson Chung1e8d71b2014-05-16 17:05:22 -0700375 int mRecentAppsHeldModifiers;
Jeff Browncf39bdf2012-05-18 14:41:19 -0700376 boolean mLanguageSwitchKeyPressed;
Jeff Brown68b909d2011-12-07 16:36:01 -0800377
Jeff Brown2e7760e2012-04-11 15:14:55 -0700378 int mLidState = LID_ABSENT;
Michael Wright3818c922014-09-02 13:59:07 -0700379 int mCameraLensCoverState = CAMERA_LENS_COVER_ABSENT;
Jeff Browndaa37532012-05-01 15:54:03 -0700380 boolean mHaveBuiltInKeyboard;
Jeff Brown4aed78b2011-01-14 17:36:55 -0800381
Dianne Hackbornc777e072010-02-12 13:07:59 -0800382 boolean mSystemReady;
Dianne Hackbornba24e4d2011-09-01 11:17:06 -0700383 boolean mSystemBooted;
Adrian Roos3542f7d2015-07-13 15:57:53 -0700384 private boolean mDeferBindKeyguard;
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800385 boolean mHdmiPlugged;
Jinsuk Kime601b712015-07-07 08:01:02 +0900386 HdmiControl mHdmiControl;
Jeff Brown4f5fa282014-06-12 19:19:15 -0700387 IUiModeManager mUiModeManager;
Daniel Sandler6396c722013-04-16 20:19:09 -0400388 int mUiMode;
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700389 int mDockMode = Intent.EXTRA_DOCK_STATE_UNDOCKED;
Mike Lockwood1753f7f2009-08-24 14:49:07 -0700390 int mLidOpenRotation;
Mike Lockwood2d1efbd2009-09-16 12:15:53 -0400391 int mCarDockRotation;
392 int mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -0700393 int mUndockedHdmiRotation;
394 int mDemoHdmiRotation;
395 boolean mDemoHdmiRotationLock;
Chong Zhangae6119ff2014-11-11 18:54:39 -0800396 int mDemoRotation;
397 boolean mDemoRotationLock;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400398
Jeff Browna20dda42014-05-27 20:57:24 -0700399 boolean mWakeGestureEnabledSetting;
400 MyWakeGestureListener mWakeGestureListener;
401
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700402 // Default display does not rotate, apps that require non-default orientation will have to
403 // have the orientation emulated.
404 private boolean mForceDefaultOrientation = false;
405
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400406 int mUserRotationMode = WindowManagerPolicy.USER_ROTATION_FREE;
407 int mUserRotation = Surface.ROTATION_0;
Jeff Brown207673cd2012-06-05 17:47:11 -0700408 boolean mAccelerometerDefault;
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400409
Jeff Brownbcdfc622014-03-06 19:13:04 -0800410 boolean mSupportAutoRotation;
Jeff Brownd3187e32011-09-21 19:26:44 -0700411 int mAllowAllRotations = -1;
Mike Lockwoode9867d22009-09-20 01:59:02 -0400412 boolean mCarDockEnablesAccelerometer;
413 boolean mDeskDockEnablesAccelerometer;
Dianne Hackborn2862fff2009-09-15 22:56:29 -0700414 int mLidKeyboardAccessibility;
415 int mLidNavigationAccessibility;
Edward Savage-Jones7def60d2015-11-13 13:27:03 +0100416 boolean mLidControlsScreenLock;
Jeff Brownc458ce92012-04-30 14:58:40 -0700417 boolean mLidControlsSleep;
Jeff Brown13f00f02014-10-31 14:45:50 -0700418 int mShortPressOnPowerBehavior;
419 int mLongPressOnPowerBehavior;
420 int mDoublePressOnPowerBehavior;
421 int mTriplePressOnPowerBehavior;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +0000422 int mShortPressOnSleepBehavior;
Jaewan Kim49117872016-01-19 17:24:08 +0900423 int mShortPressWindowBehavior;
Jeff Brown3ee549c2014-09-22 20:14:39 -0700424 boolean mAwake;
425 boolean mScreenOnEarly;
426 boolean mScreenOnFully;
427 ScreenOnListener mScreenOnListener;
428 boolean mKeyguardDrawComplete;
429 boolean mWindowManagerDrawComplete;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800430 boolean mOrientationSensorEnabled = false;
431 int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800432 boolean mHasSoftInput = false;
Daniel Sandlerdd73ee42013-10-11 22:19:59 -0400433 boolean mTranslucentDecorEnabled = true;
RoboErik001c59c2015-01-26 15:53:51 -0800434 boolean mUseTvRouting;
Craig Mautner967212c2013-04-13 21:10:58 -0700435
Jeff Brown70825162012-03-28 17:27:48 -0700436 int mPointerLocationMode = 0; // guarded by mLock
Joe Onorato664644d2011-01-23 17:53:23 -0800437
438 // The last window we were told about in focusChanged.
439 WindowState mFocusedWindow;
Dianne Hackborne0f085d2011-11-30 18:41:15 -0800440 IApplicationToken mFocusedApp;
Joe Onorato664644d2011-01-23 17:53:23 -0800441
Jeff Brown70825162012-03-28 17:27:48 -0700442 PointerLocationView mPointerLocationView;
Jeff Brown32cbc38552011-12-01 14:01:49 -0800443
Dianne Hackbornc652de82013-02-15 16:32:56 -0800444 // The current size of the screen; really; extends into the overscan area of
445 // the screen and doesn't account for any system elements like the status bar.
446 int mOverscanScreenLeft, mOverscanScreenTop;
447 int mOverscanScreenWidth, mOverscanScreenHeight;
448 // The current visible size of the screen; really; (ir)regardless of whether the status
449 // bar can be hidden but not extending into the overscan area.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800450 int mUnrestrictedScreenLeft, mUnrestrictedScreenTop;
451 int mUnrestrictedScreenWidth, mUnrestrictedScreenHeight;
Dianne Hackborn313440842013-02-19 19:22:59 -0800452 // Like mOverscanScreen*, but allowed to move into the overscan region where appropriate.
453 int mRestrictedOverscanScreenLeft, mRestrictedOverscanScreenTop;
454 int mRestrictedOverscanScreenWidth, mRestrictedOverscanScreenHeight;
Dianne Hackborn82de1ae2010-10-28 11:28:39 -0700455 // The current size of the screen; these may be different than (0,0)-(dw,dh)
456 // if the status bar can't be hidden; in that case it effectively carves out
457 // that area of the display from all other windows.
Joe Onorato29fc2c92010-11-24 10:26:50 -0800458 int mRestrictedScreenLeft, mRestrictedScreenTop;
459 int mRestrictedScreenWidth, mRestrictedScreenHeight;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700460 // During layout, the current screen borders accounting for any currently
461 // visible system UI elements.
462 int mSystemLeft, mSystemTop, mSystemRight, mSystemBottom;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -0700463 // For applications requesting stable content insets, these are them.
464 int mStableLeft, mStableTop, mStableRight, mStableBottom;
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -0700465 // For applications requesting stable content insets but have also set the
466 // fullscreen window flag, these are the stable dimensions without the status bar.
467 int mStableFullscreenLeft, mStableFullscreenTop;
468 int mStableFullscreenRight, mStableFullscreenBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800469 // During layout, the current screen borders with all outer decoration
470 // (status bar, input method dock) accounted for.
471 int mCurLeft, mCurTop, mCurRight, mCurBottom;
472 // During layout, the frame in which content should be displayed
473 // to the user, accounting for all screen decoration except for any
474 // space they deem as available for other content. This is usually
475 // the same as mCur*, but may be larger if the screen decor has supplied
476 // content insets.
477 int mContentLeft, mContentTop, mContentRight, mContentBottom;
Dianne Hackborne30e02f2014-05-27 18:24:45 -0700478 // During layout, the frame in which voice content should be displayed
479 // to the user, accounting for all screen decoration except for any
480 // space they deem as available for other content.
481 int mVoiceContentLeft, mVoiceContentTop, mVoiceContentRight, mVoiceContentBottom;
Dianne Hackborn8e11ef02010-11-18 19:47:42 -0800482 // During layout, the current screen borders along which input method
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800483 // windows are placed.
484 int mDockLeft, mDockTop, mDockRight, mDockBottom;
485 // During layout, the layer at which the doc window is placed.
486 int mDockLayer;
Dianne Hackborn5c58de32012-04-28 19:52:37 -0700487 // During layout, this is the layer of the status bar.
488 int mStatusBarLayer;
Dianne Hackborne26ab702011-10-16 13:21:33 -0700489 int mLastSystemUiFlags;
490 // Bits that we are in the process of clearing, so we want to prevent
491 // them from being set by applications until everything has been updated
492 // to have them clear.
493 int mResettingSystemUiFlags = 0;
494 // Bits that we are currently always keeping cleared.
495 int mForceClearedSystemUiFlags = 0;
Jorim Jaggi86905582016-02-09 21:36:09 -0800496 int mLastFullscreenStackSysUiFlags;
497 int mLastDockedStackSysUiFlags;
498 final Rect mNonDockedStackBounds = new Rect();
499 final Rect mDockedStackBounds = new Rect();
500 final Rect mLastNonDockedStackBounds = new Rect();
501 final Rect mLastDockedStackBounds = new Rect();
502
Dianne Hackborn4eff8d32011-11-10 19:38:40 -0800503 // What we last reported to system UI about whether the compatibility
504 // menu needs to be displayed.
505 boolean mLastFocusNeedsMenu = false;
Adrian Roosddc8b272015-05-21 16:28:27 -0700506 // If nonzero, a panic gesture was performed at that time in uptime millis and is still pending.
507 private long mPendingPanicGestureUptime;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700508
Selim Cinekf83e8242015-05-19 18:08:14 -0700509 InputConsumer mInputConsumer = null;
Dianne Hackborndf89e652011-10-06 22:35:11 -0700510
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800511 static final Rect mTmpParentFrame = new Rect();
512 static final Rect mTmpDisplayFrame = new Rect();
Dianne Hackbornc4aad012013-02-22 15:05:25 -0800513 static final Rect mTmpOverscanFrame = new Rect();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800514 static final Rect mTmpContentFrame = new Rect();
515 static final Rect mTmpVisibleFrame = new Rect();
John Spurlock46646232013-09-30 22:32:42 -0400516 static final Rect mTmpDecorFrame = new Rect();
Adrian Roosfa104232014-06-20 16:10:14 -0700517 static final Rect mTmpStableFrame = new Rect();
Dianne Hackborn1f903c32011-09-13 19:18:06 -0700518 static final Rect mTmpNavigationFrame = new Rect();
Filip Gruszczynski2217f612015-05-26 11:32:08 -0700519 static final Rect mTmpOutsetFrame = new Rect();
Craig Mautner967212c2013-04-13 21:10:58 -0700520
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800521 WindowState mTopFullscreenOpaqueWindowState;
Adrian Rooscd3884d2015-02-18 17:25:23 +0100522 WindowState mTopFullscreenOpaqueOrDimmingWindowState;
Jorim Jaggi86905582016-02-09 21:36:09 -0800523 WindowState mTopDockedOpaqueWindowState;
524 WindowState mTopDockedOpaqueOrDimmingWindowState;
Craig Mautner2bc789b2014-03-19 19:48:38 -0700525 HashSet<IApplicationToken> mAppsToBeHidden = new HashSet<IApplicationToken>();
Jorim Jaggic13fcac2014-09-11 17:36:57 +0200526 HashSet<IApplicationToken> mAppsThatDismissKeyguard = new HashSet<IApplicationToken>();
Joe Onorato93056472010-09-10 10:30:46 -0400527 boolean mTopIsFullscreen;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800528 boolean mForceStatusBar;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -0700529 boolean mForceStatusBarFromKeyguard;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -0700530 private boolean mForceStatusBarTransparent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700531 boolean mHideLockScreen;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -0800532 boolean mForcingShowNavBar;
533 int mForcingShowNavBarLayer;
Craig Mautnerad09bcc2012-10-08 13:33:11 -0700534
535 // States of keyguard dismiss.
536 private static final int DISMISS_KEYGUARD_NONE = 0; // Keyguard not being dismissed.
537 private static final int DISMISS_KEYGUARD_START = 1; // Keyguard needs to be dismissed.
538 private static final int DISMISS_KEYGUARD_CONTINUE = 2; // Keyguard has been dismissed.
539 int mDismissKeyguard = DISMISS_KEYGUARD_NONE;
540
541 /** The window that is currently dismissing the keyguard. Dismissing the keyguard must only
542 * be done once per window. */
543 private WindowState mWinDismissingKeyguard;
544
tingna_sunge785ffa2015-05-12 13:23:15 +0800545 /** When window is currently dismissing the keyguard, dismissing the keyguard must handle
546 * the keygaurd secure state change instantly case, e.g. the use case of inserting a PIN
547 * lock SIM card. This variable is used to record the previous keyguard secure state for
548 * monitoring secure state change on window dismissing keyguard. */
549 private boolean mSecureDismissingKeyguard;
550
Craig Mautnerc9457fa2014-06-06 14:27:48 -0700551 /** The window that is currently showing "over" the keyguard. If there is an app window
552 * belonging to another app on top of this the keyguard shows. If there is a fullscreen
553 * app window under this, still dismiss the keyguard but don't show the app underneath. Show
554 * the wallpaper. */
555 private WindowState mWinShowWhenLocked;
556
Dianne Hackborn7ad44382012-10-18 17:46:00 -0700557 boolean mShowingLockscreen;
558 boolean mShowingDream;
559 boolean mDreamingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -0700560 boolean mDreamingSleepTokenNeeded;
561 SleepToken mDreamingSleepToken;
Jeff Brown48d1b142015-06-10 16:36:03 -0700562 SleepToken mScreenOffSleepToken;
Jim Millerab954542014-10-10 18:21:49 -0700563 boolean mKeyguardSecure;
564 boolean mKeyguardSecureIncludingHidden;
565 volatile boolean mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800566 boolean mHomePressed;
Jeff Browncaca8812013-05-09 13:34:33 -0700567 boolean mHomeConsumed;
568 boolean mHomeDoubleTapPending;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800569 Intent mHomeIntent;
Dianne Hackborn39c2d712009-09-22 11:41:31 -0700570 Intent mCarDockIntent;
571 Intent mDeskDockIntent;
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700572 boolean mSearchKeyShortcutPending;
573 boolean mConsumeSearchKeyUp;
Jeff Brownde7a8ea2012-06-13 18:28:57 -0700574 boolean mAssistKeyLongPressed;
Michael Wright6a62e552014-06-03 19:19:48 -0700575 boolean mPendingMetaAction;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800576
Mike Lockwood28569302010-01-28 11:54:40 -0500577 // support for activating the lock screen while the screen is on
578 boolean mAllowLockscreenWhenOn;
579 int mLockScreenTimeout;
580 boolean mLockScreenTimerActive;
581
David Brownbaf8d092010-03-08 21:52:59 -0800582 // Behavior of ENDCALL Button. (See Settings.System.END_BUTTON_BEHAVIOR.)
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800583 int mEndcallBehavior;
David Brownbaf8d092010-03-08 21:52:59 -0800584
585 // Behavior of POWER button while in-call and screen on.
586 // (See Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR.)
587 int mIncallPowerBehavior;
588
Dianne Hackbornf87d1962012-04-04 12:48:24 -0700589 Display mDisplay;
590
Filip Gruszczynski2987f612015-06-30 15:03:30 -0700591 private int mDisplayRotation;
592
Dianne Hackborn9d132642011-04-21 17:26:39 -0700593 int mLandscapeRotation = 0; // default landscape rotation
594 int mSeascapeRotation = 0; // "other" landscape rotation, 180 degrees from mLandscapeRotation
595 int mPortraitRotation = 0; // default portrait rotation
596 int mUpsideDownRotation = 0; // "other" portrait rotation
Mitsuru Oshima831d0d92009-06-16 18:27:18 -0700597
Dianne Hackbornc652de82013-02-15 16:32:56 -0800598 int mOverscanLeft = 0;
599 int mOverscanTop = 0;
600 int mOverscanRight = 0;
601 int mOverscanBottom = 0;
602
Joe Onorato46b0d682010-11-22 17:37:27 -0800603 // What we do when the user long presses on home
Jeff Browncaca8812013-05-09 13:34:33 -0700604 private int mLongPressOnHomeBehavior;
605
606 // What we do when the user double-taps on home
607 private int mDoubleTapOnHomeBehavior;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800608
Bryce Lee584a4452014-10-21 15:55:55 -0700609 // Allowed theater mode wake actions
610 private boolean mAllowTheaterModeWakeFromKey;
611 private boolean mAllowTheaterModeWakeFromPowerKey;
612 private boolean mAllowTheaterModeWakeFromMotion;
Bryce Lee812d7022014-11-10 13:33:28 -0800613 private boolean mAllowTheaterModeWakeFromMotionWhenNotDreaming;
Bryce Lee584a4452014-10-21 15:55:55 -0700614 private boolean mAllowTheaterModeWakeFromCameraLens;
615 private boolean mAllowTheaterModeWakeFromLidSwitch;
616 private boolean mAllowTheaterModeWakeFromWakeGesture;
617
Bryce Leed3b28402015-03-09 15:49:13 +0000618 // Whether to support long press from power button in non-interactive mode
619 private boolean mSupportLongPressPowerWhenNonInteractive;
620
Bryce Lee55e846d2014-11-04 12:43:44 -0800621 // Whether to go to sleep entering theater mode from power button
622 private boolean mGoToSleepOnButtonPressTheaterMode;
623
Winson Chung9112ec32011-06-27 13:15:32 -0700624 // Screenshot trigger states
Jeff Brownd5bb82d2011-10-12 13:57:59 -0700625 // Time to volume and power must be pressed within this interval of each other.
626 private static final long SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS = 150;
Winson Chung1cea2f32012-10-08 20:42:01 -0700627 // Increase the chord delay when taking a screenshot from the keyguard
628 private static final float KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER = 2.5f;
Christopher Tatee90585f2012-03-05 18:56:25 -0800629 private boolean mScreenshotChordEnabled;
Jeff Brown13f00f02014-10-31 14:45:50 -0700630 private boolean mScreenshotChordVolumeDownKeyTriggered;
631 private long mScreenshotChordVolumeDownKeyTime;
632 private boolean mScreenshotChordVolumeDownKeyConsumed;
633 private boolean mScreenshotChordVolumeUpKeyTriggered;
634 private boolean mScreenshotChordPowerKeyTriggered;
635 private long mScreenshotChordPowerKeyTime;
Winson Chung9112ec32011-06-27 13:15:32 -0700636
Michael Wrightb854e242013-02-05 17:54:02 -0800637 /* The number of steps between min and max brightness */
638 private static final int BRIGHTNESS_STEPS = 10;
639
Christopher Tate5e08af02012-09-21 17:17:22 -0700640 SettingsObserver mSettingsObserver;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800641 ShortcutManager mShortcutManager;
642 PowerManager.WakeLock mBroadcastWakeLock;
Jeff Brown13f00f02014-10-31 14:45:50 -0700643 PowerManager.WakeLock mPowerKeyWakeLock;
Jeff Brown40013652012-05-16 21:22:36 -0700644 boolean mHavePendingMediaKeyRepeatWithWakeLock;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800645
Craig Mautnerd625ab22013-09-06 13:40:31 -0700646 private int mCurrentUserId;
647
Justin Kohd378ad72013-04-01 12:18:26 -0700648 // Maps global key codes to the components that will handle them.
649 private GlobalKeyManager mGlobalKeyManager;
650
Jeff Brownfd23e3e2012-05-09 13:34:28 -0700651 // Fallback actions by key code.
652 private final SparseArray<KeyCharacterMap.FallbackAction> mFallbackActions =
653 new SparseArray<KeyCharacterMap.FallbackAction>();
Jeff Brown49ed71d2010-12-06 17:13:33 -0800654
Jorim Jaggi76a16232014-08-08 17:00:47 +0200655 private final LogDecelerateInterpolator mLogDecelerateInterpolator
656 = new LogDecelerateInterpolator(100, 0);
657
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800658 private boolean mForceWindowDrawsStatusBarBackground;
659
Jeff Brown70825162012-03-28 17:27:48 -0700660 private static final int MSG_ENABLE_POINTER_LOCATION = 1;
661 private static final int MSG_DISABLE_POINTER_LOCATION = 2;
Jeff Brown40013652012-05-16 21:22:36 -0700662 private static final int MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK = 3;
663 private static final int MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK = 4;
Craig Mautner8a0da012014-05-31 15:13:37 -0700664 private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5;
665 private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6;
666 private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7;
Craig Mautner84984fa2014-06-19 11:19:20 -0700667 private static final int MSG_DISPATCH_SHOW_RECENTS = 9;
Alan Viverettee34560b22014-07-10 14:50:06 -0700668 private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10;
Craig Mautnera631d492014-08-05 15:16:01 -0700669 private static final int MSG_HIDE_BOOT_MESSAGE = 11;
Michael Wright869a67c2014-08-26 19:33:06 -0700670 private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12;
Jeff Brown13f00f02014-10-31 14:45:50 -0700671 private static final int MSG_POWER_DELAYED_PRESS = 13;
672 private static final int MSG_POWER_LONG_PRESS = 14;
Jeff Brown061ea992015-04-17 19:55:47 -0700673 private static final int MSG_UPDATE_DREAMING_SLEEP_TOKEN = 15;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700674 private static final int MSG_REQUEST_TRANSIENT_BARS = 16;
Jaewan Kimc552b042016-01-18 16:08:45 +0900675 private static final int MSG_REQUEST_TV_PICTURE_IN_PICTURE = 17;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700676
677 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS = 0;
678 private static final int MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION = 1;
Jeff Brown70825162012-03-28 17:27:48 -0700679
680 private class PolicyHandler extends Handler {
681 @Override
682 public void handleMessage(Message msg) {
683 switch (msg.what) {
684 case MSG_ENABLE_POINTER_LOCATION:
685 enablePointerLocation();
686 break;
687 case MSG_DISABLE_POINTER_LOCATION:
688 disablePointerLocation();
689 break;
Jeff Brown40013652012-05-16 21:22:36 -0700690 case MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK:
691 dispatchMediaKeyWithWakeLock((KeyEvent)msg.obj);
692 break;
693 case MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK:
694 dispatchMediaKeyRepeatWithWakeLock((KeyEvent)msg.obj);
695 break;
Craig Mautner84984fa2014-06-19 11:19:20 -0700696 case MSG_DISPATCH_SHOW_RECENTS:
697 showRecentApps(false);
698 break;
Alan Viverettee34560b22014-07-10 14:50:06 -0700699 case MSG_DISPATCH_SHOW_GLOBAL_ACTIONS:
700 showGlobalActionsInternal();
701 break;
Craig Mautner8a0da012014-05-31 15:13:37 -0700702 case MSG_KEYGUARD_DRAWN_COMPLETE:
703 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700704 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700705 break;
706 case MSG_KEYGUARD_DRAWN_TIMEOUT:
707 Slog.w(TAG, "Keyguard drawn timeout. Setting mKeyguardDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700708 finishKeyguardDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700709 break;
710 case MSG_WINDOW_MANAGER_DRAWN_COMPLETE:
711 if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete");
Jeff Brown36c4db82014-09-19 12:05:31 -0700712 finishWindowsDrawn();
Craig Mautner8a0da012014-05-31 15:13:37 -0700713 break;
Craig Mautnera631d492014-08-05 15:16:01 -0700714 case MSG_HIDE_BOOT_MESSAGE:
715 handleHideBootMessage();
716 break;
Michael Wright869a67c2014-08-26 19:33:06 -0700717 case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK:
718 launchVoiceAssistWithWakeLock(msg.arg1 != 0);
719 break;
Jeff Brown13f00f02014-10-31 14:45:50 -0700720 case MSG_POWER_DELAYED_PRESS:
721 powerPress((Long)msg.obj, msg.arg1 != 0, msg.arg2);
722 finishPowerKeyPress();
723 break;
724 case MSG_POWER_LONG_PRESS:
725 powerLongPress();
726 break;
Jeff Brown061ea992015-04-17 19:55:47 -0700727 case MSG_UPDATE_DREAMING_SLEEP_TOKEN:
728 updateDreamingSleepToken(msg.arg1 != 0);
729 break;
Jun Mukaid2e7e352015-07-22 17:14:02 -0700730 case MSG_REQUEST_TRANSIENT_BARS:
731 WindowState targetBar = (msg.arg1 == MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS) ?
732 mStatusBar : mNavigationBar;
733 if (targetBar != null) {
734 requestTransientBars(targetBar);
735 }
736 break;
Jaewan Kimc552b042016-01-18 16:08:45 +0900737 case MSG_REQUEST_TV_PICTURE_IN_PICTURE:
738 requestTvPictureInPictureInternal();
739 break;
Jeff Brown70825162012-03-28 17:27:48 -0700740 }
741 }
742 }
743
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -0800744 private UEventObserver mHDMIObserver = new UEventObserver() {
745 @Override
746 public void onUEvent(UEventObserver.UEvent event) {
747 setHdmiPlugged("1".equals(event.get("SWITCH_STATE")));
748 }
749 };
750
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800751 class SettingsObserver extends ContentObserver {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800752 SettingsObserver(Handler handler) {
753 super(handler);
754 }
David Brownbaf8d092010-03-08 21:52:59 -0800755
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800756 void observe() {
Christopher Tate5e08af02012-09-21 17:17:22 -0700757 // Observe all users' changes
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800758 ContentResolver resolver = mContext.getContentResolver();
759 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700760 Settings.System.END_BUTTON_BEHAVIOR), false, this,
761 UserHandle.USER_ALL);
David Brownbaf8d092010-03-08 21:52:59 -0800762 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700763 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR), false, this,
764 UserHandle.USER_ALL);
Jeff Browna20dda42014-05-27 20:57:24 -0700765 resolver.registerContentObserver(Settings.Secure.getUriFor(
766 Settings.Secure.WAKE_GESTURE_ENABLED), false, this,
767 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800768 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700769 Settings.System.ACCELEROMETER_ROTATION), false, this,
770 UserHandle.USER_ALL);
Mike Lockwood28569302010-01-28 11:54:40 -0500771 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700772 Settings.System.USER_ROTATION), false, this,
773 UserHandle.USER_ALL);
Daniel Sandlerb73617d2010-08-17 00:41:00 -0400774 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700775 Settings.System.SCREEN_OFF_TIMEOUT), false, this,
776 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800777 resolver.registerContentObserver(Settings.System.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700778 Settings.System.POINTER_LOCATION), false, this,
779 UserHandle.USER_ALL);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800780 resolver.registerContentObserver(Settings.Secure.getUriFor(
Christopher Tate5e08af02012-09-21 17:17:22 -0700781 Settings.Secure.DEFAULT_INPUT_METHOD), false, this,
782 UserHandle.USER_ALL);
John Spurlockd9b70bd2014-02-06 17:02:44 -0500783 resolver.registerContentObserver(Settings.Secure.getUriFor(
John Spurlockf1a36642013-10-12 17:50:42 -0400784 Settings.Secure.IMMERSIVE_MODE_CONFIRMATIONS), false, this,
Christopher Tate5e08af02012-09-21 17:17:22 -0700785 UserHandle.USER_ALL);
John Spurlockc6d1c602014-01-17 15:22:06 -0500786 resolver.registerContentObserver(Settings.Global.getUriFor(
787 Settings.Global.POLICY_CONTROL), false, this,
788 UserHandle.USER_ALL);
Dianne Hackbornc777e072010-02-12 13:07:59 -0800789 updateSettings();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800790 }
791
792 @Override public void onChange(boolean selfChange) {
Dianne Hackbornc777e072010-02-12 13:07:59 -0800793 updateSettings();
Jeff Brown01a98dd2011-09-20 15:08:29 -0700794 updateRotation(false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800795 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800796 }
Craig Mautner967212c2013-04-13 21:10:58 -0700797
Jeff Browna20dda42014-05-27 20:57:24 -0700798 class MyWakeGestureListener extends WakeGestureListener {
799 MyWakeGestureListener(Context context, Handler handler) {
800 super(context, handler);
801 }
802
803 @Override
804 public void onWakeUp() {
805 synchronized (mLock) {
806 if (shouldEnableWakeGestureLp()) {
Jeff Browne07b94b2014-06-18 15:56:27 -0700807 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
Dianne Hackborn280a64e2015-07-13 14:48:08 -0700808 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromWakeGesture,
809 "android.policy:GESTURE");
Jeff Browna20dda42014-05-27 20:57:24 -0700810 }
811 }
812 }
813 }
814
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800815 class MyOrientationListener extends WindowOrientationListener {
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700816 private final Runnable mUpdateRotationRunnable = new Runnable() {
817 @Override
818 public void run() {
Tim Murray1f407642015-10-01 17:07:12 -0700819 // send interaction hint to improve redraw performance
820 mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700821 updateRotation(false);
822 }
823 };
824
Craig Mautnereee29c42013-01-17 14:44:34 -0800825 MyOrientationListener(Context context, Handler handler) {
826 super(context, handler);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800827 }
Craig Mautner967212c2013-04-13 21:10:58 -0700828
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800829 @Override
Jeff Brownc0347aa2011-09-23 17:26:09 -0700830 public void onProposedRotationChanged(int rotation) {
Craig Mautnereda67292013-04-28 13:50:14 -0700831 if (localLOGV) Slog.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
Chong Zhang5aaa0b32015-08-28 10:22:36 -0700832 mHandler.post(mUpdateRotationRunnable);
Jeff Brown01a98dd2011-09-20 15:08:29 -0700833 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800834 }
835 MyOrientationListener mOrientationListener;
836
Jorim Jaggi24bec7c2015-02-04 12:40:14 +0100837 private final StatusBarController mStatusBarController = new StatusBarController();
John Spurlock5b9145b2013-08-20 15:13:47 -0400838
John Spurlock27735a42013-08-14 17:57:38 -0400839 private final BarController mNavigationBarController = new BarController("NavigationBar",
John Spurlock5b9145b2013-08-20 15:13:47 -0400840 View.NAVIGATION_BAR_TRANSIENT,
841 View.NAVIGATION_BAR_UNHIDE,
John Spurlockbd957402013-10-03 11:38:39 -0400842 View.NAVIGATION_BAR_TRANSLUCENT,
843 StatusBarManager.WINDOW_NAVIGATION_BAR,
Jorim Jaggi4fa78922015-11-30 17:13:56 -0800844 WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
845 View.NAVIGATION_BAR_TRANSPARENT);
John Spurlock5b9145b2013-08-20 15:13:47 -0400846
John Spurlockf1a36642013-10-12 17:50:42 -0400847 private ImmersiveModeConfirmation mImmersiveModeConfirmation;
John Spurlock32beb2c2013-03-11 10:16:47 -0400848
Craig Mautner037aa8d2013-06-07 10:35:44 -0700849 private SystemGesturesPointerEventListener mSystemGestures;
John Spurlock32beb2c2013-03-11 10:16:47 -0400850
Dianne Hackborn42e620c2012-06-24 13:20:51 -0700851 IStatusBarService getStatusBarService() {
852 synchronized (mServiceAquireLock) {
853 if (mStatusBarService == null) {
854 mStatusBarService = IStatusBarService.Stub.asInterface(
855 ServiceManager.getService("statusbar"));
856 }
857 return mStatusBarService;
858 }
859 }
860
Jorim Jaggi86905582016-02-09 21:36:09 -0800861 StatusBarManagerInternal getStatusBarManagerInternal() {
862 synchronized (mServiceAquireLock) {
863 if (mStatusBarManagerInternal == null) {
864 mStatusBarManagerInternal =
865 LocalServices.getService(StatusBarManagerInternal.class);
866 }
867 return mStatusBarManagerInternal;
868 }
869 }
870
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700871 /*
872 * We always let the sensor be switched on by default except when
873 * the user has explicitly disabled sensor based rotation or when the
874 * screen is switched off.
875 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700876 boolean needSensorRunningLp() {
Jeff Brownbcdfc622014-03-06 19:13:04 -0800877 if (mSupportAutoRotation) {
878 if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
879 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
880 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
881 || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
882 // If the application has explicitly requested to follow the
883 // orientation, then we need to turn the sensor on.
884 return true;
885 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800886 }
Dianne Hackborn867ab6472010-04-29 13:28:56 -0700887 if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) ||
Jeff Brown1a693182011-11-08 14:44:16 -0800888 (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
889 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
890 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK))) {
Mike Lockwoode9867d22009-09-20 01:59:02 -0400891 // enable accelerometer if we are docked in a dock that enables accelerometer
892 // orientation management,
893 return true;
894 }
Jeff Brown207673cd2012-06-05 17:47:11 -0700895 if (mUserRotationMode == USER_ROTATION_LOCKED) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800896 // If the setting for using the sensor by default is enabled, then
897 // we will always leave it on. Note that the user could go to
898 // a window that forces an orientation that does not use the
899 // sensor and in theory we could turn it off... however, when next
900 // turning it on we won't have a good value for the current
901 // orientation for a little bit, which can cause orientation
902 // changes to lag, so we'd like to keep it always on. (It will
903 // still be turned off when the screen is off.)
Suchi Amalapurapua9e1b162009-03-24 22:24:47 -0700904 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800905 }
Jeff Brownbcdfc622014-03-06 19:13:04 -0800906 return mSupportAutoRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800907 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700908
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800909 /*
910 * Various use cases for invoking this function
911 * screen turning off, should always disable listeners if already enabled
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700912 * screen turned on and current app has sensor based orientation, enable listeners
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800913 * if not already enabled
914 * screen turned on and current app does not have sensor orientation, disable listeners if
915 * already enabled
916 * screen turning on and current app has sensor based orientation, enable listeners if needed
917 * screen turning on and current app has nosensor based orientation, do nothing
918 */
The Android Open Source Project0727d222009-03-11 12:11:58 -0700919 void updateOrientationListenerLp() {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800920 if (!mOrientationListener.canDetectOrientation()) {
921 // If sensor is turned off or nonexistent for some reason
922 return;
923 }
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000924 // Could have been invoked due to screen turning on or off or
925 // change of the currently visible window's orientation.
Jeff Brown3ee549c2014-09-22 20:14:39 -0700926 if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly
927 + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000928 + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled
929 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
930 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800931 boolean disable = true;
Stefan Kuhne9326dc12015-06-12 09:25:32 -1000932 // Note: We postpone the rotating of the screen until the keyguard as well as the
933 // window manager have reported a draw complete.
934 if (mScreenOnEarly && mAwake &&
935 mKeyguardDrawComplete && mWindowManagerDrawComplete) {
The Android Open Source Project0727d222009-03-11 12:11:58 -0700936 if (needSensorRunningLp()) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800937 disable = false;
938 //enable listener if not already enabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700939 if (!mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800940 mOrientationListener.enable();
Craig Mautnereda67292013-04-28 13:50:14 -0700941 if(localLOGV) Slog.v(TAG, "Enabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800942 mOrientationSensorEnabled = true;
943 }
Craig Mautner46ac6fa2013-08-01 10:06:34 -0700944 }
945 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800946 //check if sensors need to be disabled
The Android Open Source Project0727d222009-03-11 12:11:58 -0700947 if (disable && mOrientationSensorEnabled) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800948 mOrientationListener.disable();
Craig Mautnereda67292013-04-28 13:50:14 -0700949 if(localLOGV) Slog.v(TAG, "Disabling listeners");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -0800950 mOrientationSensorEnabled = false;
951 }
952 }
953
Jeff Brown13f00f02014-10-31 14:45:50 -0700954 private void interceptPowerKeyDown(KeyEvent event, boolean interactive) {
955 // Hold a wake lock until the power key is released.
956 if (!mPowerKeyWakeLock.isHeld()) {
957 mPowerKeyWakeLock.acquire();
958 }
959
960 // Cancel multi-press detection timeout.
961 if (mPowerKeyPressCounter != 0) {
962 mHandler.removeMessages(MSG_POWER_DELAYED_PRESS);
963 }
964
965 // Detect user pressing the power button in panic when an application has
966 // taken over the whole screen.
967 boolean panic = mImmersiveModeConfirmation.onPowerKeyDown(interactive,
Craig Mautner0124980e92014-11-30 21:15:34 -0800968 SystemClock.elapsedRealtime(), isImmersiveMode(mLastSystemUiFlags));
Jeff Brown13f00f02014-10-31 14:45:50 -0700969 if (panic) {
Adrian Roosddc8b272015-05-21 16:28:27 -0700970 mHandler.post(mHiddenNavPanic);
Jeff Brown13f00f02014-10-31 14:45:50 -0700971 }
972
973 // Latch power key state to detect screenshot chord.
974 if (interactive && !mScreenshotChordPowerKeyTriggered
975 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
976 mScreenshotChordPowerKeyTriggered = true;
977 mScreenshotChordPowerKeyTime = event.getDownTime();
978 interceptScreenshotChord();
979 }
980
981 // Stop ringing or end call if configured to do so when power is pressed.
982 TelecomManager telecomManager = getTelecommService();
983 boolean hungUp = false;
984 if (telecomManager != null) {
985 if (telecomManager.isRinging()) {
986 // Pressing Power while there's a ringing incoming
987 // call should silence the ringer.
988 telecomManager.silenceRinger();
989 } else if ((mIncallPowerBehavior
990 & Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_HANGUP) != 0
991 && telecomManager.isInCall() && interactive) {
992 // Otherwise, if "Power button ends call" is enabled,
993 // the Power button will hang up any current active call.
994 hungUp = telecomManager.endCall();
995 }
996 }
997
Adrian Roos5941c982015-09-03 15:59:49 -0700998 GestureLauncherService gestureService = LocalServices.getService(
999 GestureLauncherService.class);
1000 boolean gesturedServiceIntercepted = false;
1001 if (gestureService != null) {
1002 gesturedServiceIntercepted = gestureService.interceptPowerKeyDown(event, interactive);
1003 }
1004
Jeff Brown13f00f02014-10-31 14:45:50 -07001005 // If the power key has still not yet been handled, then detect short
1006 // press, long press, or multi press and decide what to do.
1007 mPowerKeyHandled = hungUp || mScreenshotChordVolumeDownKeyTriggered
Adrian Roos5941c982015-09-03 15:59:49 -07001008 || mScreenshotChordVolumeUpKeyTriggered || gesturedServiceIntercepted;
Jeff Brown13f00f02014-10-31 14:45:50 -07001009 if (!mPowerKeyHandled) {
1010 if (interactive) {
1011 // When interactive, we're already awake.
1012 // Wait for a long press or for the button to be released to decide what to do.
1013 if (hasLongPressOnPowerBehavior()) {
1014 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1015 msg.setAsynchronous(true);
1016 mHandler.sendMessageDelayed(msg,
1017 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
1018 }
1019 } else {
Bryce Leed9268e32014-11-17 17:40:59 -08001020 wakeUpFromPowerKey(event.getDownTime());
Bryce Leed9268e32014-11-17 17:40:59 -08001021
Bryce Leed3b28402015-03-09 15:49:13 +00001022 if (mSupportLongPressPowerWhenNonInteractive && hasLongPressOnPowerBehavior()) {
1023 Message msg = mHandler.obtainMessage(MSG_POWER_LONG_PRESS);
1024 msg.setAsynchronous(true);
1025 mHandler.sendMessageDelayed(msg,
1026 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Bryce Leed9268e32014-11-17 17:40:59 -08001027 mBeganFromNonInteractive = true;
Bryce Leed3b28402015-03-09 15:49:13 +00001028 } else {
1029 final int maxCount = getMaxMultiPressPowerCount();
1030
1031 if (maxCount <= 1) {
1032 mPowerKeyHandled = true;
1033 } else {
1034 mBeganFromNonInteractive = true;
1035 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001036 }
1037 }
Jeff Brown4d396052010-10-29 21:50:21 -07001038 }
1039 }
1040
Jeff Brown13f00f02014-10-31 14:45:50 -07001041 private void interceptPowerKeyUp(KeyEvent event, boolean interactive, boolean canceled) {
1042 final boolean handled = canceled || mPowerKeyHandled;
1043 mScreenshotChordPowerKeyTriggered = false;
1044 cancelPendingScreenshotChordAction();
1045 cancelPendingPowerKeyAction();
1046
1047 if (!handled) {
1048 // Figure out how to handle the key now that it has been released.
1049 mPowerKeyPressCounter += 1;
1050
1051 final int maxCount = getMaxMultiPressPowerCount();
1052 final long eventTime = event.getDownTime();
1053 if (mPowerKeyPressCounter < maxCount) {
1054 // This could be a multi-press. Wait a little bit longer to confirm.
1055 // Continue holding the wake lock.
1056 Message msg = mHandler.obtainMessage(MSG_POWER_DELAYED_PRESS,
1057 interactive ? 1 : 0, mPowerKeyPressCounter, eventTime);
1058 msg.setAsynchronous(true);
1059 mHandler.sendMessageDelayed(msg, ViewConfiguration.getDoubleTapTimeout());
1060 return;
1061 }
1062
1063 // No other actions. Handle it immediately.
1064 powerPress(eventTime, interactive, mPowerKeyPressCounter);
Jeff Brown4d396052010-10-29 21:50:21 -07001065 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001066
1067 // Done. Reset our state.
1068 finishPowerKeyPress();
1069 }
1070
1071 private void finishPowerKeyPress() {
Bryce Leed9268e32014-11-17 17:40:59 -08001072 mBeganFromNonInteractive = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001073 mPowerKeyPressCounter = 0;
1074 if (mPowerKeyWakeLock.isHeld()) {
1075 mPowerKeyWakeLock.release();
1076 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001077 }
1078
1079 private void cancelPendingPowerKeyAction() {
1080 if (!mPowerKeyHandled) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001081 mPowerKeyHandled = true;
1082 mHandler.removeMessages(MSG_POWER_LONG_PRESS);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001083 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001084 }
1085
1086 private void powerPress(long eventTime, boolean interactive, int count) {
1087 if (mScreenOnEarly && !mScreenOnFully) {
1088 Slog.i(TAG, "Suppressed redundant power key press while "
1089 + "already in the process of turning the screen on.");
1090 return;
Jeff Brownff204712011-10-25 21:27:54 -07001091 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001092
1093 if (count == 2) {
1094 powerMultiPressAction(eventTime, interactive, mDoublePressOnPowerBehavior);
1095 } else if (count == 3) {
1096 powerMultiPressAction(eventTime, interactive, mTriplePressOnPowerBehavior);
Bryce Leed9268e32014-11-17 17:40:59 -08001097 } else if (interactive && !mBeganFromNonInteractive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001098 switch (mShortPressOnPowerBehavior) {
1099 case SHORT_PRESS_POWER_NOTHING:
1100 break;
1101 case SHORT_PRESS_POWER_GO_TO_SLEEP:
1102 mPowerManager.goToSleep(eventTime,
1103 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1104 break;
1105 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP:
1106 mPowerManager.goToSleep(eventTime,
1107 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1108 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1109 break;
1110 case SHORT_PRESS_POWER_REALLY_GO_TO_SLEEP_AND_GO_HOME:
1111 mPowerManager.goToSleep(eventTime,
1112 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON,
1113 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
1114 launchHomeFromHotKey();
1115 break;
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001116 case SHORT_PRESS_POWER_GO_HOME:
Bryce Lee662ed802015-04-10 20:11:39 +00001117 launchHomeFromHotKey(true /* awakenFromDreams */, false /*respectKeyguard*/);
Bryce Lee01b0c5f2015-02-05 18:24:04 -08001118 break;
Jeff Brown13f00f02014-10-31 14:45:50 -07001119 }
1120 }
1121 }
1122
1123 private void powerMultiPressAction(long eventTime, boolean interactive, int behavior) {
1124 switch (behavior) {
1125 case MULTI_PRESS_POWER_NOTHING:
1126 break;
1127 case MULTI_PRESS_POWER_THEATER_MODE:
Bryce Lee3ae447e2015-06-30 12:31:41 -07001128 if (!isUserSetupComplete()) {
1129 Slog.i(TAG, "Ignoring toggling theater mode - device not setup.");
1130 break;
1131 }
1132
Jeff Brown13f00f02014-10-31 14:45:50 -07001133 if (isTheaterModeEnabled()) {
1134 Slog.i(TAG, "Toggling theater mode off.");
1135 Settings.Global.putInt(mContext.getContentResolver(),
1136 Settings.Global.THEATER_MODE_ON, 0);
1137 if (!interactive) {
1138 wakeUpFromPowerKey(eventTime);
1139 }
1140 } else {
1141 Slog.i(TAG, "Toggling theater mode on.");
1142 Settings.Global.putInt(mContext.getContentResolver(),
1143 Settings.Global.THEATER_MODE_ON, 1);
Bryce Lee55e846d2014-11-04 12:43:44 -08001144
1145 if (mGoToSleepOnButtonPressTheaterMode && interactive) {
Jeff Brown13f00f02014-10-31 14:45:50 -07001146 mPowerManager.goToSleep(eventTime,
1147 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
1148 }
1149 }
1150 break;
1151 case MULTI_PRESS_POWER_BRIGHTNESS_BOOST:
Jeff Brown7b5be5e2014-11-12 18:45:31 -08001152 Slog.i(TAG, "Starting brightness boost.");
1153 if (!interactive) {
1154 wakeUpFromPowerKey(eventTime);
1155 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001156 mPowerManager.boostScreenBrightness(eventTime);
1157 break;
1158 }
1159 }
1160
1161 private int getMaxMultiPressPowerCount() {
1162 if (mTriplePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1163 return 3;
1164 }
1165 if (mDoublePressOnPowerBehavior != MULTI_PRESS_POWER_NOTHING) {
1166 return 2;
1167 }
1168 return 1;
1169 }
1170
1171 private void powerLongPress() {
1172 final int behavior = getResolvedLongPressOnPowerBehavior();
1173 switch (behavior) {
1174 case LONG_PRESS_POWER_NOTHING:
1175 break;
1176 case LONG_PRESS_POWER_GLOBAL_ACTIONS:
1177 mPowerKeyHandled = true;
1178 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1179 performAuditoryFeedbackForAccessibilityIfNeed();
1180 }
1181 showGlobalActionsInternal();
1182 break;
1183 case LONG_PRESS_POWER_SHUT_OFF:
1184 case LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM:
1185 mPowerKeyHandled = true;
1186 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
1187 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
1188 mWindowManagerFuncs.shutdown(behavior == LONG_PRESS_POWER_SHUT_OFF);
1189 break;
1190 }
1191 }
1192
Nick Vaccarob593a812015-05-15 11:23:05 -07001193 private void sleepPress(long eventTime) {
1194 if (mShortPressOnSleepBehavior == SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME) {
1195 launchHomeFromHotKey(false /* awakenDreams */, true /*respectKeyguard*/);
1196 }
1197 }
1198
1199 private void sleepRelease(long eventTime) {
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001200 switch (mShortPressOnSleepBehavior) {
1201 case SHORT_PRESS_SLEEP_GO_TO_SLEEP:
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001202 case SHORT_PRESS_SLEEP_GO_TO_SLEEP_AND_GO_HOME:
Nick Vaccarob593a812015-05-15 11:23:05 -07001203 Slog.i(TAG, "sleepRelease() calling goToSleep(GO_TO_SLEEP_REASON_SLEEP_BUTTON)");
1204 mPowerManager.goToSleep(eventTime,
1205 PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON, 0);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001206 break;
1207 }
1208 }
1209
Jeff Brown13f00f02014-10-31 14:45:50 -07001210 private int getResolvedLongPressOnPowerBehavior() {
1211 if (FactoryTest.isLongPressOnPowerOffEnabled()) {
1212 return LONG_PRESS_POWER_SHUT_OFF_NO_CONFIRM;
1213 }
1214 return mLongPressOnPowerBehavior;
1215 }
1216
1217 private boolean hasLongPressOnPowerBehavior() {
1218 return getResolvedLongPressOnPowerBehavior() != LONG_PRESS_POWER_NOTHING;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001219 }
1220
1221 private void interceptScreenshotChord() {
Christopher Tatee90585f2012-03-05 18:56:25 -08001222 if (mScreenshotChordEnabled
Jeff Brown13f00f02014-10-31 14:45:50 -07001223 && mScreenshotChordVolumeDownKeyTriggered && mScreenshotChordPowerKeyTriggered
1224 && !mScreenshotChordVolumeUpKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001225 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07001226 if (now <= mScreenshotChordVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS
1227 && now <= mScreenshotChordPowerKeyTime
1228 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) {
1229 mScreenshotChordVolumeDownKeyConsumed = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001230 cancelPendingPowerKeyAction();
1231
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001232 mHandler.postDelayed(mScreenshotRunnable, getScreenshotChordLongPressDelay());
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001233 }
1234 }
1235 }
1236
Winson Chung1cea2f32012-10-08 20:42:01 -07001237 private long getScreenshotChordLongPressDelay() {
Jim Miller5ecd8112013-01-09 18:50:26 -08001238 if (mKeyguardDelegate.isShowing()) {
Winson Chung1cea2f32012-10-08 20:42:01 -07001239 // Double the time it takes to take a screenshot from the keyguard
1240 return (long) (KEYGUARD_SCREENSHOT_CHORD_DELAY_MULTIPLIER *
Justin Kohfeabd2c2014-05-02 10:02:44 -07001241 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
Winson Chung1cea2f32012-10-08 20:42:01 -07001242 }
Justin Kohfeabd2c2014-05-02 10:02:44 -07001243 return ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout();
Winson Chung1cea2f32012-10-08 20:42:01 -07001244 }
1245
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001246 private void cancelPendingScreenshotChordAction() {
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001247 mHandler.removeCallbacks(mScreenshotRunnable);
Jeff Brown4d396052010-10-29 21:50:21 -07001248 }
1249
Jeff Brown13f00f02014-10-31 14:45:50 -07001250 private final Runnable mEndCallLongPress = new Runnable() {
Craig Mautnerf1b67412012-09-19 13:18:29 -07001251 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001252 public void run() {
Jeff Brown13f00f02014-10-31 14:45:50 -07001253 mEndCallKeyHandled = true;
1254 if (!performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false)) {
1255 performAuditoryFeedbackForAccessibilityIfNeed();
Joe Onoratod208e702010-10-08 16:22:43 -04001256 }
Jeff Brown13f00f02014-10-31 14:45:50 -07001257 showGlobalActionsInternal();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001258 }
1259 };
1260
Jeff Sharkey2991fa32012-12-05 18:06:43 -08001261 private final Runnable mScreenshotRunnable = new Runnable() {
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001262 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07001263 public void run() {
1264 takeScreenshot();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001265 }
1266 };
1267
Alan Viverettee34560b22014-07-10 14:50:06 -07001268 @Override
1269 public void showGlobalActions() {
1270 mHandler.removeMessages(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1271 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_GLOBAL_ACTIONS);
1272 }
1273
1274 void showGlobalActionsInternal() {
1275 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_GLOBAL_ACTIONS);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001276 if (mGlobalActions == null) {
Jeff Brown7304c342012-05-11 18:42:42 -07001277 mGlobalActions = new GlobalActions(mContext, mWindowManagerFuncs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001278 }
Jim Millerab954542014-10-10 18:21:49 -07001279 final boolean keyguardShowing = isKeyguardShowingAndNotOccluded();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001280 mGlobalActions.showDialog(keyguardShowing, isDeviceProvisioned());
1281 if (keyguardShowing) {
1282 // since it took two seconds of long press to bring this up,
1283 // poke the wake lock so they have some time to see the dialog.
Jim Miller25190572013-02-28 17:36:24 -08001284 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001285 }
1286 }
1287
1288 boolean isDeviceProvisioned() {
Jeff Brownbf6f6f92012-09-25 15:03:20 -07001289 return Settings.Global.getInt(
1290 mContext.getContentResolver(), Settings.Global.DEVICE_PROVISIONED, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001291 }
1292
Maurice Lam99c6e072014-04-28 18:24:28 -07001293 boolean isUserSetupComplete() {
1294 return Settings.Secure.getIntForUser(mContext.getContentResolver(),
1295 Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) != 0;
1296 }
1297
Jeff Brown13f00f02014-10-31 14:45:50 -07001298 private void handleShortPressOnHome() {
Jinsuk Kime601b712015-07-07 08:01:02 +09001299 // Turn on the connected TV and switch HDMI input if we're a HDMI playback device.
1300 getHdmiControl().turnOnTv();
1301
Jeff Brown13f00f02014-10-31 14:45:50 -07001302 // If there's a dream running then use home to escape the dream
1303 // but don't actually go home.
1304 if (mDreamManagerInternal != null && mDreamManagerInternal.isDreaming()) {
1305 mDreamManagerInternal.stopDream(false /*immediate*/);
1306 return;
1307 }
1308
1309 // Go home!
1310 launchHomeFromHotKey();
1311 }
1312
Jinsuk Kime601b712015-07-07 08:01:02 +09001313 /**
1314 * Creates an accessor to HDMI control service that performs the operation of
1315 * turning on TV (optional) and switching input to us. If HDMI control service
1316 * is not available or we're not a HDMI playback device, the operation is no-op.
1317 */
1318 private HdmiControl getHdmiControl() {
1319 if (null == mHdmiControl) {
1320 HdmiControlManager manager = (HdmiControlManager) mContext.getSystemService(
1321 Context.HDMI_CONTROL_SERVICE);
1322 HdmiPlaybackClient client = null;
1323 if (manager != null) {
1324 client = manager.getPlaybackClient();
1325 }
1326 mHdmiControl = new HdmiControl(client);
1327 }
1328 return mHdmiControl;
1329 }
1330
1331 private static class HdmiControl {
1332 private final HdmiPlaybackClient mClient;
1333
1334 private HdmiControl(HdmiPlaybackClient client) {
1335 mClient = client;
1336 }
1337
1338 public void turnOnTv() {
1339 if (mClient == null) {
1340 return;
1341 }
1342 mClient.oneTouchPlay(new OneTouchPlayCallback() {
1343 @Override
1344 public void onComplete(int result) {
1345 if (result != HdmiControlManager.RESULT_SUCCESS) {
1346 Log.w(TAG, "One touch play failed: " + result);
1347 }
1348 }
1349 });
1350 }
1351 }
1352
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001353 private void handleLongPressOnHome(int deviceId) {
Jaewan Kim52632e22016-01-14 18:01:52 +09001354 if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_NOTHING) {
1355 return;
1356 }
1357 mHomeConsumed = true;
1358 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
Patrick Dubroyece94522011-02-23 18:35:01 -08001359
Jaewan Kim52632e22016-01-14 18:01:52 +09001360 switch (mLongPressOnHomeBehavior) {
1361 case LONG_PRESS_HOME_RECENT_SYSTEM_UI:
Jeff Browncaca8812013-05-09 13:34:33 -07001362 toggleRecentApps();
Jaewan Kim52632e22016-01-14 18:01:52 +09001363 break;
1364 case LONG_PRESS_HOME_ASSIST:
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07001365 launchAssistAction(null, deviceId);
Jaewan Kim52632e22016-01-14 18:01:52 +09001366 break;
Jaewan Kim52632e22016-01-14 18:01:52 +09001367 default:
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09001368 Log.w(TAG, "Undefined home long press behavior: " + mLongPressOnHomeBehavior);
Jaewan Kim52632e22016-01-14 18:01:52 +09001369 break;
Jim Millere6ad1a82010-08-20 19:25:39 -07001370 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001371 }
Patrick Dubroyece94522011-02-23 18:35:01 -08001372
Jeff Browncaca8812013-05-09 13:34:33 -07001373 private void handleDoubleTapOnHome() {
1374 if (mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1375 mHomeConsumed = true;
1376 toggleRecentApps();
1377 }
1378 }
1379
Jaewan Kimc552b042016-01-18 16:08:45 +09001380 private void requestTvPictureInPicture(KeyEvent event) {
1381 if (DEBUG_INPUT) Log.d(TAG, "requestTvPictureInPicture event=" + event);
1382 mHandler.removeMessages(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1383 Message msg = mHandler.obtainMessage(MSG_REQUEST_TV_PICTURE_IN_PICTURE);
1384 msg.setAsynchronous(true);
1385 msg.sendToTarget();
1386 }
1387
1388 private void requestTvPictureInPictureInternal() {
1389 try {
1390 IStatusBarService statusbar = getStatusBarService();
1391 if (statusbar != null) {
1392 statusbar.requestTvPictureInPicture();
1393 }
1394 } catch (RemoteException|IllegalArgumentException e) {
1395 Slog.e(TAG, "Cannot handle picture-in-picture key", e);
1396 // re-acquire status bar service next time it is needed.
1397 mStatusBarService = null;
1398 }
Jaewan Kim52632e22016-01-14 18:01:52 +09001399 }
1400
Jeff Browncaca8812013-05-09 13:34:33 -07001401 private final Runnable mHomeDoubleTapTimeoutRunnable = new Runnable() {
1402 @Override
1403 public void run() {
1404 if (mHomeDoubleTapPending) {
1405 mHomeDoubleTapPending = false;
Jeff Brown13f00f02014-10-31 14:45:50 -07001406 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07001407 }
1408 }
1409 };
1410
Mark Renoufc1256912015-03-11 14:38:23 -04001411 private boolean isRoundWindow() {
Adam Powell01f280d2015-05-18 16:07:42 -07001412 return mContext.getResources().getConfiguration().isScreenRound();
Mark Renoufc1256912015-03-11 14:38:23 -04001413 }
1414
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001415 /** {@inheritDoc} */
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001416 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001417 public void init(Context context, IWindowManager windowManager,
Jeff Brown96307042012-07-27 15:51:34 -07001418 WindowManagerFuncs windowManagerFuncs) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001419 mContext = context;
1420 mWindowManager = windowManager;
Dianne Hackborndf89e652011-10-06 22:35:11 -07001421 mWindowManagerFuncs = windowManagerFuncs;
Craig Mautner8a0da012014-05-31 15:13:37 -07001422 mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
Jeff Brown061ea992015-04-17 19:55:47 -07001423 mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class);
Jose Lima9546b202014-07-02 17:21:51 -07001424 mDreamManagerInternal = LocalServices.getService(DreamManagerInternal.class);
Michael Wrighta4d22d72015-09-16 23:19:26 +01001425 mPowerManagerInternal = LocalServices.getService(PowerManagerInternal.class);
Billy Laucbe540f2015-06-25 01:51:44 +01001426 mAppOpsManager = (AppOpsManager) mContext.getSystemService(Context.APP_OPS_SERVICE);
Mark Renoufc1256912015-03-11 14:38:23 -04001427
1428 // Init display burn-in protection
1429 boolean burnInProtectionEnabled = context.getResources().getBoolean(
1430 com.android.internal.R.bool.config_enableBurnInProtection);
1431 // Allow a system property to override this. Used by developer settings.
1432 boolean burnInProtectionDevMode =
1433 SystemProperties.getBoolean("persist.debug.force_burn_in", false);
1434 if (burnInProtectionEnabled || burnInProtectionDevMode) {
1435 final int minHorizontal;
1436 final int maxHorizontal;
1437 final int minVertical;
1438 final int maxVertical;
1439 final int maxRadius;
1440 if (burnInProtectionDevMode) {
1441 minHorizontal = -8;
1442 maxHorizontal = 8;
1443 minVertical = -8;
1444 maxVertical = -4;
1445 maxRadius = (isRoundWindow()) ? 6 : -1;
1446 } else {
1447 Resources resources = context.getResources();
1448 minHorizontal = resources.getInteger(
1449 com.android.internal.R.integer.config_burnInProtectionMinHorizontalOffset);
1450 maxHorizontal = resources.getInteger(
1451 com.android.internal.R.integer.config_burnInProtectionMaxHorizontalOffset);
1452 minVertical = resources.getInteger(
1453 com.android.internal.R.integer.config_burnInProtectionMinVerticalOffset);
1454 maxVertical = resources.getInteger(
1455 com.android.internal.R.integer.config_burnInProtectionMaxVerticalOffset);
1456 maxRadius = resources.getInteger(
1457 com.android.internal.R.integer.config_burnInProtectionMaxRadius);
1458 }
1459 mBurnInProtectionHelper = new BurnInProtectionHelper(
1460 context, minHorizontal, maxHorizontal, minVertical, maxVertical, maxRadius);
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00001461 }
Craig Mautner8a0da012014-05-31 15:13:37 -07001462
Jeff Brown70825162012-03-28 17:27:48 -07001463 mHandler = new PolicyHandler();
Jeff Browna20dda42014-05-27 20:57:24 -07001464 mWakeGestureListener = new MyWakeGestureListener(mContext, mHandler);
Craig Mautnereee29c42013-01-17 14:44:34 -08001465 mOrientationListener = new MyOrientationListener(mContext, mHandler);
Jeff Brownc0347aa2011-09-23 17:26:09 -07001466 try {
1467 mOrientationListener.setCurrentRotation(windowManager.getRotation());
1468 } catch (RemoteException ex) { }
Christopher Tate5e08af02012-09-21 17:17:22 -07001469 mSettingsObserver = new SettingsObserver(mHandler);
1470 mSettingsObserver.observe();
Svetoslav683914b2015-01-15 14:22:26 -08001471 mShortcutManager = new ShortcutManager(context);
Daniel Sandler6396c722013-04-16 20:19:09 -04001472 mUiMode = context.getResources().getInteger(
1473 com.android.internal.R.integer.config_defaultUiModeType);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001474 mHomeIntent = new Intent(Intent.ACTION_MAIN, null);
1475 mHomeIntent.addCategory(Intent.CATEGORY_HOME);
1476 mHomeIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1477 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
keunyounga7710492015-09-23 11:33:58 -07001478 mEnableCarDockHomeCapture = context.getResources().getBoolean(
1479 com.android.internal.R.bool.config_enableCarDockHomeLaunch);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07001480 mCarDockIntent = new Intent(Intent.ACTION_MAIN, null);
1481 mCarDockIntent.addCategory(Intent.CATEGORY_CAR_DOCK);
1482 mCarDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1483 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
1484 mDeskDockIntent = new Intent(Intent.ACTION_MAIN, null);
1485 mDeskDockIntent.addCategory(Intent.CATEGORY_DESK_DOCK);
1486 mDeskDockIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
1487 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
Jim Millere6ad1a82010-08-20 19:25:39 -07001488
Jeff Brown96307042012-07-27 15:51:34 -07001489 mPowerManager = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
1490 mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001491 "PhoneWindowManager.mBroadcastWakeLock");
Jeff Brown13f00f02014-10-31 14:45:50 -07001492 mPowerKeyWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
1493 "PhoneWindowManager.mPowerKeyWakeLock");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001494 mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable"));
Jeff Brownbcdfc622014-03-06 19:13:04 -08001495 mSupportAutoRotation = mContext.getResources().getBoolean(
1496 com.android.internal.R.bool.config_supportAutoRotation);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001497 mLidOpenRotation = readRotation(
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001498 com.android.internal.R.integer.config_lidOpenRotation);
1499 mCarDockRotation = readRotation(
1500 com.android.internal.R.integer.config_carDockRotation);
1501 mDeskDockRotation = readRotation(
1502 com.android.internal.R.integer.config_deskDockRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001503 mUndockedHdmiRotation = readRotation(
1504 com.android.internal.R.integer.config_undockedHdmiRotation);
Mike Lockwoode9867d22009-09-20 01:59:02 -04001505 mCarDockEnablesAccelerometer = mContext.getResources().getBoolean(
1506 com.android.internal.R.bool.config_carDockEnablesAccelerometer);
1507 mDeskDockEnablesAccelerometer = mContext.getResources().getBoolean(
1508 com.android.internal.R.bool.config_deskDockEnablesAccelerometer);
Dianne Hackborn2862fff2009-09-15 22:56:29 -07001509 mLidKeyboardAccessibility = mContext.getResources().getInteger(
1510 com.android.internal.R.integer.config_lidKeyboardAccessibility);
1511 mLidNavigationAccessibility = mContext.getResources().getInteger(
1512 com.android.internal.R.integer.config_lidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01001513 mLidControlsScreenLock = mContext.getResources().getBoolean(
1514 com.android.internal.R.bool.config_lidControlsScreenLock);
Jeff Brownc458ce92012-04-30 14:58:40 -07001515 mLidControlsSleep = mContext.getResources().getBoolean(
1516 com.android.internal.R.bool.config_lidControlsSleep);
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04001517 mTranslucentDecorEnabled = mContext.getResources().getBoolean(
1518 com.android.internal.R.bool.config_enableTranslucentDecor);
Bryce Lee584a4452014-10-21 15:55:55 -07001519
1520 mAllowTheaterModeWakeFromKey = mContext.getResources().getBoolean(
1521 com.android.internal.R.bool.config_allowTheaterModeWakeFromKey);
1522 mAllowTheaterModeWakeFromPowerKey = mAllowTheaterModeWakeFromKey
1523 || mContext.getResources().getBoolean(
1524 com.android.internal.R.bool.config_allowTheaterModeWakeFromPowerKey);
1525 mAllowTheaterModeWakeFromMotion = mContext.getResources().getBoolean(
1526 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotion);
Bryce Lee812d7022014-11-10 13:33:28 -08001527 mAllowTheaterModeWakeFromMotionWhenNotDreaming = mContext.getResources().getBoolean(
1528 com.android.internal.R.bool.config_allowTheaterModeWakeFromMotionWhenNotDreaming);
Bryce Lee584a4452014-10-21 15:55:55 -07001529 mAllowTheaterModeWakeFromCameraLens = mContext.getResources().getBoolean(
1530 com.android.internal.R.bool.config_allowTheaterModeWakeFromCameraLens);
1531 mAllowTheaterModeWakeFromLidSwitch = mContext.getResources().getBoolean(
1532 com.android.internal.R.bool.config_allowTheaterModeWakeFromLidSwitch);
1533 mAllowTheaterModeWakeFromWakeGesture = mContext.getResources().getBoolean(
1534 com.android.internal.R.bool.config_allowTheaterModeWakeFromGesture);
1535
Bryce Lee55e846d2014-11-04 12:43:44 -08001536 mGoToSleepOnButtonPressTheaterMode = mContext.getResources().getBoolean(
1537 com.android.internal.R.bool.config_goToSleepOnButtonPressTheaterMode);
1538
Bryce Leed3b28402015-03-09 15:49:13 +00001539 mSupportLongPressPowerWhenNonInteractive = mContext.getResources().getBoolean(
1540 com.android.internal.R.bool.config_supportLongPressPowerWhenNonInteractive);
1541
Jeff Brown13f00f02014-10-31 14:45:50 -07001542 mShortPressOnPowerBehavior = mContext.getResources().getInteger(
1543 com.android.internal.R.integer.config_shortPressOnPowerBehavior);
1544 mLongPressOnPowerBehavior = mContext.getResources().getInteger(
1545 com.android.internal.R.integer.config_longPressOnPowerBehavior);
1546 mDoublePressOnPowerBehavior = mContext.getResources().getInteger(
1547 com.android.internal.R.integer.config_doublePressOnPowerBehavior);
1548 mTriplePressOnPowerBehavior = mContext.getResources().getInteger(
1549 com.android.internal.R.integer.config_triplePressOnPowerBehavior);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00001550 mShortPressOnSleepBehavior = mContext.getResources().getInteger(
1551 com.android.internal.R.integer.config_shortPressOnSleepBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07001552
John Spurlock61560172015-02-06 19:46:04 -05001553 mUseTvRouting = AudioSystem.getPlatformType(mContext) == AudioSystem.PLATFORM_TELEVISION;
RoboErik001c59c2015-01-26 15:53:51 -08001554
Jeff Brownf71343d2013-05-31 17:59:11 -07001555 readConfigurationDependentBehaviors();
Jeff Browncaca8812013-05-09 13:34:33 -07001556
Svetoslav8e3feb12014-02-24 13:46:47 -08001557 mAccessibilityManager = (AccessibilityManager) context.getSystemService(
1558 Context.ACCESSIBILITY_SERVICE);
1559
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001560 // register for dock events
Dianne Hackborn78968392010-03-04 20:47:56 -08001561 IntentFilter filter = new IntentFilter();
1562 filter.addAction(UiModeManager.ACTION_ENTER_CAR_MODE);
1563 filter.addAction(UiModeManager.ACTION_EXIT_CAR_MODE);
1564 filter.addAction(UiModeManager.ACTION_ENTER_DESK_MODE);
1565 filter.addAction(UiModeManager.ACTION_EXIT_DESK_MODE);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07001566 filter.addAction(Intent.ACTION_DOCK_EVENT);
1567 Intent intent = context.registerReceiver(mDockReceiver, filter);
1568 if (intent != null) {
1569 // Retrieve current sticky dock event broadcast.
1570 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
1571 Intent.EXTRA_DOCK_STATE_UNDOCKED);
1572 }
Daniel Sandler7e37df52011-11-16 22:08:23 -08001573
Jeff Brown6aaf2952012-10-05 16:01:08 -07001574 // register for dream-related broadcasts
1575 filter = new IntentFilter();
1576 filter.addAction(Intent.ACTION_DREAMING_STARTED);
1577 filter.addAction(Intent.ACTION_DREAMING_STOPPED);
1578 context.registerReceiver(mDreamReceiver, filter);
1579
Christopher Tate5e08af02012-09-21 17:17:22 -07001580 // register for multiuser-relevant broadcasts
1581 filter = new IntentFilter(Intent.ACTION_USER_SWITCHED);
1582 context.registerReceiver(mMultiuserReceiver, filter);
1583
John Spurlock57306e62013-04-22 09:48:49 -04001584 // monitor for system gestures
Craig Mautner037aa8d2013-06-07 10:35:44 -07001585 mSystemGestures = new SystemGesturesPointerEventListener(context,
1586 new SystemGesturesPointerEventListener.Callbacks() {
John Spurlock57306e62013-04-22 09:48:49 -04001587 @Override
1588 public void onSwipeFromTop() {
John Spurlock04db1762013-05-13 12:46:41 -04001589 if (mStatusBar != null) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001590 requestTransientBars(mStatusBar);
John Spurlock04db1762013-05-13 12:46:41 -04001591 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001592 }
1593 @Override
1594 public void onSwipeFromBottom() {
John Spurlock04db1762013-05-13 12:46:41 -04001595 if (mNavigationBar != null && mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001596 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001597 }
1598 }
1599 @Override
1600 public void onSwipeFromRight() {
John Spurlock04db1762013-05-13 12:46:41 -04001601 if (mNavigationBar != null && !mNavigationBarOnBottom) {
John Spurlocke1f366f2013-08-05 12:22:40 -04001602 requestTransientBars(mNavigationBar);
John Spurlockad3e6cb2013-04-30 08:47:43 -04001603 }
1604 }
1605 @Override
Michael Wrighta4d22d72015-09-16 23:19:26 +01001606 public void onFling(int duration) {
1607 if (mPowerManagerInternal != null) {
1608 mPowerManagerInternal.powerHint(
1609 PowerManagerInternal.POWER_HINT_INTERACTION, duration);
1610 }
1611 }
1612 @Override
John Spurlockad3e6cb2013-04-30 08:47:43 -04001613 public void onDebug() {
John Spurlockd67ec252013-09-05 11:31:54 -04001614 // no-op
John Spurlockad3e6cb2013-04-30 08:47:43 -04001615 }
Adrian Roos3595be42015-03-05 16:31:15 +01001616 @Override
1617 public void onDown() {
1618 mOrientationListener.onTouchStart();
1619 }
1620 @Override
1621 public void onUpOrCancel() {
1622 mOrientationListener.onTouchEnd();
1623 }
Jun Mukaid2e7e352015-07-22 17:14:02 -07001624 @Override
1625 public void onMouseHoverAtTop() {
1626 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1627 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1628 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_STATUS;
1629 mHandler.sendMessageDelayed(msg, 500);
1630 }
1631 @Override
1632 public void onMouseHoverAtBottom() {
1633 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1634 Message msg = mHandler.obtainMessage(MSG_REQUEST_TRANSIENT_BARS);
1635 msg.arg1 = MSG_REQUEST_TRANSIENT_BARS_ARG_NAVIGATION;
1636 mHandler.sendMessageDelayed(msg, 500);
1637 }
1638 @Override
1639 public void onMouseLeaveFromEdge() {
1640 mHandler.removeMessages(MSG_REQUEST_TRANSIENT_BARS);
1641 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04001642 });
John Spurlockf1a36642013-10-12 17:50:42 -04001643 mImmersiveModeConfirmation = new ImmersiveModeConfirmation(mContext);
Craig Mautner037aa8d2013-06-07 10:35:44 -07001644 mWindowManagerFuncs.registerPointerEventListener(mSystemGestures);
John Spurlock32beb2c2013-03-11 10:16:47 -04001645
Jeff Brownc2346132012-04-13 01:55:38 -07001646 mVibrator = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001647 mLongPressVibePattern = getLongIntArray(mContext.getResources(),
1648 com.android.internal.R.array.config_longPressVibePattern);
1649 mVirtualKeyVibePattern = getLongIntArray(mContext.getResources(),
1650 com.android.internal.R.array.config_virtualKeyVibePattern);
Amith Yamasanic33cb712010-02-10 15:21:49 -08001651 mKeyboardTapVibePattern = getLongIntArray(mContext.getResources(),
1652 com.android.internal.R.array.config_keyboardTapVibePattern);
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07001653 mClockTickVibePattern = getLongIntArray(mContext.getResources(),
1654 com.android.internal.R.array.config_clockTickVibePattern);
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07001655 mCalendarDateVibePattern = getLongIntArray(mContext.getResources(),
1656 com.android.internal.R.array.config_calendarDateVibePattern);
Dianne Hackbornb1a79802009-09-29 15:18:31 -07001657 mSafeModeDisabledVibePattern = getLongIntArray(mContext.getResources(),
1658 com.android.internal.R.array.config_safeModeDisabledVibePattern);
1659 mSafeModeEnabledVibePattern = getLongIntArray(mContext.getResources(),
1660 com.android.internal.R.array.config_safeModeEnabledVibePattern);
Mady Mellore8608912015-06-05 09:02:55 -07001661 mContextClickVibePattern = getLongIntArray(mContext.getResources(),
1662 com.android.internal.R.array.config_contextClickVibePattern);
Daniel Sandler40427442010-07-16 11:44:52 -04001663
Christopher Tatee90585f2012-03-05 18:56:25 -08001664 mScreenshotChordEnabled = mContext.getResources().getBoolean(
1665 com.android.internal.R.bool.config_enableScreenshotChord);
Jorim Jaggi406585a2015-12-21 10:58:56 +01001666 mForceWindowDrawsStatusBarBackground = mContext.getResources().getBoolean(
1667 R.bool.config_forceWindowDrawsStatusBarBackground);
Christopher Tatee90585f2012-03-05 18:56:25 -08001668
Justin Kohd378ad72013-04-01 12:18:26 -07001669 mGlobalKeyManager = new GlobalKeyManager(mContext);
1670
Joe Onoratoea495d42011-04-06 11:41:11 -07001671 // Controls rotation and the like.
1672 initializeHdmiState();
Dianne Hackborn40011092011-09-22 13:37:48 -07001673
1674 // Match current screen state.
Craig Mautnera631d492014-08-05 15:16:01 -07001675 if (!mPowerManager.isInteractive()) {
Jeff Brown416c49c2015-05-26 19:50:18 -07001676 startedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
1677 finishedGoingToSleep(WindowManagerPolicy.OFF_BECAUSE_OF_USER);
Dianne Hackborn40011092011-09-22 13:37:48 -07001678 }
Jorim Jaggi24bec7c2015-02-04 12:40:14 +01001679
1680 mWindowManagerInternal.registerAppTransitionListener(
1681 mStatusBarController.getAppTransitionListener());
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001682 }
1683
Jeff Brownf71343d2013-05-31 17:59:11 -07001684 /**
1685 * Read values from config.xml that may be overridden depending on
1686 * the configuration of the device.
1687 * eg. Disable long press on home goes to recents on sw600dp.
1688 */
1689 private void readConfigurationDependentBehaviors() {
Jaewan Kimc552b042016-01-18 16:08:45 +09001690 final Resources res = mContext.getResources();
1691
1692 mLongPressOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001693 com.android.internal.R.integer.config_longPressOnHomeBehavior);
1694 if (mLongPressOnHomeBehavior < LONG_PRESS_HOME_NOTHING ||
Jaewan Kim52632e22016-01-14 18:01:52 +09001695 mLongPressOnHomeBehavior > LAST_LONG_PRESS_HOME_BEHAVIOR) {
Jeff Brownf71343d2013-05-31 17:59:11 -07001696 mLongPressOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1697 }
1698
Jaewan Kimc552b042016-01-18 16:08:45 +09001699 mDoubleTapOnHomeBehavior = res.getInteger(
Jeff Brownf71343d2013-05-31 17:59:11 -07001700 com.android.internal.R.integer.config_doubleTapOnHomeBehavior);
1701 if (mDoubleTapOnHomeBehavior < DOUBLE_TAP_HOME_NOTHING ||
1702 mDoubleTapOnHomeBehavior > DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
1703 mDoubleTapOnHomeBehavior = LONG_PRESS_HOME_NOTHING;
1704 }
Jaewan Kim49117872016-01-19 17:24:08 +09001705
1706 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_NOTHING;
1707 if (mContext.getPackageManager().hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)) {
1708 mShortPressWindowBehavior = SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE;
1709 }
Jeff Brownf71343d2013-05-31 17:59:11 -07001710 }
1711
Craig Mautner0bf6ec92012-12-18 08:33:27 -08001712 @Override
Dianne Hackborndde331c2012-08-03 14:01:57 -07001713 public void setInitialDisplaySize(Display display, int width, int height, int density) {
Jeff Brownef981a42013-08-07 14:13:37 -07001714 // This method might be called before the policy has been fully initialized
1715 // or for other displays we don't care about.
1716 if (mContext == null || display.getDisplayId() != Display.DEFAULT_DISPLAY) {
1717 return;
Dianne Hackbornc652de82013-02-15 16:32:56 -08001718 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001719 mDisplay = display;
1720
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001721 final Resources res = mContext.getResources();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001722 int shortSize, longSize;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001723 if (width > height) {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001724 shortSize = height;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001725 longSize = width;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001726 mLandscapeRotation = Surface.ROTATION_0;
1727 mSeascapeRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001728 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001729 mPortraitRotation = Surface.ROTATION_90;
1730 mUpsideDownRotation = Surface.ROTATION_270;
1731 } else {
1732 mPortraitRotation = Surface.ROTATION_270;
1733 mUpsideDownRotation = Surface.ROTATION_90;
1734 }
1735 } else {
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001736 shortSize = width;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001737 longSize = height;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001738 mPortraitRotation = Surface.ROTATION_0;
1739 mUpsideDownRotation = Surface.ROTATION_180;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001740 if (res.getBoolean(com.android.internal.R.bool.config_reverseDefaultRotation)) {
Dianne Hackborn9d132642011-04-21 17:26:39 -07001741 mLandscapeRotation = Surface.ROTATION_270;
1742 mSeascapeRotation = Surface.ROTATION_90;
1743 } else {
1744 mLandscapeRotation = Surface.ROTATION_90;
1745 mSeascapeRotation = Surface.ROTATION_270;
1746 }
1747 }
Dianne Hackborn81e56d52011-05-26 00:55:58 -07001748
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001749 mStatusBarHeight =
1750 res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_height);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001751
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001752 // Height of the navigation bar when presented horizontally at bottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001753 mNavigationBarHeightForRotationDefault[mPortraitRotation] =
1754 mNavigationBarHeightForRotationDefault[mUpsideDownRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001755 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_height);
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001756 mNavigationBarHeightForRotationDefault[mLandscapeRotation] =
1757 mNavigationBarHeightForRotationDefault[mSeascapeRotation] = res.getDimensionPixelSize(
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001758 com.android.internal.R.dimen.navigation_bar_height_landscape);
Daniel Sandler9f65c4c2012-04-26 01:35:35 -04001759
1760 // Width of the navigation bar when presented vertically along one side
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001761 mNavigationBarWidthForRotationDefault[mPortraitRotation] =
1762 mNavigationBarWidthForRotationDefault[mUpsideDownRotation] =
1763 mNavigationBarWidthForRotationDefault[mLandscapeRotation] =
1764 mNavigationBarWidthForRotationDefault[mSeascapeRotation] =
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001765 res.getDimensionPixelSize(com.android.internal.R.dimen.navigation_bar_width);
Daniel Sandler4a066c52012-04-20 14:49:13 -04001766
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08001767 // Height of the navigation bar when presented horizontally at bottom
1768 mNavigationBarHeightForRotationInCarMode[mPortraitRotation] =
1769 mNavigationBarHeightForRotationInCarMode[mUpsideDownRotation] =
1770 res.getDimensionPixelSize(
1771 com.android.internal.R.dimen.navigation_bar_height_car_mode);
1772 mNavigationBarHeightForRotationInCarMode[mLandscapeRotation] =
1773 mNavigationBarHeightForRotationInCarMode[mSeascapeRotation] = res.getDimensionPixelSize(
1774 com.android.internal.R.dimen.navigation_bar_height_landscape_car_mode);
1775
1776 // Width of the navigation bar when presented vertically along one side
1777 mNavigationBarWidthForRotationInCarMode[mPortraitRotation] =
1778 mNavigationBarWidthForRotationInCarMode[mUpsideDownRotation] =
1779 mNavigationBarWidthForRotationInCarMode[mLandscapeRotation] =
1780 mNavigationBarWidthForRotationInCarMode[mSeascapeRotation] =
1781 res.getDimensionPixelSize(
1782 com.android.internal.R.dimen.navigation_bar_width_car_mode);
1783
Daniel Sandler4a066c52012-04-20 14:49:13 -04001784 // SystemUI (status bar) layout policy
Dianne Hackborndde331c2012-08-03 14:01:57 -07001785 int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / density;
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001786 int longSizeDp = longSize * DisplayMetrics.DENSITY_DEFAULT / density;
Daniel Sandler4a066c52012-04-20 14:49:13 -04001787
Devin Kimd7b12b42014-05-05 14:34:58 -07001788 // Allow the navigation bar to move on non-square small devices (phones).
1789 mNavigationBarCanMove = width != height && shortSizeDp < 600;
Daniel Sandler36412a72011-08-04 09:35:13 -04001790
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001791 mHasNavigationBar = res.getBoolean(com.android.internal.R.bool.config_showNavigationBar);
John Spurlock80f00c12013-06-13 11:10:51 -04001792 // Allow a system property to override this. Used by the emulator.
1793 // See also hasNavigationBar().
1794 String navBarOverride = SystemProperties.get("qemu.hw.mainkeys");
1795 if ("1".equals(navBarOverride)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07001796 mHasNavigationBar = false;
John Spurlock80f00c12013-06-13 11:10:51 -04001797 } else if ("0".equals(navBarOverride)) {
1798 mHasNavigationBar = true;
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04001799 }
1800
Jeff Brown27f1d672012-10-17 18:32:34 -07001801 // For demo purposes, allow the rotation of the HDMI display to be controlled.
1802 // By default, HDMI locks rotation to landscape.
Erik Gilling9a41ef82011-09-26 19:21:03 -07001803 if ("portrait".equals(SystemProperties.get("persist.demo.hdmirotation"))) {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001804 mDemoHdmiRotation = mPortraitRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001805 } else {
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001806 mDemoHdmiRotation = mLandscapeRotation;
Erik Gilling9a41ef82011-09-26 19:21:03 -07001807 }
Jeff Brownc82c89ed2013-04-17 17:18:15 -07001808 mDemoHdmiRotationLock = SystemProperties.getBoolean("persist.demo.hdmirotationlock", false);
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001809
Chong Zhangae6119ff2014-11-11 18:54:39 -08001810 // For demo purposes, allow the rotation of the remote display to be controlled.
1811 // By default, remote display locks rotation to landscape.
1812 if ("portrait".equals(SystemProperties.get("persist.demo.remoterotation"))) {
1813 mDemoRotation = mPortraitRotation;
1814 } else {
1815 mDemoRotation = mLandscapeRotation;
1816 }
1817 mDemoRotationLock = SystemProperties.getBoolean(
1818 "persist.demo.rotationlock", false);
1819
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001820 // Only force the default orientation if the screen is xlarge, at least 960dp x 720dp, per
1821 // http://developer.android.com/guide/practices/screens_support.html#range
1822 mForceDefaultOrientation = longSizeDp >= 960 && shortSizeDp >= 720 &&
1823 res.getBoolean(com.android.internal.R.bool.config_forceDefaultOrientation) &&
1824 // For debug purposes the next line turns this feature off with:
1825 // $ adb shell setprop config.override_forced_orient true
1826 // $ adb shell wm size reset
1827 !"true".equals(SystemProperties.get("config.override_forced_orient"));
1828 }
1829
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001830 /**
1831 * @return whether the navigation bar can be hidden, e.g. the device has a
1832 * navigation bar and touch exploration is not enabled
1833 */
1834 private boolean canHideNavigationBar() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04001835 return mHasNavigationBar;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07001836 }
1837
Craig Mautner46ac6fa2013-08-01 10:06:34 -07001838 @Override
1839 public boolean isDefaultOrientationForced() {
1840 return mForceDefaultOrientation;
Dianne Hackborn9d132642011-04-21 17:26:39 -07001841 }
1842
Dianne Hackbornc652de82013-02-15 16:32:56 -08001843 @Override
1844 public void setDisplayOverscan(Display display, int left, int top, int right, int bottom) {
1845 if (display.getDisplayId() == Display.DEFAULT_DISPLAY) {
1846 mOverscanLeft = left;
1847 mOverscanTop = top;
1848 mOverscanRight = right;
1849 mOverscanBottom = bottom;
1850 }
1851 }
1852
Dianne Hackbornc777e072010-02-12 13:07:59 -08001853 public void updateSettings() {
1854 ContentResolver resolver = mContext.getContentResolver();
1855 boolean updateRotation = false;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001856 synchronized (mLock) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001857 mEndcallBehavior = Settings.System.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001858 Settings.System.END_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001859 Settings.System.END_BUTTON_BEHAVIOR_DEFAULT,
1860 UserHandle.USER_CURRENT);
1861 mIncallPowerBehavior = Settings.Secure.getIntForUser(resolver,
David Brownbaf8d092010-03-08 21:52:59 -08001862 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR,
Christopher Tate5e08af02012-09-21 17:17:22 -07001863 Settings.Secure.INCALL_POWER_BUTTON_BEHAVIOR_DEFAULT,
1864 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001865
Jeff Browna20dda42014-05-27 20:57:24 -07001866 // Configure wake gesture.
1867 boolean wakeGestureEnabledSetting = Settings.Secure.getIntForUser(resolver,
1868 Settings.Secure.WAKE_GESTURE_ENABLED, 0,
1869 UserHandle.USER_CURRENT) != 0;
1870 if (mWakeGestureEnabledSetting != wakeGestureEnabledSetting) {
1871 mWakeGestureEnabledSetting = wakeGestureEnabledSetting;
1872 updateWakeGestureListenerLp();
1873 }
1874
Jeff Brown207673cd2012-06-05 17:47:11 -07001875 // Configure rotation lock.
Christopher Tate5e08af02012-09-21 17:17:22 -07001876 int userRotation = Settings.System.getIntForUser(resolver,
1877 Settings.System.USER_ROTATION, Surface.ROTATION_0,
1878 UserHandle.USER_CURRENT);
Jeff Brown207673cd2012-06-05 17:47:11 -07001879 if (mUserRotation != userRotation) {
1880 mUserRotation = userRotation;
1881 updateRotation = true;
1882 }
Christopher Tate5e08af02012-09-21 17:17:22 -07001883 int userRotationMode = Settings.System.getIntForUser(resolver,
1884 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
Jeff Brown207673cd2012-06-05 17:47:11 -07001885 WindowManagerPolicy.USER_ROTATION_FREE :
1886 WindowManagerPolicy.USER_ROTATION_LOCKED;
1887 if (mUserRotationMode != userRotationMode) {
1888 mUserRotationMode = userRotationMode;
1889 updateRotation = true;
Dianne Hackbornc777e072010-02-12 13:07:59 -08001890 updateOrientationListenerLp();
1891 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04001892
Dianne Hackbornc777e072010-02-12 13:07:59 -08001893 if (mSystemReady) {
Christopher Tate5e08af02012-09-21 17:17:22 -07001894 int pointerLocation = Settings.System.getIntForUser(resolver,
1895 Settings.System.POINTER_LOCATION, 0, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001896 if (mPointerLocationMode != pointerLocation) {
1897 mPointerLocationMode = pointerLocation;
Jeff Brown70825162012-03-28 17:27:48 -07001898 mHandler.sendEmptyMessage(pointerLocation != 0 ?
1899 MSG_ENABLE_POINTER_LOCATION : MSG_DISABLE_POINTER_LOCATION);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001900 }
1901 }
1902 // use screen off timeout setting as the timeout for the lockscreen
Christopher Tate5e08af02012-09-21 17:17:22 -07001903 mLockScreenTimeout = Settings.System.getIntForUser(resolver,
1904 Settings.System.SCREEN_OFF_TIMEOUT, 0, UserHandle.USER_CURRENT);
1905 String imId = Settings.Secure.getStringForUser(resolver,
1906 Settings.Secure.DEFAULT_INPUT_METHOD, UserHandle.USER_CURRENT);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001907 boolean hasSoftInput = imId != null && imId.length() > 0;
1908 if (mHasSoftInput != hasSoftInput) {
1909 mHasSoftInput = hasSoftInput;
1910 updateRotation = true;
1911 }
John Spurlockf1a36642013-10-12 17:50:42 -04001912 if (mImmersiveModeConfirmation != null) {
John Spurlock4355a532014-02-19 09:49:25 -05001913 mImmersiveModeConfirmation.loadSetting(mCurrentUserId);
John Spurlockd67ec252013-09-05 11:31:54 -04001914 }
tiger_huangcc6366d2015-06-29 17:17:30 +08001915 }
1916 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05001917 PolicyControl.reloadFromSetting(mContext);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001918 }
1919 if (updateRotation) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07001920 updateRotation(true);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001921 }
Jeff Brown70825162012-03-28 17:27:48 -07001922 }
1923
Jeff Browna20dda42014-05-27 20:57:24 -07001924 private void updateWakeGestureListenerLp() {
1925 if (shouldEnableWakeGestureLp()) {
1926 mWakeGestureListener.requestWakeUpTrigger();
1927 } else {
1928 mWakeGestureListener.cancelWakeUpTrigger();
1929 }
1930 }
1931
1932 private boolean shouldEnableWakeGestureLp() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07001933 return mWakeGestureEnabledSetting && !mAwake
Jeff Browna20dda42014-05-27 20:57:24 -07001934 && (!mLidControlsSleep || mLidState != LID_CLOSED)
1935 && mWakeGestureListener.isSupported();
1936 }
1937
Jeff Brown70825162012-03-28 17:27:48 -07001938 private void enablePointerLocation() {
1939 if (mPointerLocationView == null) {
1940 mPointerLocationView = new PointerLocationView(mContext);
1941 mPointerLocationView.setPrintCoords(false);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001942 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
1943 WindowManager.LayoutParams.MATCH_PARENT,
1944 WindowManager.LayoutParams.MATCH_PARENT);
Jeff Brown3b2b3542010-10-15 00:54:27 -07001945 lp.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07001946 lp.flags = WindowManager.LayoutParams.FLAG_FULLSCREEN
1947 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
1948 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
1949 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
Jeff Brown90fc9052012-10-01 14:44:24 -07001950 if (ActivityManager.isHighEndGfx()) {
1951 lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
1952 lp.privateFlags |=
1953 WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
1954 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001955 lp.format = PixelFormat.TRANSLUCENT;
1956 lp.setTitle("PointerLocation");
Dianne Hackborn5fd21692011-06-07 14:09:47 -07001957 WindowManager wm = (WindowManager)
Dianne Hackbornc777e072010-02-12 13:07:59 -08001958 mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Browncc4f7db2011-08-30 20:34:48 -07001959 lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_NO_INPUT_CHANNEL;
Jeff Brown70825162012-03-28 17:27:48 -07001960 wm.addView(mPointerLocationView, lp);
Michael Wrightc9c487e2013-11-07 18:55:09 -08001961 mWindowManagerFuncs.registerPointerEventListener(mPointerLocationView);
Dianne Hackbornc777e072010-02-12 13:07:59 -08001962 }
Dianne Hackbornc777e072010-02-12 13:07:59 -08001963 }
Jeff Brown70825162012-03-28 17:27:48 -07001964
1965 private void disablePointerLocation() {
Jeff Brown70825162012-03-28 17:27:48 -07001966 if (mPointerLocationView != null) {
Michael Wrightc9c487e2013-11-07 18:55:09 -08001967 mWindowManagerFuncs.unregisterPointerEventListener(mPointerLocationView);
1968 WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
Jeff Brown70825162012-03-28 17:27:48 -07001969 wm.removeView(mPointerLocationView);
1970 mPointerLocationView = null;
1971 }
1972 }
1973
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001974 private int readRotation(int resID) {
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001975 try {
1976 int rotation = mContext.getResources().getInteger(resID);
1977 switch (rotation) {
1978 case 0:
1979 return Surface.ROTATION_0;
1980 case 90:
1981 return Surface.ROTATION_90;
1982 case 180:
1983 return Surface.ROTATION_180;
1984 case 270:
1985 return Surface.ROTATION_270;
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001986 }
1987 } catch (Resources.NotFoundException e) {
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001988 // fall through
Mike Lockwood1753f7f2009-08-24 14:49:07 -07001989 }
Mike Lockwood2d1efbd2009-09-16 12:15:53 -04001990 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001991 }
1992
1993 /** {@inheritDoc} */
Craig Mautner88400d32012-09-30 12:35:45 -07001994 @Override
Dianne Hackbornc2293022013-02-06 23:14:49 -08001995 public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08001996 int type = attrs.type;
Dianne Hackbornc2293022013-02-06 23:14:49 -08001997
1998 outAppOp[0] = AppOpsManager.OP_NONE;
1999
Wale Ogunwale74bf0652015-01-12 10:24:36 -08002000 if (!((type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW)
2001 || (type >= FIRST_SUB_WINDOW && type <= LAST_SUB_WINDOW)
2002 || (type >= FIRST_SYSTEM_WINDOW && type <= LAST_SYSTEM_WINDOW))) {
2003 return WindowManagerGlobal.ADD_INVALID_TYPE;
2004 }
2005
2006 if (type < FIRST_SYSTEM_WINDOW || type > LAST_SYSTEM_WINDOW) {
2007 // Window manager will make sure these are okay.
Jeff Brown98365d72012-08-19 20:30:52 -07002008 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002009 }
2010 String permission = null;
2011 switch (type) {
2012 case TYPE_TOAST:
2013 // XXX right now the app process has complete control over
2014 // this... should introduce a token to let the system
2015 // monitor/control what they are doing.
Jason Monk1c7c3192014-06-26 12:52:18 -04002016 outAppOp[0] = AppOpsManager.OP_TOAST_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002017 break;
Daniel Sandler7d276c32012-01-30 14:33:52 -05002018 case TYPE_DREAM:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002019 case TYPE_INPUT_METHOD:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002020 case TYPE_WALLPAPER:
keunyounga446bf02013-06-21 19:07:57 -07002021 case TYPE_PRIVATE_PRESENTATION:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002022 case TYPE_VOICE_INTERACTION:
Svetoslav3a5c7212014-10-14 09:54:26 -07002023 case TYPE_ACCESSIBILITY_OVERLAY:
Jason Monk8f7f3182015-11-18 16:35:14 -05002024 case TYPE_QS_DIALOG:
Dianne Hackbornb7cd8b92009-08-08 20:53:03 -07002025 // The window manager will check these.
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002026 break;
2027 case TYPE_PHONE:
2028 case TYPE_PRIORITY_PHONE:
2029 case TYPE_SYSTEM_ALERT:
2030 case TYPE_SYSTEM_ERROR:
2031 case TYPE_SYSTEM_OVERLAY:
2032 permission = android.Manifest.permission.SYSTEM_ALERT_WINDOW;
Dianne Hackbornc2293022013-02-06 23:14:49 -08002033 outAppOp[0] = AppOpsManager.OP_SYSTEM_ALERT_WINDOW;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002034 break;
2035 default:
2036 permission = android.Manifest.permission.INTERNAL_SYSTEM_WINDOW;
2037 }
2038 if (permission != null) {
Svet Ganov9cea80cd2016-02-16 11:47:00 -08002039 if (android.Manifest.permission.SYSTEM_ALERT_WINDOW.equals(permission)) {
Billy Laucbe540f2015-06-25 01:51:44 +01002040 final int callingUid = Binder.getCallingUid();
Billy Lau060275f2015-07-15 22:29:19 +01002041 // system processes will be automatically allowed privilege to draw
Billy Laucbe540f2015-06-25 01:51:44 +01002042 if (callingUid == Process.SYSTEM_UID) {
2043 return WindowManagerGlobal.ADD_OKAY;
2044 }
2045
Billy Lau060275f2015-07-15 22:29:19 +01002046 // check if user has enabled this operation. SecurityException will be thrown if
2047 // this app has not been allowed by the user
Billy Laucbe540f2015-06-25 01:51:44 +01002048 final int mode = mAppOpsManager.checkOp(outAppOp[0], callingUid,
2049 attrs.packageName);
Billy Lau060275f2015-07-15 22:29:19 +01002050 switch (mode) {
2051 case AppOpsManager.MODE_ALLOWED:
2052 case AppOpsManager.MODE_IGNORED:
2053 // although we return ADD_OKAY for MODE_IGNORED, the added window will
2054 // actually be hidden in WindowManagerService
2055 return WindowManagerGlobal.ADD_OKAY;
2056 case AppOpsManager.MODE_ERRORED:
Billy Laucbe540f2015-06-25 01:51:44 +01002057 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
Billy Lau060275f2015-07-15 22:29:19 +01002058 default:
2059 // in the default mode, we will make a decision here based on
2060 // checkCallingPermission()
2061 if (mContext.checkCallingPermission(permission) !=
2062 PackageManager.PERMISSION_GRANTED) {
2063 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
2064 } else {
2065 return WindowManagerGlobal.ADD_OKAY;
2066 }
Billy Laucbe540f2015-06-25 01:51:44 +01002067 }
Billy Laucbe540f2015-06-25 01:51:44 +01002068 }
2069
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002070 if (mContext.checkCallingOrSelfPermission(permission)
2071 != PackageManager.PERMISSION_GRANTED) {
Jeff Brown98365d72012-08-19 20:30:52 -07002072 return WindowManagerGlobal.ADD_PERMISSION_DENIED;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002073 }
2074 }
Jeff Brown98365d72012-08-19 20:30:52 -07002075 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002076 }
Craig Mautner88400d32012-09-30 12:35:45 -07002077
2078 @Override
2079 public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {
2080
2081 // If this switch statement is modified, modify the comment in the declarations of
2082 // the type in {@link WindowManager.LayoutParams} as well.
2083 switch (attrs.type) {
2084 default:
2085 // These are the windows that by default are shown only to the user that created
2086 // them. If this needs to be overridden, set
2087 // {@link WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS} in
2088 // {@link WindowManager.LayoutParams}. Note that permission
2089 // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
2090 if ((attrs.privateFlags & PRIVATE_FLAG_SHOW_FOR_ALL_USERS) == 0) {
2091 return true;
2092 }
2093 break;
2094
2095 // These are the windows that by default are shown to all users. However, to
2096 // protect against spoofing, check permissions below.
2097 case TYPE_APPLICATION_STARTING:
2098 case TYPE_BOOT_PROGRESS:
2099 case TYPE_DISPLAY_OVERLAY:
Selim Cinekf83e8242015-05-19 18:08:14 -07002100 case TYPE_INPUT_CONSUMER:
Jim Miller5ecd8112013-01-09 18:50:26 -08002101 case TYPE_KEYGUARD_SCRIM:
Craig Mautner88400d32012-09-30 12:35:45 -07002102 case TYPE_KEYGUARD_DIALOG:
2103 case TYPE_MAGNIFICATION_OVERLAY:
2104 case TYPE_NAVIGATION_BAR:
2105 case TYPE_NAVIGATION_BAR_PANEL:
2106 case TYPE_PHONE:
2107 case TYPE_POINTER:
2108 case TYPE_PRIORITY_PHONE:
Craig Mautner88400d32012-09-30 12:35:45 -07002109 case TYPE_SEARCH_BAR:
2110 case TYPE_STATUS_BAR:
2111 case TYPE_STATUS_BAR_PANEL:
2112 case TYPE_STATUS_BAR_SUB_PANEL:
2113 case TYPE_SYSTEM_DIALOG:
Craig Mautner88400d32012-09-30 12:35:45 -07002114 case TYPE_VOLUME_OVERLAY:
keunyounga446bf02013-06-21 19:07:57 -07002115 case TYPE_PRIVATE_PRESENTATION:
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002116 case TYPE_DOCK_DIVIDER:
Craig Mautner88400d32012-09-30 12:35:45 -07002117 break;
2118 }
2119
2120 // Check if third party app has set window to system window type.
2121 return mContext.checkCallingOrSelfPermission(
2122 android.Manifest.permission.INTERNAL_SYSTEM_WINDOW)
2123 != PackageManager.PERMISSION_GRANTED;
2124 }
2125
Craig Mautner967212c2013-04-13 21:10:58 -07002126 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002127 public void adjustWindowParamsLw(WindowManager.LayoutParams attrs) {
2128 switch (attrs.type) {
2129 case TYPE_SYSTEM_OVERLAY:
Jeff Brown3b2b3542010-10-15 00:54:27 -07002130 case TYPE_SECURE_SYSTEM_OVERLAY:
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002131 // These types of windows can't receive input events.
2132 attrs.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
2133 | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
Jeff Brownbfcb60a2011-09-08 18:51:14 -07002134 attrs.flags &= ~WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002135 break;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002136 case TYPE_STATUS_BAR:
2137
2138 // If the Keyguard is in a hidden state (occluded by another window), we force to
2139 // remove the wallpaper and keyguard flag so that any change in-flight after setting
2140 // the keyguard as occluded wouldn't set these flags again.
2141 // See {@link #processKeyguardSetHiddenResultLw}.
2142 if (mKeyguardHidden) {
2143 attrs.flags &= ~WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
2144 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2145 }
2146 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002147 }
Adrian Roos38502112014-04-09 21:04:11 +02002148
2149 if (attrs.type != TYPE_STATUS_BAR) {
2150 // The status bar is the only window allowed to exhibit keyguard behavior.
2151 attrs.privateFlags &= ~WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
2152 }
Adrian Roosea562512014-05-05 13:33:03 +02002153
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002154 if (ActivityManager.isHighEndGfx()) {
2155 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0) {
2156 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
2157 }
2158 if ((attrs.flags & FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) != 0
Jorim Jaggi406585a2015-12-21 10:58:56 +01002159 || (mForceWindowDrawsStatusBarBackground
2160 && attrs.height == MATCH_PARENT && attrs.width == MATCH_PARENT)) {
Jorim Jaggi4fa78922015-11-30 17:13:56 -08002161 attrs.subtreeSystemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
2162 }
Adrian Roosea562512014-05-05 13:33:03 +02002163 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002164 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002165
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002166 void readLidState() {
Jeff Brown2e7760e2012-04-11 15:14:55 -07002167 mLidState = mWindowManagerFuncs.getLidState();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002168 }
RoboErik8a2cfc32014-05-16 11:19:38 -07002169
Michael Wright3818c922014-09-02 13:59:07 -07002170 private void readCameraLensCoverState() {
2171 mCameraLensCoverState = mWindowManagerFuncs.getCameraLensCoverState();
2172 }
2173
Jeff Browndaa37532012-05-01 15:54:03 -07002174 private boolean isHidden(int accessibilityMode) {
2175 switch (accessibilityMode) {
2176 case 1:
2177 return mLidState == LID_CLOSED;
2178 case 2:
2179 return mLidState == LID_OPEN;
2180 default:
2181 return false;
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002182 }
Dianne Hackborn2862fff2009-09-15 22:56:29 -07002183 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002184
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002185 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002186 @Override
Jeff Browndaa37532012-05-01 15:54:03 -07002187 public void adjustConfigurationLw(Configuration config, int keyboardPresence,
2188 int navigationPresence) {
2189 mHaveBuiltInKeyboard = (keyboardPresence & PRESENCE_INTERNAL) != 0;
2190
Jeff Brownf71343d2013-05-31 17:59:11 -07002191 readConfigurationDependentBehaviors();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002192 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07002193 applyLidSwitchState();
Jeff Brownd04a88c2011-01-16 14:05:47 -08002194
Jeff Browndaa37532012-05-01 15:54:03 -07002195 if (config.keyboard == Configuration.KEYBOARD_NOKEYS
2196 || (keyboardPresence == PRESENCE_INTERNAL
2197 && isHidden(mLidKeyboardAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002198 config.hardKeyboardHidden = Configuration.HARDKEYBOARDHIDDEN_YES;
Jeff Browndaa37532012-05-01 15:54:03 -07002199 if (!mHasSoftInput) {
2200 config.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
2201 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002202 }
2203
Jeff Browndaa37532012-05-01 15:54:03 -07002204 if (config.navigation == Configuration.NAVIGATION_NONAV
2205 || (navigationPresence == PRESENCE_INTERNAL
2206 && isHidden(mLidNavigationAccessibility))) {
Jeff Brownd04a88c2011-01-16 14:05:47 -08002207 config.navigationHidden = Configuration.NAVIGATIONHIDDEN_YES;
Jeff Brownd04a88c2011-01-16 14:05:47 -08002208 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002209 }
Jeff Brownd04a88c2011-01-16 14:05:47 -08002210
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002211 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07002212 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002213 public int windowTypeToLayerLw(int type) {
2214 if (type >= FIRST_APPLICATION_WINDOW && type <= LAST_APPLICATION_WINDOW) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002215 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002216 }
2217 switch (type) {
keunyounga446bf02013-06-21 19:07:57 -07002218 case TYPE_PRIVATE_PRESENTATION:
2219 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002220 case TYPE_WALLPAPER:
2221 // wallpaper is at the bottom, though the window manager may move it.
2222 return 2;
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002223 case TYPE_DOCK_DIVIDER:
2224 return 2;
Jason Monk8f7f3182015-11-18 16:35:14 -05002225 case TYPE_QS_DIALOG:
2226 return 2;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002227 case TYPE_PHONE:
2228 return 3;
2229 case TYPE_SEARCH_BAR:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002230 case TYPE_VOICE_INTERACTION_STARTING:
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002231 return 4;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002232 case TYPE_VOICE_INTERACTION:
2233 // voice interaction layer is almost immediately above apps.
2234 return 5;
Selim Cinekf83e8242015-05-19 18:08:14 -07002235 case TYPE_INPUT_CONSUMER:
Dianne Hackborne30e02f2014-05-27 18:24:45 -07002236 return 6;
Selim Cinekf83e8242015-05-19 18:08:14 -07002237 case TYPE_SYSTEM_DIALOG:
2238 return 7;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002239 case TYPE_TOAST:
2240 // toasts and the plugged-in battery thing
Selim Cinekf83e8242015-05-19 18:08:14 -07002241 return 8;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002242 case TYPE_PRIORITY_PHONE:
2243 // SIM errors and unlock. Not sure if this really should be in a high layer.
Selim Cinekf83e8242015-05-19 18:08:14 -07002244 return 9;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002245 case TYPE_DREAM:
2246 // used for Dreams (screensavers with TYPE_DREAM windows)
Selim Cinekf83e8242015-05-19 18:08:14 -07002247 return 10;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002248 case TYPE_SYSTEM_ALERT:
2249 // like the ANR / app crashed dialogs
Selim Cinekf83e8242015-05-19 18:08:14 -07002250 return 11;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002251 case TYPE_INPUT_METHOD:
2252 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002253 return 12;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002254 case TYPE_INPUT_METHOD_DIALOG:
2255 // on-screen keyboards and other such input method user interfaces go here.
Selim Cinekf83e8242015-05-19 18:08:14 -07002256 return 13;
Jim Miller5ecd8112013-01-09 18:50:26 -08002257 case TYPE_KEYGUARD_SCRIM:
2258 // the safety window that shows behind keyguard while keyguard is starting
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002259 return 14;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002260 case TYPE_STATUS_BAR_SUB_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002261 return 15;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002262 case TYPE_STATUS_BAR:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002263 return 16;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002264 case TYPE_STATUS_BAR_PANEL:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002265 return 17;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002266 case TYPE_KEYGUARD_DIALOG:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002267 return 18;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002268 case TYPE_VOLUME_OVERLAY:
2269 // the on-screen volume indicator and controller shown when the user
2270 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002271 return 19;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002272 case TYPE_SYSTEM_OVERLAY:
2273 // the on-screen volume indicator and controller shown when the user
2274 // changes the device volume
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002275 return 20;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002276 case TYPE_NAVIGATION_BAR:
2277 // the navigation bar, if available, shows atop most things
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002278 return 21;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002279 case TYPE_NAVIGATION_BAR_PANEL:
2280 // some panels (e.g. search) need to show on top of the navigation bar
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002281 return 22;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002282 case TYPE_SYSTEM_ERROR:
2283 // system-level error dialogs
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002284 return 23;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002285 case TYPE_MAGNIFICATION_OVERLAY:
2286 // used to highlight the magnified portion of a display
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002287 return 24;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002288 case TYPE_DISPLAY_OVERLAY:
2289 // used to simulate secondary display devices
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002290 return 25;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002291 case TYPE_DRAG:
2292 // the drag layer: input for drag-and-drop is associated with this window,
2293 // which sits above all other focusable windows
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002294 return 26;
Svetoslav3a5c7212014-10-14 09:54:26 -07002295 case TYPE_ACCESSIBILITY_OVERLAY:
2296 // overlay put by accessibility services to intercept user interaction
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002297 return 27;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002298 case TYPE_SECURE_SYSTEM_OVERLAY:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002299 return 28;
Filip Gruszczynski466f3212015-09-21 17:57:57 -07002300 case TYPE_BOOT_PROGRESS:
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002301 return 29;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002302 case TYPE_POINTER:
2303 // the (mouse) pointer layer
Filip Gruszczynskie95b0ae2015-09-30 10:55:33 -07002304 return 30;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002305 }
2306 Log.e(TAG, "Unknown window type: " + type);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002307 return 2;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002308 }
2309
2310 /** {@inheritDoc} */
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002311 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002312 public int subWindowTypeToLayerLw(int type) {
2313 switch (type) {
2314 case TYPE_APPLICATION_PANEL:
2315 case TYPE_APPLICATION_ATTACHED_DIALOG:
2316 return APPLICATION_PANEL_SUBLAYER;
2317 case TYPE_APPLICATION_MEDIA:
2318 return APPLICATION_MEDIA_SUBLAYER;
Dianne Hackborn5cb8d792009-05-21 17:34:15 -07002319 case TYPE_APPLICATION_MEDIA_OVERLAY:
2320 return APPLICATION_MEDIA_OVERLAY_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002321 case TYPE_APPLICATION_SUB_PANEL:
2322 return APPLICATION_SUB_PANEL_SUBLAYER;
Wale Ogunwale0a4dc222015-04-14 12:58:42 -07002323 case TYPE_APPLICATION_ABOVE_SUB_PANEL:
2324 return APPLICATION_ABOVE_SUB_PANEL_SUBLAYER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002325 }
2326 Log.e(TAG, "Unknown sub-window type: " + type);
2327 return 0;
2328 }
2329
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002330 @Override
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002331 public int getMaxWallpaperLayer() {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002332 return windowTypeToLayerLw(TYPE_STATUS_BAR);
Dianne Hackbornabe0da02009-09-18 01:55:39 -07002333 }
2334
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002335 private int getNavigationBarWidth(int rotation, int uiMode) {
2336 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2337 return mNavigationBarWidthForRotationInCarMode[rotation];
2338 } else {
2339 return mNavigationBarWidthForRotationDefault[rotation];
2340 }
2341 }
2342
Craig Mautner46ac6fa2013-08-01 10:06:34 -07002343 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002344 public int getNonDecorDisplayWidth(int fullWidth, int fullHeight, int rotation,
2345 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002346 if (mHasNavigationBar) {
2347 // For a basic navigation bar, when we are in landscape mode we place
2348 // the navigation bar to the side.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002349 if (mNavigationBarCanMove && fullWidth > fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002350 return fullWidth - getNavigationBarWidth(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002351 }
Dianne Hackborn1f903c32011-09-13 19:18:06 -07002352 }
2353 return fullWidth;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002354 }
2355
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002356 private int getNavigationBarHeight(int rotation, int uiMode) {
2357 if ((uiMode & UI_MODE_TYPE_MASK) == UI_MODE_TYPE_CAR) {
2358 return mNavigationBarHeightForRotationInCarMode[rotation];
2359 } else {
2360 return mNavigationBarHeightForRotationDefault[rotation];
2361 }
2362 }
2363
Jose Lima9546b202014-07-02 17:21:51 -07002364 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002365 public int getNonDecorDisplayHeight(int fullWidth, int fullHeight, int rotation,
2366 int uiMode) {
Dianne Hackborn077ee852012-04-09 16:27:07 -07002367 if (mHasNavigationBar) {
2368 // For a basic navigation bar, when we are in portrait mode we place
2369 // the navigation bar to the bottom.
Daniel Sandler4a066c52012-04-20 14:49:13 -04002370 if (!mNavigationBarCanMove || fullWidth < fullHeight) {
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002371 return fullHeight - getNavigationBarHeight(rotation, uiMode);
Dianne Hackborn077ee852012-04-09 16:27:07 -07002372 }
2373 }
2374 return fullHeight;
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002375 }
2376
Jose Lima9546b202014-07-02 17:21:51 -07002377 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002378 public int getConfigDisplayWidth(int fullWidth, int fullHeight, int rotation, int uiMode) {
2379 return getNonDecorDisplayWidth(fullWidth, fullHeight, rotation, uiMode);
Dianne Hackborn69cb8752011-05-19 18:13:32 -07002380 }
2381
Jose Lima9546b202014-07-02 17:21:51 -07002382 @Override
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002383 public int getConfigDisplayHeight(int fullWidth, int fullHeight, int rotation, int uiMode) {
John Spurlock80f00c12013-06-13 11:10:51 -04002384 // There is a separate status bar at the top of the display. We don't count that as part
2385 // of the fixed decor, since it can hide; however, for purposes of configurations,
Dianne Hackborn077ee852012-04-09 16:27:07 -07002386 // we do want to exclude it since applications can't generally use that part
2387 // of the screen.
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08002388 return getNonDecorDisplayHeight(
2389 fullWidth, fullHeight, rotation, uiMode) - mStatusBarHeight;
Dianne Hackborne2515ee2011-04-27 18:52:56 -04002390 }
2391
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002392 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07002393 public boolean isForceHiding(WindowManager.LayoutParams attrs) {
2394 return (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 ||
Jim Millerab954542014-10-10 18:21:49 -07002395 (isKeyguardHostWindow(attrs) &&
2396 (mKeyguardDelegate != null && mKeyguardDelegate.isShowing())) ||
Adrian Roos69e510d2014-07-13 14:57:59 +02002397 (attrs.type == TYPE_KEYGUARD_SCRIM);
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002398 }
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002399
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002400 @Override
Jorim Jaggi0d674622014-05-21 01:34:15 +02002401 public boolean isKeyguardHostWindow(WindowManager.LayoutParams attrs) {
2402 return attrs.type == TYPE_STATUS_BAR;
2403 }
2404
2405 @Override
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002406 public boolean canBeForceHidden(WindowState win, WindowManager.LayoutParams attrs) {
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002407 switch (attrs.type) {
2408 case TYPE_STATUS_BAR:
2409 case TYPE_NAVIGATION_BAR:
2410 case TYPE_WALLPAPER:
2411 case TYPE_DREAM:
Jim Miller5ecd8112013-01-09 18:50:26 -08002412 case TYPE_KEYGUARD_SCRIM:
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002413 return false;
2414 default:
Adrian Roos461829d2015-06-03 14:41:18 -07002415 // Hide only windows below the keyguard host window.
2416 return windowTypeToLayerLw(win.getBaseType())
2417 < windowTypeToLayerLw(TYPE_STATUS_BAR);
Craig Mautnera3f4bf52012-10-10 20:37:48 -07002418 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002419 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002420
Craig Mautner7d7808f2014-09-11 18:02:38 -07002421 @Override
2422 public WindowState getWinShowWhenLockedLw() {
2423 return mWinShowWhenLocked;
2424 }
2425
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002426 /** {@inheritDoc} */
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002427 @Override
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002428 public View addStartingWindow(IBinder appToken, String packageName, int theme,
2429 CompatibilityInfo compatInfo, CharSequence nonLocalizedLabel, int labelRes,
Adam Powell04fe6eb2013-05-31 14:39:48 -07002430 int icon, int logo, int windowFlags) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002431 if (!SHOW_STARTING_ANIMATIONS) {
2432 return null;
2433 }
2434 if (packageName == null) {
2435 return null;
2436 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002437
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002438 WindowManager wm = null;
2439 View view = null;
2440
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002441 try {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002442 Context context = mContext;
Craig Mautner6fbda632012-07-03 09:26:39 -07002443 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow " + packageName
2444 + ": nonLocalizedLabel=" + nonLocalizedLabel + " theme="
2445 + Integer.toHexString(theme));
Dianne Hackborn247fe742011-01-08 17:25:57 -08002446 if (theme != context.getThemeResId() || labelRes != 0) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002447 try {
2448 context = context.createPackageContext(packageName, 0);
Dianne Hackborn247fe742011-01-08 17:25:57 -08002449 context.setTheme(theme);
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002450 } catch (PackageManager.NameNotFoundException e) {
2451 // Ignore
2452 }
2453 }
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002454
Jorim Jaggia16cc152015-06-01 16:55:05 -07002455 PhoneWindow win = new PhoneWindow(context);
2456 win.setIsStartingWindow(true);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002457
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002458 Resources r = context.getResources();
2459 win.setTitle(r.getText(labelRes, nonLocalizedLabel));
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002460
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002461 win.setType(
2462 WindowManager.LayoutParams.TYPE_APPLICATION_STARTING);
Adrian Roos602c68e2015-04-24 16:03:47 -07002463
2464 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
2465 // Assumes it's safe to show starting windows of launched apps while
2466 // the keyguard is being hidden. This is okay because starting windows never show
2467 // secret information.
2468 if (mKeyguardHidden) {
2469 windowFlags |= FLAG_SHOW_WHEN_LOCKED;
2470 }
2471 }
2472
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002473 // Force the window flags: this is a fake window, so it is not really
2474 // touchable or focusable by the user. We also add in the ALT_FOCUSABLE_IM
2475 // flag because we do know that the next window will take input
2476 // focus, so we want to get the IME window up on top of us right away.
2477 win.setFlags(
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002478 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002479 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2480 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2481 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
Dianne Hackborn7eec10e2010-11-12 18:03:47 -08002482 windowFlags|
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002483 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE|
2484 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
2485 WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002486
Adam Powell04fe6eb2013-05-31 14:39:48 -07002487 win.setDefaultIcon(icon);
2488 win.setDefaultLogo(logo);
2489
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002490 win.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
Dianne Hackborn2f0b1752011-05-31 17:59:49 -07002491 WindowManager.LayoutParams.MATCH_PARENT);
Craig Mautner8e4df6c2012-05-23 16:57:23 -07002492
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002493 final WindowManager.LayoutParams params = win.getAttributes();
2494 params.token = appToken;
2495 params.packageName = packageName;
2496 params.windowAnimations = win.getWindowStyle().getResourceId(
2497 com.android.internal.R.styleable.Window_windowAnimationStyle, 0);
John Reck61375a82014-09-18 19:27:48 +00002498 params.privateFlags |=
2499 WindowManager.LayoutParams.PRIVATE_FLAG_FAKE_HARDWARE_ACCELERATED;
Craig Mautner88400d32012-09-30 12:35:45 -07002500 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
Adam Lesinski95c42972013-10-02 10:13:27 -07002501
2502 if (!compatInfo.supportsScreen()) {
2503 params.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_COMPATIBLE_WINDOW;
2504 }
2505
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002506 params.setTitle("Starting " + packageName);
2507
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002508 wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
2509 view = win.getDecorView();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002510
Craig Mautner6fbda632012-07-03 09:26:39 -07002511 if (DEBUG_STARTING_WINDOW) Slog.d(
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002512 TAG, "Adding starting window for " + packageName
2513 + " / " + appToken + ": "
2514 + (view.getParent() != null ? view : null));
2515
2516 wm.addView(view, params);
2517
2518 // Only return the view if it was successfully added to the
2519 // window manager... which we can tell by it having a parent.
2520 return view.getParent() != null ? view : null;
Jeff Brown98365d72012-08-19 20:30:52 -07002521 } catch (WindowManager.BadTokenException e) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002522 // ignore
Craig Mautner42bf39e2014-02-21 16:46:22 -08002523 Log.w(TAG, appToken + " already running, starting window not displayed. " +
2524 e.getMessage());
Dianne Hackborn867ab6472010-04-29 13:28:56 -07002525 } catch (RuntimeException e) {
2526 // don't crash if something else bad happens, for example a
2527 // failure loading resources because we are loading from an app
2528 // on external storage that has been unmounted.
2529 Log.w(TAG, appToken + " failed creating starting window", e);
Mathias Jeppssond1443e92012-08-24 15:25:32 +02002530 } finally {
2531 if (view != null && view.getParent() == null) {
2532 Log.w(TAG, "view not successfully added to wm, removing view");
2533 wm.removeViewImmediate(view);
2534 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002535 }
2536
2537 return null;
2538 }
2539
2540 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002541 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002542 public void removeStartingWindow(IBinder appToken, View window) {
Craig Mautner276a6eb2014-11-04 15:32:57 -08002543 if (DEBUG_STARTING_WINDOW) Slog.v(TAG, "Removing starting window for " + appToken + ": "
2544 + window + " Callers=" + Debug.getCallers(4));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002545
2546 if (window != null) {
Dianne Hackborn5fd21692011-06-07 14:09:47 -07002547 WindowManager wm = (WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002548 wm.removeView(window);
2549 }
2550 }
2551
2552 /**
2553 * Preflight adding a window to the system.
RoboErik8a2cfc32014-05-16 11:19:38 -07002554 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002555 * Currently enforces that three window types are singletons:
2556 * <ul>
2557 * <li>STATUS_BAR_TYPE</li>
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002558 * <li>KEYGUARD_TYPE</li>
2559 * </ul>
RoboErik8a2cfc32014-05-16 11:19:38 -07002560 *
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002561 * @param win The window to be added
2562 * @param attrs Information about the window to be added
RoboErik8a2cfc32014-05-16 11:19:38 -07002563 *
Jeff Brown98365d72012-08-19 20:30:52 -07002564 * @return If ok, WindowManagerImpl.ADD_OKAY. If too many singletons,
2565 * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002566 */
Jose Lima9546b202014-07-02 17:21:51 -07002567 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002568 public int prepareAddWindowLw(WindowState win, WindowManager.LayoutParams attrs) {
2569 switch (attrs.type) {
2570 case TYPE_STATUS_BAR:
Joe Onorato8bc6c512010-06-04 16:21:12 -04002571 mContext.enforceCallingOrSelfPermission(
2572 android.Manifest.permission.STATUS_BAR_SERVICE,
2573 "PhoneWindowManager");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002574 if (mStatusBar != null) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002575 if (mStatusBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002576 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002577 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002578 }
2579 mStatusBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002580 mStatusBarController.setWindow(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002581 break;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002582 case TYPE_NAVIGATION_BAR:
2583 mContext.enforceCallingOrSelfPermission(
2584 android.Manifest.permission.STATUS_BAR_SERVICE,
2585 "PhoneWindowManager");
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002586 if (mNavigationBar != null) {
2587 if (mNavigationBar.isAlive()) {
Jeff Brown98365d72012-08-19 20:30:52 -07002588 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002589 }
2590 }
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002591 mNavigationBar = win;
John Spurlock27735a42013-08-14 17:57:38 -04002592 mNavigationBarController.setWindow(win);
Craig Mautnereda67292013-04-28 13:50:14 -07002593 if (DEBUG_LAYOUT) Slog.i(TAG, "NAVIGATION BAR: " + mNavigationBar);
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002594 break;
Jim Millere898ac52012-04-06 17:10:57 -07002595 case TYPE_NAVIGATION_BAR_PANEL:
Dianne Hackborn08743722009-12-21 12:16:51 -08002596 case TYPE_STATUS_BAR_PANEL:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002597 case TYPE_STATUS_BAR_SUB_PANEL:
Jorim Jaggi225d3b52015-04-01 11:18:57 -07002598 case TYPE_VOICE_INTERACTION_STARTING:
Joe Onorato29fc2c92010-11-24 10:26:50 -08002599 mContext.enforceCallingOrSelfPermission(
2600 android.Manifest.permission.STATUS_BAR_SERVICE,
2601 "PhoneWindowManager");
Joe Onorato29fc2c92010-11-24 10:26:50 -08002602 break;
Jim Miller5ecd8112013-01-09 18:50:26 -08002603 case TYPE_KEYGUARD_SCRIM:
Jim Miller25190572013-02-28 17:36:24 -08002604 if (mKeyguardScrim != null) {
2605 return WindowManagerGlobal.ADD_MULTIPLE_SINGLETON;
2606 }
Jim Miller5ecd8112013-01-09 18:50:26 -08002607 mKeyguardScrim = win;
2608 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002609 }
Jeff Brown98365d72012-08-19 20:30:52 -07002610 return WindowManagerGlobal.ADD_OKAY;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002611 }
2612
2613 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07002614 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002615 public void removeWindowLw(WindowState win) {
2616 if (mStatusBar == win) {
2617 mStatusBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002618 mStatusBarController.setWindow(null);
Jim Millerc0b676d2013-03-22 16:11:08 -07002619 mKeyguardDelegate.showScrim();
Jim Miller5ecd8112013-01-09 18:50:26 -08002620 } else if (mKeyguardScrim == win) {
2621 Log.v(TAG, "Removing keyguard scrim");
2622 mKeyguardScrim = null;
2623 } if (mNavigationBar == win) {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04002624 mNavigationBar = null;
John Spurlock27735a42013-08-14 17:57:38 -04002625 mNavigationBarController.setWindow(null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002626 }
2627 }
2628
2629 static final boolean PRINT_ANIM = false;
RoboErik8a2cfc32014-05-16 11:19:38 -07002630
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002631 /** {@inheritDoc} */
Craig Mautner4b71aa12012-12-27 17:20:01 -08002632 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002633 public int selectAnimationLw(WindowState win, int transit) {
2634 if (PRINT_ANIM) Log.i(TAG, "selectAnimation in " + win
2635 + ": transit=" + transit);
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002636 if (win == mStatusBar) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002637 boolean isKeyguard = (win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002638 if (transit == TRANSIT_EXIT
2639 || transit == TRANSIT_HIDE) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002640 return isKeyguard ? -1 : R.anim.dock_top_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002641 } else if (transit == TRANSIT_ENTER
2642 || transit == TRANSIT_SHOW) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002643 return isKeyguard ? -1 : R.anim.dock_top_enter;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002644 }
2645 } else if (win == mNavigationBar) {
Jorim Jaggi0d210f62015-07-10 14:24:44 -07002646 if (win.getAttrs().windowAnimations != 0) {
2647 return 0;
2648 }
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002649 // This can be on either the bottom or the right.
2650 if (mNavigationBarOnBottom) {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002651 if (transit == TRANSIT_EXIT
2652 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002653 return R.anim.dock_bottom_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002654 } else if (transit == TRANSIT_ENTER
2655 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002656 return R.anim.dock_bottom_enter;
2657 }
2658 } else {
Craig Mautner4b71aa12012-12-27 17:20:01 -08002659 if (transit == TRANSIT_EXIT
2660 || transit == TRANSIT_HIDE) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002661 return R.anim.dock_right_exit;
Craig Mautner4b71aa12012-12-27 17:20:01 -08002662 } else if (transit == TRANSIT_ENTER
2663 || transit == TRANSIT_SHOW) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07002664 return R.anim.dock_right_enter;
2665 }
2666 }
Filip Gruszczynski57f76f12015-11-04 16:10:54 -08002667 } else if (win.getAttrs().type == TYPE_DOCK_DIVIDER) {
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002668 return selectDockedDividerAnimationLw(win, transit);
Craig Mautner4b71aa12012-12-27 17:20:01 -08002669 }
2670
2671 if (transit == TRANSIT_PREVIEW_DONE) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002672 if (win.hasAppShownWindows()) {
2673 if (PRINT_ANIM) Log.i(TAG, "**** STARTING EXIT");
2674 return com.android.internal.R.anim.app_starting_exit;
2675 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07002676 } else if (win.getAttrs().type == TYPE_DREAM && mDreamingLockscreen
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07002677 && transit == TRANSIT_ENTER) {
2678 // Special case: we are animating in a dream, while the keyguard
2679 // is shown. We don't want an animation on the dream, because
2680 // we need it shown immediately with the keyguard animating away
2681 // to reveal it.
2682 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002683 }
2684
2685 return 0;
2686 }
2687
Jorim Jaggi81ba11e2016-02-03 22:04:22 -08002688 private int selectDockedDividerAnimationLw(WindowState win, int transit) {
2689 int insets = mWindowManagerFuncs.getDockedDividerInsetsLw();
2690
2691 // If the divider is behind the navigation bar, don't animate.
2692 if (mNavigationBar != null
2693 && (win.getFrameLw().top + insets >= mNavigationBar.getFrameLw().top
2694 || win.getFrameLw().left + insets >= mNavigationBar.getFrameLw().left)) {
2695 return 0;
2696 }
2697 if (transit == TRANSIT_ENTER || transit == TRANSIT_SHOW) {
2698 return R.anim.fade_in;
2699 } else if (transit == TRANSIT_EXIT) {
2700 return R.anim.fade_out;
2701 } else {
2702 return 0;
2703 }
2704 }
2705
Craig Mautner3c174372013-02-21 17:54:37 -08002706 @Override
2707 public void selectRotationAnimationLw(int anim[]) {
2708 if (PRINT_ANIM) Slog.i(TAG, "selectRotationAnimation mTopFullscreen="
2709 + mTopFullscreenOpaqueWindowState + " rotationAnimation="
2710 + (mTopFullscreenOpaqueWindowState == null ?
2711 "0" : mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation));
2712 if (mTopFullscreenOpaqueWindowState != null && mTopIsFullscreen) {
2713 switch (mTopFullscreenOpaqueWindowState.getAttrs().rotationAnimation) {
2714 case ROTATION_ANIMATION_CROSSFADE:
2715 anim[0] = R.anim.rotation_animation_xfade_exit;
2716 anim[1] = R.anim.rotation_animation_enter;
2717 break;
2718 case ROTATION_ANIMATION_JUMPCUT:
2719 anim[0] = R.anim.rotation_animation_jump_exit;
2720 anim[1] = R.anim.rotation_animation_enter;
2721 break;
2722 case ROTATION_ANIMATION_ROTATE:
2723 default:
2724 anim[0] = anim[1] = 0;
2725 break;
2726 }
2727 } else {
2728 anim[0] = anim[1] = 0;
2729 }
2730 }
2731
2732 @Override
2733 public boolean validateRotationAnimationLw(int exitAnimId, int enterAnimId,
2734 boolean forceDefault) {
2735 switch (exitAnimId) {
2736 case R.anim.rotation_animation_xfade_exit:
2737 case R.anim.rotation_animation_jump_exit:
2738 // These are the only cases that matter.
2739 if (forceDefault) {
2740 return false;
2741 }
2742 int anim[] = new int[2];
2743 selectRotationAnimationLw(anim);
2744 return (exitAnimId == anim[0] && enterAnimId == anim[1]);
2745 default:
2746 return true;
2747 }
2748 }
2749
2750 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002751 public Animation createForceHideEnterAnimation(boolean onWallpaper,
2752 boolean goingToNotificationShade) {
2753 if (goingToNotificationShade) {
2754 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_behind_enter_fade_in);
Craig Mautnerb8340802014-11-04 15:32:57 -08002755 }
Craig Mautner276a6eb2014-11-04 15:32:57 -08002756
2757 AnimationSet set = (AnimationSet) AnimationUtils.loadAnimation(mContext, onWallpaper ?
2758 R.anim.lock_screen_behind_enter_wallpaper :
2759 R.anim.lock_screen_behind_enter);
2760
2761 // TODO: Use XML interpolators when we have log interpolators available in XML.
2762 final List<Animation> animations = set.getAnimations();
2763 for (int i = animations.size() - 1; i >= 0; --i) {
2764 animations.get(i).setInterpolator(mLogDecelerateInterpolator);
2765 }
2766
2767 return set;
Jorim Jaggi76a16232014-08-08 17:00:47 +02002768 }
2769
2770
2771 @Override
Jorim Jaggi84a3e7a2014-08-13 17:58:58 +02002772 public Animation createForceHideWallpaperExitAnimation(boolean goingToNotificationShade) {
2773 if (goingToNotificationShade) {
2774 return null;
2775 } else {
2776 return AnimationUtils.loadAnimation(mContext, R.anim.lock_screen_wallpaper_exit);
2777 }
Dianne Hackborn01ad2f42009-09-24 19:24:56 -07002778 }
John Spurlockc8b46ca2013-04-08 12:59:26 -04002779
2780 private static void awakenDreams() {
2781 IDreamManager dreamManager = getDreamManager();
2782 if (dreamManager != null) {
2783 try {
2784 dreamManager.awaken();
2785 } catch (RemoteException e) {
2786 // fine, stay asleep then
2787 }
2788 }
2789 }
2790
2791 static IDreamManager getDreamManager() {
2792 return IDreamManager.Stub.asInterface(
2793 ServiceManager.checkService(DreamService.DREAM_SERVICE));
2794 }
2795
Tyler Gunnef9f6f92014-09-12 22:16:17 -07002796 TelecomManager getTelecommService() {
2797 return (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002798 }
2799
Jeff Brown4d396052010-10-29 21:50:21 -07002800 static IAudioService getAudioService() {
2801 IAudioService audioService = IAudioService.Stub.asInterface(
2802 ServiceManager.checkService(Context.AUDIO_SERVICE));
2803 if (audioService == null) {
2804 Log.w(TAG, "Unable to find IAudioService interface.");
2805 }
2806 return audioService;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002807 }
2808
2809 boolean keyguardOn() {
Jim Millerab954542014-10-10 18:21:49 -07002810 return isKeyguardShowingAndNotOccluded() || inKeyguardRestrictedKeyInputMode();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002811 }
2812
2813 private static final int[] WINDOW_TYPES_WHERE_HOME_DOESNT_WORK = {
2814 WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
2815 WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
2816 };
2817
2818 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002819 @Override
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002820 public long interceptKeyBeforeDispatching(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002821 final boolean keyguardOn = keyguardOn();
Jeff Brown1f245102010-11-18 20:53:46 -08002822 final int keyCode = event.getKeyCode();
2823 final int repeatCount = event.getRepeatCount();
2824 final int metaState = event.getMetaState();
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002825 final int flags = event.getFlags();
Jeff Brown1f245102010-11-18 20:53:46 -08002826 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
2827 final boolean canceled = event.isCanceled();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002828
Jeff Brown40013652012-05-16 21:22:36 -07002829 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002830 Log.d(TAG, "interceptKeyTi keyCode=" + keyCode + " down=" + down + " repeatCount="
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002831 + repeatCount + " keyguardOn=" + keyguardOn + " mHomePressed=" + mHomePressed
2832 + " canceled=" + canceled);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002833 }
2834
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002835 // If we think we might have a volume down & power key chord on the way
2836 // but we're not sure, then tell the dispatcher to wait a little while and
2837 // try again later before dispatching.
Christopher Tatee90585f2012-03-05 18:56:25 -08002838 if (mScreenshotChordEnabled && (flags & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002839 if (mScreenshotChordVolumeDownKeyTriggered && !mScreenshotChordPowerKeyTriggered) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002840 final long now = SystemClock.uptimeMillis();
Jeff Brown13f00f02014-10-31 14:45:50 -07002841 final long timeoutTime = mScreenshotChordVolumeDownKeyTime
2842 + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002843 if (now < timeoutTime) {
2844 return timeoutTime - now;
2845 }
2846 }
2847 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
Jeff Brown13f00f02014-10-31 14:45:50 -07002848 && mScreenshotChordVolumeDownKeyConsumed) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002849 if (!down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07002850 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002851 }
2852 return -1;
2853 }
2854 }
2855
Michael Wright6a62e552014-06-03 19:19:48 -07002856 // Cancel any pending meta actions if we see any other keys being pressed between the down
2857 // of the meta key and its corresponding up.
Michael Wright251e35d2014-08-22 15:40:27 -07002858 if (mPendingMetaAction && !KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07002859 mPendingMetaAction = false;
2860 }
2861
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002862 // First we always handle the home key here, so applications
2863 // can never break it, although if keyguard is on, we do let
2864 // it handle it, because that gives us the correct 5 second
2865 // timeout.
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002866 if (keyCode == KeyEvent.KEYCODE_HOME) {
Michael Jurka7f2668c2012-03-27 07:49:52 -07002867
Jeff Brown49ed71d2010-12-06 17:13:33 -08002868 // If we have released the home key, and didn't do anything else
2869 // while it was pressed, then it is time to go home!
Michael Jurka7f2668c2012-03-27 07:49:52 -07002870 if (!down) {
Jeff Browncaca8812013-05-09 13:34:33 -07002871 cancelPreloadRecentApps();
2872
Jeff Brown49ed71d2010-12-06 17:13:33 -08002873 mHomePressed = false;
Jeff Browncaca8812013-05-09 13:34:33 -07002874 if (mHomeConsumed) {
2875 mHomeConsumed = false;
Michael Jurka7f2668c2012-03-27 07:49:52 -07002876 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002877 }
Jeff Browncaca8812013-05-09 13:34:33 -07002878
2879 if (canceled) {
2880 Log.i(TAG, "Ignoring HOME; event canceled.");
2881 return -1;
2882 }
2883
Yorke Lee4f803242014-12-15 23:22:06 +00002884 // If an incoming call is ringing, HOME is totally disabled.
2885 // (The user is already on the InCallUI at this point,
2886 // and his ONLY options are to answer or reject the call.)
2887 TelecomManager telecomManager = getTelecommService();
2888 if (telecomManager != null && telecomManager.isRinging()) {
2889 Log.i(TAG, "Ignoring HOME; there's a ringing incoming call.");
2890 return -1;
2891 }
2892
Jeff Browncaca8812013-05-09 13:34:33 -07002893 // Delay handling home if a double-tap is possible.
2894 if (mDoubleTapOnHomeBehavior != DOUBLE_TAP_HOME_NOTHING) {
2895 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable); // just in case
2896 mHomeDoubleTapPending = true;
2897 mHandler.postDelayed(mHomeDoubleTapTimeoutRunnable,
2898 ViewConfiguration.getDoubleTapTimeout());
2899 return -1;
2900 }
2901
Jeff Brown13f00f02014-10-31 14:45:50 -07002902 handleShortPressOnHome();
Jeff Browncaca8812013-05-09 13:34:33 -07002903 return -1;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002904 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002905
2906 // If a system window has focus, then it doesn't make sense
2907 // right now to interact with applications.
2908 WindowManager.LayoutParams attrs = win != null ? win.getAttrs() : null;
2909 if (attrs != null) {
2910 final int type = attrs.type;
Jorim Jaggi380ecb82014-03-14 17:25:20 +01002911 if (type == WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM
2912 || type == WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG
2913 || (attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002914 // the "app" is keyguard, so give it the key
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002915 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002916 }
2917 final int typeCount = WINDOW_TYPES_WHERE_HOME_DOESNT_WORK.length;
2918 for (int i=0; i<typeCount; i++) {
2919 if (type == WINDOW_TYPES_WHERE_HOME_DOESNT_WORK[i]) {
2920 // don't do anything, but also don't pass it to the app
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002921 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002922 }
2923 }
2924 }
Jeff Browncaca8812013-05-09 13:34:33 -07002925
2926 // Remember that home is pressed and handle special actions.
2927 if (repeatCount == 0) {
2928 mHomePressed = true;
2929 if (mHomeDoubleTapPending) {
2930 mHomeDoubleTapPending = false;
2931 mHandler.removeCallbacks(mHomeDoubleTapTimeoutRunnable);
2932 handleDoubleTapOnHome();
2933 } else if (mLongPressOnHomeBehavior == LONG_PRESS_HOME_RECENT_SYSTEM_UI
2934 || mDoubleTapOnHomeBehavior == DOUBLE_TAP_HOME_RECENT_SYSTEM_UI) {
2935 preloadRecentApps();
Michael Jurka7f2668c2012-03-27 07:49:52 -07002936 }
Jeff Browncaca8812013-05-09 13:34:33 -07002937 } else if ((event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0) {
2938 if (!keyguardOn) {
Jaewan Kim76b7d0d2016-02-12 19:01:02 +09002939 handleLongPressOnHome(event.getDeviceId());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002940 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002941 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002942 return -1;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002943 } else if (keyCode == KeyEvent.KEYCODE_MENU) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002944 // Hijack modified menu keys for debugging features
2945 final int chordBug = KeyEvent.META_SHIFT_ON;
2946
2947 if (down && repeatCount == 0) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002948 if (mEnableShiftMenuBugReports && (metaState & chordBug) == chordBug) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002949 Intent intent = new Intent(Intent.ACTION_BUG_REPORT);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07002950 mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT,
2951 null, null, null, 0, null, null);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002952 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002953 } else if (SHOW_PROCESSES_ON_ALT_MENU &&
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002954 (metaState & KeyEvent.META_ALT_ON) == KeyEvent.META_ALT_ON) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002955 Intent service = new Intent();
2956 service.setClassName(mContext, "com.android.server.LoadAverageService");
2957 ContentResolver res = mContext.getContentResolver();
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002958 boolean shown = Settings.Global.getInt(
2959 res, Settings.Global.SHOW_PROCESSES, 0) != 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002960 if (!shown) {
2961 mContext.startService(service);
2962 } else {
2963 mContext.stopService(service);
2964 }
Jeff Sharkey8d9a1f62012-10-18 15:38:14 -07002965 Settings.Global.putInt(
2966 res, Settings.Global.SHOW_PROCESSES, shown ? 0 : 1);
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002967 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002968 }
2969 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07002970 } else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002971 if (down) {
2972 if (repeatCount == 0) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002973 mSearchKeyShortcutPending = true;
2974 mConsumeSearchKeyUp = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002975 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07002976 } else {
2977 mSearchKeyShortcutPending = false;
2978 if (mConsumeSearchKeyUp) {
2979 mConsumeSearchKeyUp = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002980 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08002981 }
2982 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002983 return 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08002984 } else if (keyCode == KeyEvent.KEYCODE_APP_SWITCH) {
Michael Wrightc9ebea72013-01-16 19:25:02 -08002985 if (!keyguardOn) {
Jeff Browncaca8812013-05-09 13:34:33 -07002986 if (down && repeatCount == 0) {
2987 preloadRecentApps();
2988 } else if (!down) {
2989 toggleRecentApps();
Michael Wrightc9ebea72013-01-16 19:25:02 -08002990 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08002991 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07002992 return -1;
Jun Mukaid21b3c82015-04-23 14:09:34 -07002993 } else if (keyCode == KeyEvent.KEYCODE_N && event.isMetaPressed()) {
2994 if (down) {
2995 IStatusBarService service = getStatusBarService();
2996 if (service != null) {
2997 try {
2998 service.expandNotificationsPanel();
2999 } catch (RemoteException e) {
3000 // do nothing.
3001 }
3002 }
3003 }
Clara Bayarrif2debb12015-07-10 14:47:17 +01003004 } else if (keyCode == KeyEvent.KEYCODE_SLASH && event.isMetaPressed()) {
3005 if (down) {
3006 if (repeatCount == 0) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003007 toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003008 }
3009 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003010 } else if (keyCode == KeyEvent.KEYCODE_ASSIST) {
3011 if (down) {
3012 if (repeatCount == 0) {
3013 mAssistKeyLongPressed = false;
3014 } else if (repeatCount == 1) {
3015 mAssistKeyLongPressed = true;
3016 if (!keyguardOn) {
3017 launchAssistLongPressAction();
3018 }
3019 }
3020 } else {
3021 if (mAssistKeyLongPressed) {
3022 mAssistKeyLongPressed = false;
3023 } else {
3024 if (!keyguardOn) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003025 launchAssistAction(null, event.getDeviceId());
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003026 }
3027 }
3028 }
3029 return -1;
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003030 } else if (keyCode == KeyEvent.KEYCODE_VOICE_ASSIST) {
3031 if (!down) {
3032 Intent voiceIntent;
Michael Wright869a67c2014-08-26 19:33:06 -07003033 if (!keyguardOn) {
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003034 voiceIntent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH);
3035 } else {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07003036 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
3037 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
3038 if (dic != null) {
3039 try {
3040 dic.exitIdle("voice-search");
3041 } catch (RemoteException e) {
3042 }
3043 }
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003044 voiceIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
Michael Wright869a67c2014-08-26 19:33:06 -07003045 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, true);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003046 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003047 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wrightdc63f7b2014-08-21 19:05:21 -07003048 }
Jeff Sharkey2991fa32012-12-05 18:06:43 -08003049 } else if (keyCode == KeyEvent.KEYCODE_SYSRQ) {
3050 if (down && repeatCount == 0) {
3051 mHandler.post(mScreenshotRunnable);
3052 }
3053 return -1;
Michael Wrightb854e242013-02-05 17:54:02 -08003054 } else if (keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP
3055 || keyCode == KeyEvent.KEYCODE_BRIGHTNESS_DOWN) {
3056 if (down) {
3057 int direction = keyCode == KeyEvent.KEYCODE_BRIGHTNESS_UP ? 1 : -1;
3058
3059 // Disable autobrightness if it's on
3060 int auto = Settings.System.getIntForUser(
3061 mContext.getContentResolver(),
3062 Settings.System.SCREEN_BRIGHTNESS_MODE,
3063 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3064 UserHandle.USER_CURRENT_OR_SELF);
3065 if (auto != 0) {
3066 Settings.System.putIntForUser(mContext.getContentResolver(),
3067 Settings.System.SCREEN_BRIGHTNESS_MODE,
3068 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL,
3069 UserHandle.USER_CURRENT_OR_SELF);
3070 }
3071
3072 int min = mPowerManager.getMinimumScreenBrightnessSetting();
3073 int max = mPowerManager.getMaximumScreenBrightnessSetting();
3074 int step = (max - min + BRIGHTNESS_STEPS - 1) / BRIGHTNESS_STEPS * direction;
3075 int brightness = Settings.System.getIntForUser(mContext.getContentResolver(),
3076 Settings.System.SCREEN_BRIGHTNESS,
3077 mPowerManager.getDefaultScreenBrightnessSetting(),
3078 UserHandle.USER_CURRENT_OR_SELF);
3079 brightness += step;
3080 // Make sure we don't go beyond the limits.
3081 brightness = Math.min(max, brightness);
3082 brightness = Math.max(min, brightness);
3083
3084 Settings.System.putIntForUser(mContext.getContentResolver(),
3085 Settings.System.SCREEN_BRIGHTNESS, brightness,
3086 UserHandle.USER_CURRENT_OR_SELF);
Bart Sears8b1c27c2015-03-18 23:51:02 +00003087 startActivityAsUser(new Intent(Intent.ACTION_SHOW_BRIGHTNESS_DIALOG),
Alan Viverette5a399492014-07-14 16:19:38 -07003088 UserHandle.CURRENT_OR_SELF);
Michael Wrightb854e242013-02-05 17:54:02 -08003089 }
3090 return -1;
Jaewan Kim765487f2016-01-12 14:45:42 +09003091 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP
3092 || keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
3093 || keyCode == KeyEvent.KEYCODE_VOLUME_MUTE) {
3094 if (mUseTvRouting) {
3095 // On TVs volume keys never go to the foreground app.
3096 dispatchDirectAudioEvent(event);
3097 return -1;
3098 }
Michael Wrightce0c13a2014-07-30 10:49:21 -07003099 } else if (KeyEvent.isMetaKey(keyCode)) {
Michael Wright6a62e552014-06-03 19:19:48 -07003100 if (down) {
3101 mPendingMetaAction = true;
3102 } else if (mPendingMetaAction) {
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003103 launchAssistAction(Intent.EXTRA_ASSIST_INPUT_HINT_KEYBOARD, event.getDeviceId());
Michael Wright6a62e552014-06-03 19:19:48 -07003104 }
3105 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003106 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003107
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003108 // Shortcuts are invoked through Search+key, so intercept those here
Jeff Browncaab4d02010-12-09 22:13:41 -08003109 // Any printing key that is chorded with Search should be consumed
3110 // even if no shortcut was invoked. This prevents text from being
3111 // inadvertently inserted when using a keyboard that has built-in macro
3112 // shortcut keys (that emit Search+x) and some of them are not registered.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003113 if (mSearchKeyShortcutPending) {
Jeff Browncaab4d02010-12-09 22:13:41 -08003114 final KeyCharacterMap kcm = event.getKeyCharacterMap();
3115 if (kcm.isPrintingKey(keyCode)) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003116 mConsumeSearchKeyUp = true;
3117 mSearchKeyShortcutPending = false;
Jeff Browncaab4d02010-12-09 22:13:41 -08003118 if (down && repeatCount == 0 && !keyguardOn) {
3119 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode, metaState);
3120 if (shortcutIntent != null) {
3121 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003122 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003123 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003124 } catch (ActivityNotFoundException ex) {
3125 Slog.w(TAG, "Dropping shortcut key combination because "
3126 + "the activity to which it is registered was not found: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003127 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode), ex);
Jeff Brownf0a3cc52011-01-26 18:42:46 -08003128 }
Jeff Browncaab4d02010-12-09 22:13:41 -08003129 } else {
3130 Slog.i(TAG, "Dropping unregistered shortcut key combination: "
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003131 + "SEARCH+" + KeyEvent.keyCodeToString(keyCode));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003132 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003133 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003134 return -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003135 }
3136 }
3137
Jeff Brown68b909d2011-12-07 16:36:01 -08003138 // Invoke shortcuts using Meta.
Jeff Brown602ab322012-05-16 13:33:47 -07003139 if (down && repeatCount == 0 && !keyguardOn
Jeff Brown68b909d2011-12-07 16:36:01 -08003140 && (metaState & KeyEvent.META_META_ON) != 0) {
3141 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brown602ab322012-05-16 13:33:47 -07003142 if (kcm.isPrintingKey(keyCode)) {
3143 Intent shortcutIntent = mShortcutManager.getIntent(kcm, keyCode,
3144 metaState & ~(KeyEvent.META_META_ON
3145 | KeyEvent.META_META_LEFT_ON | KeyEvent.META_META_RIGHT_ON));
3146 if (shortcutIntent != null) {
3147 shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3148 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003149 startActivityAsUser(shortcutIntent, UserHandle.CURRENT);
Jeff Brown602ab322012-05-16 13:33:47 -07003150 } catch (ActivityNotFoundException ex) {
3151 Slog.w(TAG, "Dropping shortcut key combination because "
3152 + "the activity to which it is registered was not found: "
3153 + "META+" + KeyEvent.keyCodeToString(keyCode), ex);
3154 }
3155 return -1;
Jeff Brown68b909d2011-12-07 16:36:01 -08003156 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003157 }
3158 }
3159
Jeff Brown6651a632011-11-28 12:59:11 -08003160 // Handle application launch keys.
Jeff Brown602ab322012-05-16 13:33:47 -07003161 if (down && repeatCount == 0 && !keyguardOn) {
Jeff Brown6651a632011-11-28 12:59:11 -08003162 String category = sApplicationLaunchKeyCategories.get(keyCode);
3163 if (category != null) {
Dianne Hackbornf5b86712011-12-05 17:42:41 -08003164 Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN, category);
Jeff Brown6651a632011-11-28 12:59:11 -08003165 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3166 try {
Bart Sears8b1c27c2015-03-18 23:51:02 +00003167 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brown6651a632011-11-28 12:59:11 -08003168 } catch (ActivityNotFoundException ex) {
3169 Slog.w(TAG, "Dropping application launch key because "
3170 + "the activity to which it is registered was not found: "
3171 + "keyCode=" + keyCode + ", category=" + category, ex);
3172 }
Jeff Brown68b909d2011-12-07 16:36:01 -08003173 return -1;
Jeff Brown6651a632011-11-28 12:59:11 -08003174 }
3175 }
3176
Michael Wright61c46752014-08-21 16:57:33 -07003177 // Display task switcher for ALT-TAB.
Jeff Brown68b909d2011-12-07 16:36:01 -08003178 if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_TAB) {
Michael Wrightd847ad52015-10-24 13:24:15 +01003179 if (mRecentAppsHeldModifiers == 0 && !keyguardOn && isUserSetupComplete()) {
Jeff Brown68b909d2011-12-07 16:36:01 -08003180 final int shiftlessModifiers = event.getModifiers() & ~KeyEvent.META_SHIFT_MASK;
Michael Wright61c46752014-08-21 16:57:33 -07003181 if (KeyEvent.metaStateHasModifiers(shiftlessModifiers, KeyEvent.META_ALT_ON)) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003182 mRecentAppsHeldModifiers = shiftlessModifiers;
3183 showRecentApps(true);
Jeff Brown68b909d2011-12-07 16:36:01 -08003184 return -1;
3185 }
3186 }
Winson Chung1e8d71b2014-05-16 17:05:22 -07003187 } else if (!down && mRecentAppsHeldModifiers != 0
3188 && (metaState & mRecentAppsHeldModifiers) == 0) {
3189 mRecentAppsHeldModifiers = 0;
Winson Chungcdcd4872014-08-05 18:00:13 -07003190 hideRecentApps(true, false);
Jeff Brown68b909d2011-12-07 16:36:01 -08003191 }
3192
Yohei Yukawaae61f712015-12-09 13:00:10 -08003193 // Handle input method switching.
Jeff Browncf39bdf2012-05-18 14:41:19 -07003194 if (down && repeatCount == 0
3195 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3196 || (keyCode == KeyEvent.KEYCODE_SPACE
Yohei Yukawaae61f712015-12-09 13:00:10 -08003197 && (metaState & KeyEvent.META_META_MASK) != 0))) {
3198 final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
3199 mWindowManagerFuncs.switchInputMethod(forwardDirection);
Jeff Browncf39bdf2012-05-18 14:41:19 -07003200 return -1;
3201 }
3202 if (mLanguageSwitchKeyPressed && !down
3203 && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
3204 || keyCode == KeyEvent.KEYCODE_SPACE)) {
3205 mLanguageSwitchKeyPressed = false;
3206 return -1;
3207 }
3208
Jeff Brown13f00f02014-10-31 14:45:50 -07003209 if (isValidGlobalKey(keyCode)
3210 && mGlobalKeyManager.handleGlobalKey(mContext, keyCode, event)) {
Justin Kohd378ad72013-04-01 12:18:26 -07003211 return -1;
3212 }
3213
Michael Wright6a62e552014-06-03 19:19:48 -07003214 // Reserve all the META modifier combos for system behavior
Michael Wrightce0c13a2014-07-30 10:49:21 -07003215 if ((metaState & KeyEvent.META_META_ON) != 0) {
Michael Wright6a62e552014-06-03 19:19:48 -07003216 return -1;
3217 }
3218
Jeff Brown68b909d2011-12-07 16:36:01 -08003219 // Let the application handle the key.
Jeff Brownd5bb82d2011-10-12 13:57:59 -07003220 return 0;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003221 }
3222
Jeff Brown3915bb82010-11-05 15:02:16 -07003223 /** {@inheritDoc} */
3224 @Override
Jeff Brown49ed71d2010-12-06 17:13:33 -08003225 public KeyEvent dispatchUnhandledKey(WindowState win, KeyEvent event, int policyFlags) {
Jeff Brown54875002011-04-06 15:33:01 -07003226 // Note: This method is only called if the initial down was unhandled.
Jeff Brown40013652012-05-16 21:22:36 -07003227 if (DEBUG_INPUT) {
Jeff Brown1f245102010-11-18 20:53:46 -08003228 Slog.d(TAG, "Unhandled key: win=" + win + ", action=" + event.getAction()
3229 + ", flags=" + event.getFlags()
3230 + ", keyCode=" + event.getKeyCode()
3231 + ", scanCode=" + event.getScanCode()
3232 + ", metaState=" + event.getMetaState()
3233 + ", repeatCount=" + event.getRepeatCount()
3234 + ", policyFlags=" + policyFlags);
Jeff Brown3915bb82010-11-05 15:02:16 -07003235 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003236
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003237 KeyEvent fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003238 if ((event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
3239 final KeyCharacterMap kcm = event.getKeyCharacterMap();
Jeff Brownc1fb48d2010-12-08 16:52:09 -08003240 final int keyCode = event.getKeyCode();
3241 final int metaState = event.getMetaState();
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003242 final boolean initialDown = event.getAction() == KeyEvent.ACTION_DOWN
3243 && event.getRepeatCount() == 0;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003244
Jeff Brown54875002011-04-06 15:33:01 -07003245 // Check for fallback actions specified by the key character map.
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003246 final FallbackAction fallbackAction;
3247 if (initialDown) {
3248 fallbackAction = kcm.getFallbackAction(keyCode, metaState);
3249 } else {
3250 fallbackAction = mFallbackActions.get(keyCode);
3251 }
3252
3253 if (fallbackAction != null) {
Jeff Brown40013652012-05-16 21:22:36 -07003254 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003255 Slog.d(TAG, "Fallback: keyCode=" + fallbackAction.keyCode
3256 + " metaState=" + Integer.toHexString(fallbackAction.metaState));
Jeff Brown49ed71d2010-12-06 17:13:33 -08003257 }
3258
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003259 final int flags = event.getFlags() | KeyEvent.FLAG_FALLBACK;
3260 fallbackEvent = KeyEvent.obtain(
Jeff Brown49ed71d2010-12-06 17:13:33 -08003261 event.getDownTime(), event.getEventTime(),
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003262 event.getAction(), fallbackAction.keyCode,
3263 event.getRepeatCount(), fallbackAction.metaState,
Jeff Brown49ed71d2010-12-06 17:13:33 -08003264 event.getDeviceId(), event.getScanCode(),
3265 flags, event.getSource(), null);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003266
3267 if (!interceptFallback(win, fallbackEvent, policyFlags)) {
3268 fallbackEvent.recycle();
3269 fallbackEvent = null;
Jeff Brown49ed71d2010-12-06 17:13:33 -08003270 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003271
3272 if (initialDown) {
3273 mFallbackActions.put(keyCode, fallbackAction);
3274 } else if (event.getAction() == KeyEvent.ACTION_UP) {
3275 mFallbackActions.remove(keyCode);
3276 fallbackAction.recycle();
3277 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003278 }
3279 }
3280
Jeff Brown40013652012-05-16 21:22:36 -07003281 if (DEBUG_INPUT) {
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003282 if (fallbackEvent == null) {
3283 Slog.d(TAG, "No fallback.");
3284 } else {
3285 Slog.d(TAG, "Performing fallback: " + fallbackEvent);
3286 }
Jeff Brown49ed71d2010-12-06 17:13:33 -08003287 }
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003288 return fallbackEvent;
Jeff Brown3915bb82010-11-05 15:02:16 -07003289 }
3290
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003291 private boolean interceptFallback(WindowState win, KeyEvent fallbackEvent, int policyFlags) {
Jeff Brown037c33e2014-04-09 00:31:55 -07003292 int actions = interceptKeyBeforeQueueing(fallbackEvent, policyFlags);
Jeff Brownfd23e3e2012-05-09 13:34:28 -07003293 if ((actions & ACTION_PASS_TO_USER) != 0) {
3294 long delayMillis = interceptKeyBeforeDispatching(
3295 win, fallbackEvent, policyFlags);
3296 if (delayMillis == 0) {
3297 return true;
3298 }
3299 }
3300 return false;
Jeff Brown6f2fba42011-02-19 01:08:02 -08003301 }
3302
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003303 private void launchAssistLongPressAction() {
3304 performHapticFeedbackLw(null, HapticFeedbackConstants.LONG_PRESS, false);
3305 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
3306
3307 // launch the search activity
3308 Intent intent = new Intent(Intent.ACTION_SEARCH_LONG_PRESS);
3309 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
3310 try {
RoboErik8a2cfc32014-05-16 11:19:38 -07003311 // TODO: This only stops the factory-installed search manager.
Jim Miller45308b12012-06-18 19:23:39 -07003312 // Need to formalize an API to handle others
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003313 SearchManager searchManager = getSearchManager();
3314 if (searchManager != null) {
3315 searchManager.stopSearch();
3316 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00003317 startActivityAsUser(intent, UserHandle.CURRENT);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003318 } catch (ActivityNotFoundException e) {
3319 Slog.w(TAG, "No activity to handle assist long press action.", e);
3320 }
3321 }
3322
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003323 private void launchAssistAction(String hint, int deviceId) {
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003324 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_ASSIST);
Maurice Lam39d13812015-07-23 20:49:20 -07003325 if (!isUserSetupComplete()) {
3326 // Disable opening assist window during setup
3327 return;
3328 }
Tim Kilbourn0e5f1102015-06-05 16:18:09 -07003329 Bundle args = null;
3330 if (deviceId > Integer.MIN_VALUE) {
3331 args = new Bundle();
3332 args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, deviceId);
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003333 }
Jorim Jaggi165ce062015-07-06 16:18:11 -07003334 if ((mContext.getResources().getConfiguration().uiMode
3335 & Configuration.UI_MODE_TYPE_MASK) == Configuration.UI_MODE_TYPE_TELEVISION) {
3336 // On TV, use legacy handling until assistants are implemented in the proper way.
3337 ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
3338 .launchLegacyAssist(hint, UserHandle.myUserId(), args);
3339 } else {
3340 try {
3341 if (hint != null) {
3342 if (args == null) {
3343 args = new Bundle();
3344 }
3345 args.putBoolean(hint, true);
3346 }
3347 IStatusBarService statusbar = getStatusBarService();
3348 if (statusbar != null) {
3349 statusbar.startAssist(args);
3350 }
3351 } catch (RemoteException e) {
3352 Slog.e(TAG, "RemoteException when starting assist", e);
3353 // re-acquire status bar service next time it is needed.
3354 mStatusBarService = null;
3355 }
3356 }
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003357 }
3358
Bart Sears8b1c27c2015-03-18 23:51:02 +00003359 private void startActivityAsUser(Intent intent, UserHandle handle) {
3360 if (isUserSetupComplete()) {
3361 mContext.startActivityAsUser(intent, handle);
3362 } else {
3363 Slog.i(TAG, "Not starting activity because user setup is in progress: " + intent);
3364 }
3365 }
3366
Jeff Brownde7a8ea2012-06-13 18:28:57 -07003367 private SearchManager getSearchManager() {
3368 if (mSearchManager == null) {
3369 mSearchManager = (SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE);
3370 }
3371 return mSearchManager;
3372 }
3373
Jeff Browncaca8812013-05-09 13:34:33 -07003374 private void preloadRecentApps() {
3375 mPreloadedRecentApps = true;
3376 try {
3377 IStatusBarService statusbar = getStatusBarService();
3378 if (statusbar != null) {
3379 statusbar.preloadRecentApps();
3380 }
3381 } catch (RemoteException e) {
3382 Slog.e(TAG, "RemoteException when preloading recent apps", e);
3383 // re-acquire status bar service next time it is needed.
3384 mStatusBarService = null;
3385 }
3386 }
3387
3388 private void cancelPreloadRecentApps() {
3389 if (mPreloadedRecentApps) {
3390 mPreloadedRecentApps = false;
3391 try {
3392 IStatusBarService statusbar = getStatusBarService();
3393 if (statusbar != null) {
3394 statusbar.cancelPreloadRecentApps();
3395 }
3396 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003397 Slog.e(TAG, "RemoteException when cancelling recent apps preload", e);
Jeff Browncaca8812013-05-09 13:34:33 -07003398 // re-acquire status bar service next time it is needed.
3399 mStatusBarService = null;
3400 }
3401 }
3402 }
3403
3404 private void toggleRecentApps() {
3405 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
Jeff Browncaca8812013-05-09 13:34:33 -07003406 try {
3407 IStatusBarService statusbar = getStatusBarService();
3408 if (statusbar != null) {
3409 statusbar.toggleRecentApps();
3410 }
3411 } catch (RemoteException e) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003412 Slog.e(TAG, "RemoteException when toggling recent apps", e);
3413 // re-acquire status bar service next time it is needed.
3414 mStatusBarService = null;
3415 }
3416 }
3417
Craig Mautner84984fa2014-06-19 11:19:20 -07003418 @Override
3419 public void showRecentApps() {
3420 mHandler.removeMessages(MSG_DISPATCH_SHOW_RECENTS);
3421 mHandler.sendEmptyMessage(MSG_DISPATCH_SHOW_RECENTS);
3422 }
3423
Winson Chung1e8d71b2014-05-16 17:05:22 -07003424 private void showRecentApps(boolean triggeredFromAltTab) {
3425 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3426 try {
3427 IStatusBarService statusbar = getStatusBarService();
3428 if (statusbar != null) {
3429 statusbar.showRecentApps(triggeredFromAltTab);
3430 }
3431 } catch (RemoteException e) {
Jeff Browncaca8812013-05-09 13:34:33 -07003432 Slog.e(TAG, "RemoteException when showing recent apps", e);
3433 // re-acquire status bar service next time it is needed.
3434 mStatusBarService = null;
3435 }
3436 }
3437
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003438 private void toggleKeyboardShortcutsMenu() {
Clara Bayarrif2debb12015-07-10 14:47:17 +01003439 try {
3440 IStatusBarService statusbar = getStatusBarService();
3441 if (statusbar != null) {
Andrei Stingaceanuc22ab792016-01-07 12:39:38 +00003442 statusbar.toggleKeyboardShortcutsMenu();
Clara Bayarrif2debb12015-07-10 14:47:17 +01003443 }
3444 } catch (RemoteException e) {
3445 Slog.e(TAG, "RemoteException when showing keyboard shortcuts menu", e);
3446 }
3447 }
3448
Winson Chungcdcd4872014-08-05 18:00:13 -07003449 private void hideRecentApps(boolean triggeredFromAltTab, boolean triggeredFromHome) {
Winson Chung1e8d71b2014-05-16 17:05:22 -07003450 mPreloadedRecentApps = false; // preloading no longer needs to be canceled
3451 try {
3452 IStatusBarService statusbar = getStatusBarService();
3453 if (statusbar != null) {
Winson Chungcdcd4872014-08-05 18:00:13 -07003454 statusbar.hideRecentApps(triggeredFromAltTab, triggeredFromHome);
Winson Chung1e8d71b2014-05-16 17:05:22 -07003455 }
3456 } catch (RemoteException e) {
3457 Slog.e(TAG, "RemoteException when closing recent apps", e);
3458 // re-acquire status bar service next time it is needed.
3459 mStatusBarService = null;
3460 }
3461 }
3462
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003463 void launchHomeFromHotKey() {
Bryce Lee662ed802015-04-10 20:11:39 +00003464 launchHomeFromHotKey(true /* awakenFromDreams */, true /*respectKeyguard*/);
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00003465 }
3466
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003467 /**
3468 * A home key -> launch home action was detected. Take the appropriate action
3469 * given the situation with the keyguard.
3470 */
Bryce Lee662ed802015-04-10 20:11:39 +00003471 void launchHomeFromHotKey(final boolean awakenFromDreams, final boolean respectKeyguard) {
3472 if (respectKeyguard) {
3473 if (isKeyguardShowingAndNotOccluded()) {
3474 // don't launch home if keyguard showing
3475 return;
3476 }
3477
3478 if (!mHideLockScreen && mKeyguardDelegate.isInputRestricted()) {
3479 // when in keyguard restricted mode, must first verify unlock
3480 // before launching home
3481 mKeyguardDelegate.verifyUnlock(new OnKeyguardExitResult() {
3482 @Override
3483 public void onKeyguardExitResult(boolean success) {
3484 if (success) {
3485 try {
3486 ActivityManagerNative.getDefault().stopAppSwitches();
3487 } catch (RemoteException e) {
3488 }
3489 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3490 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07003491 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003492 }
Bryce Lee662ed802015-04-10 20:11:39 +00003493 });
3494 return;
3495 }
3496 }
3497
3498 // no keyguard stuff to worry about, just launch home!
3499 try {
3500 ActivityManagerNative.getDefault().stopAppSwitches();
3501 } catch (RemoteException e) {
3502 }
3503 if (mRecentsVisible) {
3504 // Hide Recents and notify it to launch Home
3505 if (awakenFromDreams) {
3506 awakenDreams();
3507 }
Bryce Lee662ed802015-04-10 20:11:39 +00003508 hideRecentApps(false, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003509 } else {
Bryce Lee662ed802015-04-10 20:11:39 +00003510 // Otherwise, just launch Home
3511 sendCloseSystemWindows(SYSTEM_DIALOG_REASON_HOME_KEY);
3512 startDockOrHome(true /*fromHomeKey*/, awakenFromDreams);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003513 }
3514 }
3515
John Spurlock04db1762013-05-13 12:46:41 -04003516 private final Runnable mClearHideNavigationFlag = new Runnable() {
3517 @Override
3518 public void run() {
3519 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
3520 // Clear flags.
3521 mForceClearedSystemUiFlags &=
3522 ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
3523 }
3524 mWindowManagerFuncs.reevaluateStatusBarVisibility();
Dianne Hackborne26ab702011-10-16 13:21:33 -07003525 }
3526 };
3527
3528 /**
3529 * Input handler used while nav bar is hidden. Captures any touch on the screen,
3530 * to determine when the nav bar should be shown and prevent applications from
3531 * receiving those touches.
3532 */
Jeff Brown32cbc38552011-12-01 14:01:49 -08003533 final class HideNavInputEventReceiver extends InputEventReceiver {
3534 public HideNavInputEventReceiver(InputChannel inputChannel, Looper looper) {
3535 super(inputChannel, looper);
3536 }
3537
Dianne Hackborndf89e652011-10-06 22:35:11 -07003538 @Override
Jeff Brown32cbc38552011-12-01 14:01:49 -08003539 public void onInputEvent(InputEvent event) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003540 boolean handled = false;
3541 try {
Jeff Brown4952dfd2011-11-30 19:23:22 -08003542 if (event instanceof MotionEvent
3543 && (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
3544 final MotionEvent motionEvent = (MotionEvent)event;
3545 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07003546 // When the user taps down, we re-show the nav bar.
3547 boolean changed = false;
John Spurlock04db1762013-05-13 12:46:41 -04003548 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003549 // Any user activity always causes us to show the
3550 // navigation controls, if they had been hidden.
3551 // We also clear the low profile and only content
3552 // flags so that tapping on the screen will atomically
3553 // restore all currently hidden screen decorations.
3554 int newVal = mResettingSystemUiFlags |
3555 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
3556 View.SYSTEM_UI_FLAG_LOW_PROFILE |
3557 View.SYSTEM_UI_FLAG_FULLSCREEN;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003558 if (mResettingSystemUiFlags != newVal) {
3559 mResettingSystemUiFlags = newVal;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003560 changed = true;
3561 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003562 // We don't allow the system's nav bar to be hidden
3563 // again for 1 second, to prevent applications from
3564 // spamming us and keeping it from being shown.
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003565 newVal = mForceClearedSystemUiFlags |
3566 View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
Dianne Hackborne26ab702011-10-16 13:21:33 -07003567 if (mForceClearedSystemUiFlags != newVal) {
3568 mForceClearedSystemUiFlags = newVal;
3569 changed = true;
John Spurlock04db1762013-05-13 12:46:41 -04003570 mHandler.postDelayed(mClearHideNavigationFlag, 1000);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003571 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003572 }
3573 if (changed) {
3574 mWindowManagerFuncs.reevaluateStatusBarVisibility();
3575 }
3576 }
3577 }
3578 } finally {
Jeff Brown32cbc38552011-12-01 14:01:49 -08003579 finishInputEvent(event, handled);
Dianne Hackborndf89e652011-10-06 22:35:11 -07003580 }
3581 }
Jeff Brown32cbc38552011-12-01 14:01:49 -08003582 }
3583 final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
3584 new InputEventReceiver.Factory() {
3585 @Override
3586 public InputEventReceiver createInputEventReceiver(
3587 InputChannel inputChannel, Looper looper) {
3588 return new HideNavInputEventReceiver(inputChannel, looper);
3589 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07003590 };
3591
3592 @Override
3593 public int adjustSystemUiVisibilityLw(int visibility) {
John Spurlock5b9145b2013-08-20 15:13:47 -04003594 mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
3595 mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
Winson Chungd42a6cf2014-06-03 16:24:04 -07003596 mRecentsVisible = (visibility & View.RECENT_APPS_VISIBLE) > 0;
John Spurlock27735a42013-08-14 17:57:38 -04003597
Dianne Hackborndf89e652011-10-06 22:35:11 -07003598 // Reset any bits in mForceClearingStatusBarVisibility that
3599 // are now clear.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003600 mResettingSystemUiFlags &= visibility;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003601 // Clear any bits in the new visibility that are currently being
3602 // force cleared, before reporting it.
Dianne Hackborne26ab702011-10-16 13:21:33 -07003603 return visibility & ~mResettingSystemUiFlags
3604 & ~mForceClearedSystemUiFlags;
Dianne Hackborndf89e652011-10-06 22:35:11 -07003605 }
3606
Craig Mautner69b08182012-09-05 13:07:13 -07003607 @Override
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003608 public void getInsetHintLw(WindowManager.LayoutParams attrs, int displayRotation,
3609 Rect outContentInsets, Rect outStableInsets, Rect outOutsets) {
John Spurlockc6d1c602014-01-17 15:22:06 -05003610 final int fl = PolicyControl.getWindowFlags(null, attrs);
John Spurlock1db8b682014-02-18 11:18:59 -05003611 final int sysuiVis = PolicyControl.getSystemUiVisibility(null, attrs);
3612 final int systemUiVisibility = (sysuiVis | attrs.subtreeSystemUiVisibility);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003613
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003614 final boolean useOutsets = outOutsets != null && shouldUseOutsets(attrs, fl);
3615 if (useOutsets) {
3616 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
3617 if (outset > 0) {
3618 if (displayRotation == Surface.ROTATION_0) {
3619 outOutsets.bottom += outset;
3620 } else if (displayRotation == Surface.ROTATION_90) {
3621 outOutsets.right += outset;
3622 } else if (displayRotation == Surface.ROTATION_180) {
3623 outOutsets.top += outset;
3624 } else if (displayRotation == Surface.ROTATION_270) {
3625 outOutsets.left += outset;
3626 }
3627 }
3628 }
3629
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003630 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003631 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003632 int availRight, availBottom;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003633 if (canHideNavigationBar() &&
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003634 (systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003635 availRight = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
3636 availBottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
3637 } else {
3638 availRight = mRestrictedScreenLeft + mRestrictedScreenWidth;
3639 availBottom = mRestrictedScreenTop + mRestrictedScreenHeight;
3640 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003641 if ((systemUiVisibility & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
3642 if ((fl & FLAG_FULLSCREEN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003643 outContentInsets.set(mStableFullscreenLeft, mStableFullscreenTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003644 availRight - mStableFullscreenRight,
3645 availBottom - mStableFullscreenBottom);
3646 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003647 outContentInsets.set(mStableLeft, mStableTop,
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003648 availRight - mStableRight, availBottom - mStableBottom);
3649 }
Dianne Hackbornc652de82013-02-15 16:32:56 -08003650 } else if ((fl & FLAG_FULLSCREEN) != 0 || (fl & FLAG_LAYOUT_IN_OVERSCAN) != 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003651 outContentInsets.setEmpty();
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07003652 } else if ((systemUiVisibility & (View.SYSTEM_UI_FLAG_FULLSCREEN
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003653 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)) == 0) {
Adrian Roos37d7a682014-11-06 18:15:16 +01003654 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003655 availRight - mCurRight, availBottom - mCurBottom);
3656 } else {
Adrian Roos37d7a682014-11-06 18:15:16 +01003657 outContentInsets.set(mCurLeft, mCurTop,
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003658 availRight - mCurRight, availBottom - mCurBottom);
3659 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003660
3661 outStableInsets.set(mStableLeft, mStableTop,
3662 availRight - mStableRight, availBottom - mStableBottom);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003663 return;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003664 }
Adrian Roos37d7a682014-11-06 18:15:16 +01003665 outContentInsets.setEmpty();
3666 outStableInsets.setEmpty();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003667 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07003668
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003669 private boolean shouldUseOutsets(WindowManager.LayoutParams attrs, int fl) {
3670 return attrs.type == TYPE_WALLPAPER || (fl & (WindowManager.LayoutParams.FLAG_FULLSCREEN
3671 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN)) != 0;
3672 }
3673
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003674 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07003675 @Override
3676 public void beginLayoutLw(boolean isDefaultDisplay, int displayWidth, int displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003677 int displayRotation, int uiMode) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07003678 mDisplayRotation = displayRotation;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003679 final int overscanLeft, overscanTop, overscanRight, overscanBottom;
3680 if (isDefaultDisplay) {
3681 switch (displayRotation) {
3682 case Surface.ROTATION_90:
3683 overscanLeft = mOverscanTop;
3684 overscanTop = mOverscanRight;
3685 overscanRight = mOverscanBottom;
3686 overscanBottom = mOverscanLeft;
3687 break;
3688 case Surface.ROTATION_180:
3689 overscanLeft = mOverscanRight;
3690 overscanTop = mOverscanBottom;
3691 overscanRight = mOverscanLeft;
3692 overscanBottom = mOverscanTop;
3693 break;
3694 case Surface.ROTATION_270:
3695 overscanLeft = mOverscanBottom;
3696 overscanTop = mOverscanLeft;
3697 overscanRight = mOverscanTop;
3698 overscanBottom = mOverscanRight;
3699 break;
3700 default:
3701 overscanLeft = mOverscanLeft;
3702 overscanTop = mOverscanTop;
3703 overscanRight = mOverscanRight;
3704 overscanBottom = mOverscanBottom;
3705 break;
3706 }
3707 } else {
3708 overscanLeft = 0;
3709 overscanTop = 0;
3710 overscanRight = 0;
3711 overscanBottom = 0;
3712 }
Dianne Hackborn313440842013-02-19 19:22:59 -08003713 mOverscanScreenLeft = mRestrictedOverscanScreenLeft = 0;
3714 mOverscanScreenTop = mRestrictedOverscanScreenTop = 0;
3715 mOverscanScreenWidth = mRestrictedOverscanScreenWidth = displayWidth;
3716 mOverscanScreenHeight = mRestrictedOverscanScreenHeight = displayHeight;
Dianne Hackbornc652de82013-02-15 16:32:56 -08003717 mSystemLeft = 0;
3718 mSystemTop = 0;
3719 mSystemRight = displayWidth;
3720 mSystemBottom = displayHeight;
3721 mUnrestrictedScreenLeft = overscanLeft;
3722 mUnrestrictedScreenTop = overscanTop;
3723 mUnrestrictedScreenWidth = displayWidth - overscanLeft - overscanRight;
3724 mUnrestrictedScreenHeight = displayHeight - overscanTop - overscanBottom;
3725 mRestrictedScreenLeft = mUnrestrictedScreenLeft;
3726 mRestrictedScreenTop = mUnrestrictedScreenTop;
John Spurlockad3e6cb2013-04-30 08:47:43 -04003727 mRestrictedScreenWidth = mSystemGestures.screenWidth = mUnrestrictedScreenWidth;
3728 mRestrictedScreenHeight = mSystemGestures.screenHeight = mUnrestrictedScreenHeight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003729 mDockLeft = mContentLeft = mVoiceContentLeft = mStableLeft = mStableFullscreenLeft
Dianne Hackbornc652de82013-02-15 16:32:56 -08003730 = mCurLeft = mUnrestrictedScreenLeft;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003731 mDockTop = mContentTop = mVoiceContentTop = mStableTop = mStableFullscreenTop
Dianne Hackbornc652de82013-02-15 16:32:56 -08003732 = mCurTop = mUnrestrictedScreenTop;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003733 mDockRight = mContentRight = mVoiceContentRight = mStableRight = mStableFullscreenRight
Dianne Hackbornc652de82013-02-15 16:32:56 -08003734 = mCurRight = displayWidth - overscanRight;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07003735 mDockBottom = mContentBottom = mVoiceContentBottom = mStableBottom = mStableFullscreenBottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08003736 = mCurBottom = displayHeight - overscanBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003737 mDockLayer = 0x10000000;
Dianne Hackborn5c58de32012-04-28 19:52:37 -07003738 mStatusBarLayer = -1;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003739
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003740 // start with the current dock rect, which will be (0,0,displayWidth,displayHeight)
3741 final Rect pf = mTmpParentFrame;
3742 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003743 final Rect of = mTmpOverscanFrame;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003744 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04003745 final Rect dcf = mTmpDecorFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003746 pf.left = df.left = of.left = vf.left = mDockLeft;
3747 pf.top = df.top = of.top = vf.top = mDockTop;
3748 pf.right = df.right = of.right = vf.right = mDockRight;
3749 pf.bottom = df.bottom = of.bottom = vf.bottom = mDockBottom;
John Spurlock46646232013-09-30 22:32:42 -04003750 dcf.setEmpty(); // Decor frame N/A for system bars.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04003751
Craig Mautner69b08182012-09-05 13:07:13 -07003752 if (isDefaultDisplay) {
3753 // For purposes of putting out fake window up to steal focus, we will
3754 // drive nav being hidden only by whether it is requested.
John Spurlocke1f366f2013-08-05 12:22:40 -04003755 final int sysui = mLastSystemUiFlags;
3756 boolean navVisible = (sysui & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
Adrian Roosea562512014-05-05 13:33:03 +02003757 boolean navTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003758 & (View.NAVIGATION_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSPARENT)) != 0;
John Spurlockf1a36642013-10-12 17:50:42 -04003759 boolean immersive = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
3760 boolean immersiveSticky = (sysui & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
3761 boolean navAllowedHidden = immersive || immersiveSticky;
3762 navTranslucent &= !immersiveSticky; // transient trumps translucent
Adrian Roos4fb3ee32014-08-22 19:29:09 +02003763 boolean isKeyguardShowing = isStatusBarKeyguard() && !mHideLockScreen;
3764 if (!isKeyguardShowing) {
3765 navTranslucent &= areTranslucentBarsAllowed();
3766 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003767
Craig Mautner69b08182012-09-05 13:07:13 -07003768 // When the navigation bar isn't visible, we put up a fake
3769 // input window to catch all touch events. This way we can
3770 // detect when the user presses anywhere to bring back the nav
3771 // bar and ensure the application doesn't see the event.
John Spurlockf1a36642013-10-12 17:50:42 -04003772 if (navVisible || navAllowedHidden) {
Selim Cinekf83e8242015-05-19 18:08:14 -07003773 if (mInputConsumer != null) {
3774 mInputConsumer.dismiss();
3775 mInputConsumer = null;
Craig Mautner69b08182012-09-05 13:07:13 -07003776 }
Selim Cinekf83e8242015-05-19 18:08:14 -07003777 } else if (mInputConsumer == null) {
3778 mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
3779 mHideNavInputEventReceiverFactory);
Dianne Hackborne26ab702011-10-16 13:21:33 -07003780 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07003781
Craig Mautner69b08182012-09-05 13:07:13 -07003782 // For purposes of positioning and showing the nav bar, if we have
3783 // decided that it can't be hidden (because of the screen aspect ratio),
3784 // then take that into account.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07003785 navVisible |= !canHideNavigationBar();
Dianne Hackbornf87d1962012-04-04 12:48:24 -07003786
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003787 boolean updateSysUiVisibility = layoutNavigationBar(displayWidth, displayHeight,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003788 displayRotation, uiMode, overscanRight, overscanBottom, dcf, navVisible, navTranslucent,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003789 navAllowedHidden);
Craig Mautnereda67292013-04-28 13:50:14 -07003790 if (DEBUG_LAYOUT) Slog.i(TAG, String.format("mDock rect: (%d,%d - %d,%d)",
Craig Mautner69b08182012-09-05 13:07:13 -07003791 mDockLeft, mDockTop, mDockRight, mDockBottom));
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003792 updateSysUiVisibility |= layoutStatusBar(pf, df, of, vf, dcf, sysui, isKeyguardShowing);
John Spurlockad3e6cb2013-04-30 08:47:43 -04003793 if (updateSysUiVisibility) {
3794 updateSystemUiVisibilityLw();
3795 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003796 }
3797 }
3798
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003799 private boolean layoutStatusBar(Rect pf, Rect df, Rect of, Rect vf, Rect dcf, int sysui,
3800 boolean isKeyguardShowing) {
3801 // decide where the status bar goes ahead of time
3802 if (mStatusBar != null) {
3803 // apply any navigation bar insets
3804 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
3805 pf.top = df.top = of.top = mUnrestrictedScreenTop;
3806 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
3807 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight
3808 + mUnrestrictedScreenTop;
3809 vf.left = mStableLeft;
3810 vf.top = mStableTop;
3811 vf.right = mStableRight;
3812 vf.bottom = mStableBottom;
3813
3814 mStatusBarLayer = mStatusBar.getSurfaceLayer();
3815
3816 // Let the status bar determine its size.
3817 mStatusBar.computeFrameLw(pf /* parentFrame */, df /* displayFrame */,
3818 vf /* overlayFrame */, vf /* contentFrame */, vf /* visibleFrame */,
3819 dcf /* decorFrame */, vf /* stableFrame */, vf /* outsetFrame */);
3820
3821 // For layout, the status bar is always at the top with our fixed height.
3822 mStableTop = mUnrestrictedScreenTop + mStatusBarHeight;
3823
3824 boolean statusBarTransient = (sysui & View.STATUS_BAR_TRANSIENT) != 0;
3825 boolean statusBarTranslucent = (sysui
Jorim Jaggi4fa78922015-11-30 17:13:56 -08003826 & (View.STATUS_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSPARENT)) != 0;
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003827 if (!isKeyguardShowing) {
3828 statusBarTranslucent &= areTranslucentBarsAllowed();
3829 }
3830
3831 // If the status bar is hidden, we don't want to cause
3832 // windows behind it to scroll.
3833 if (mStatusBar.isVisibleLw() && !statusBarTransient) {
3834 // Status bar may go away, so the screen area it occupies
3835 // is available to apps but just covering them when the
3836 // status bar is visible.
3837 mDockTop = mUnrestrictedScreenTop + mStatusBarHeight;
3838
3839 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3840 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3841 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3842 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3843
3844 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar: " +
3845 String.format(
3846 "dock=[%d,%d][%d,%d] content=[%d,%d][%d,%d] cur=[%d,%d][%d,%d]",
3847 mDockLeft, mDockTop, mDockRight, mDockBottom,
3848 mContentLeft, mContentTop, mContentRight, mContentBottom,
3849 mCurLeft, mCurTop, mCurRight, mCurBottom));
3850 }
3851 if (mStatusBar.isVisibleLw() && !mStatusBar.isAnimatingLw()
3852 && !statusBarTransient && !statusBarTranslucent
3853 && !mStatusBarController.wasRecentlyTranslucent()) {
3854 // If the opaque status bar is currently requested to be visible,
3855 // and not in the process of animating on or off, then
3856 // we can tell the app that it is covered by it.
3857 mSystemTop = mUnrestrictedScreenTop + mStatusBarHeight;
3858 }
3859 if (mStatusBarController.checkHiddenLw()) {
3860 return true;
3861 }
3862 }
3863 return false;
3864 }
3865
3866 private boolean layoutNavigationBar(int displayWidth, int displayHeight, int displayRotation,
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003867 int uiMode, int overscanRight, int overscanBottom, Rect dcf, boolean navVisible,
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003868 boolean navTranslucent, boolean navAllowedHidden) {
3869 if (mNavigationBar != null) {
3870 boolean transientNavBarShowing = mNavigationBarController.isTransientShowing();
3871 // Force the navigation bar to its appropriate place and
3872 // size. We need to do this directly, instead of relying on
3873 // it to bubble up from the nav bar, because this needs to
3874 // change atomically with screen rotations.
Jorim Jaggi737af722015-12-31 10:42:27 +01003875 mNavigationBarOnBottom = isNavigationBarOnBottom(displayWidth, displayHeight);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003876 if (mNavigationBarOnBottom) {
3877 // It's a system nav bar or a portrait screen; nav bar goes on bottom.
3878 int top = displayHeight - overscanBottom
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003879 - getNavigationBarHeight(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003880 mTmpNavigationFrame.set(0, top, displayWidth, displayHeight - overscanBottom);
3881 mStableBottom = mStableFullscreenBottom = mTmpNavigationFrame.top;
3882 if (transientNavBarShowing) {
3883 mNavigationBarController.setBarShowingLw(true);
3884 } else if (navVisible) {
3885 mNavigationBarController.setBarShowingLw(true);
3886 mDockBottom = mTmpNavigationFrame.top;
3887 mRestrictedScreenHeight = mDockBottom - mRestrictedScreenTop;
3888 mRestrictedOverscanScreenHeight = mDockBottom - mRestrictedOverscanScreenTop;
3889 } else {
3890 // We currently want to hide the navigation UI.
3891 mNavigationBarController.setBarShowingLw(false);
3892 }
3893 if (navVisible && !navTranslucent && !navAllowedHidden
3894 && !mNavigationBar.isAnimatingLw()
3895 && !mNavigationBarController.wasRecentlyTranslucent()) {
3896 // If the opaque nav bar is currently requested to be visible,
3897 // and not in the process of animating on or off, then
3898 // we can tell the app that it is covered by it.
3899 mSystemBottom = mTmpNavigationFrame.top;
3900 }
3901 } else {
3902 // Landscape screen; nav bar goes to the right.
3903 int left = displayWidth - overscanRight
Sriram Viswanathan9ebbe6a2015-11-16 17:59:22 -08003904 - getNavigationBarWidth(displayRotation, uiMode);
Filip Gruszczynski83dd9552015-09-17 17:50:36 -07003905 mTmpNavigationFrame.set(left, 0, displayWidth - overscanRight, displayHeight);
3906 mStableRight = mStableFullscreenRight = mTmpNavigationFrame.left;
3907 if (transientNavBarShowing) {
3908 mNavigationBarController.setBarShowingLw(true);
3909 } else if (navVisible) {
3910 mNavigationBarController.setBarShowingLw(true);
3911 mDockRight = mTmpNavigationFrame.left;
3912 mRestrictedScreenWidth = mDockRight - mRestrictedScreenLeft;
3913 mRestrictedOverscanScreenWidth = mDockRight - mRestrictedOverscanScreenLeft;
3914 } else {
3915 // We currently want to hide the navigation UI.
3916 mNavigationBarController.setBarShowingLw(false);
3917 }
3918 if (navVisible && !navTranslucent && !navAllowedHidden
3919 && !mNavigationBar.isAnimatingLw()
3920 && !mNavigationBarController.wasRecentlyTranslucent()) {
3921 // If the nav bar is currently requested to be visible,
3922 // and not in the process of animating on or off, then
3923 // we can tell the app that it is covered by it.
3924 mSystemRight = mTmpNavigationFrame.left;
3925 }
3926 }
3927 // Make sure the content and current rectangles are updated to
3928 // account for the restrictions from the navigation bar.
3929 mContentTop = mVoiceContentTop = mCurTop = mDockTop;
3930 mContentBottom = mVoiceContentBottom = mCurBottom = mDockBottom;
3931 mContentLeft = mVoiceContentLeft = mCurLeft = mDockLeft;
3932 mContentRight = mVoiceContentRight = mCurRight = mDockRight;
3933 mStatusBarLayer = mNavigationBar.getSurfaceLayer();
3934 // And compute the final frame.
3935 mNavigationBar.computeFrameLw(mTmpNavigationFrame, mTmpNavigationFrame,
3936 mTmpNavigationFrame, mTmpNavigationFrame, mTmpNavigationFrame, dcf,
3937 mTmpNavigationFrame, mTmpNavigationFrame);
3938 if (DEBUG_LAYOUT) Slog.i(TAG, "mNavigationBar frame: " + mTmpNavigationFrame);
3939 if (mNavigationBarController.checkHiddenLw()) {
3940 return true;
3941 }
3942 }
3943 return false;
3944 }
3945
Jorim Jaggi737af722015-12-31 10:42:27 +01003946 private boolean isNavigationBarOnBottom(int displayWidth, int displayHeight) {
3947 return !mNavigationBarCanMove || displayWidth < displayHeight;
3948 }
3949
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003950 /** {@inheritDoc} */
Craig Mautner967212c2013-04-13 21:10:58 -07003951 @Override
John Spurlock46646232013-09-30 22:32:42 -04003952 public int getSystemDecorLayerLw() {
Bryce Lee2ed3e5f2015-04-01 22:09:19 +00003953 if (mStatusBar != null && mStatusBar.isVisibleLw()) {
3954 return mStatusBar.getSurfaceLayer();
3955 }
3956
3957 if (mNavigationBar != null && mNavigationBar.isVisibleLw()) {
3958 return mNavigationBar.getSurfaceLayer();
3959 }
3960
Dianne Hackborn85afd1b2012-05-13 13:31:06 -07003961 return 0;
3962 }
3963
Craig Mautner967212c2013-04-13 21:10:58 -07003964 @Override
3965 public void getContentRectLw(Rect r) {
3966 r.set(mContentLeft, mContentTop, mContentRight, mContentBottom);
3967 }
3968
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003969 void setAttachedWindowFrames(WindowState win, int fl, int adjust, WindowState attached,
3970 boolean insetDecors, Rect pf, Rect df, Rect of, Rect cf, Rect vf) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003971 if (win.getSurfaceLayer() > mDockLayer && attached.getSurfaceLayer() < mDockLayer) {
3972 // Here's a special case: if this attached window is a panel that is
3973 // above the dock window, and the window it is attached to is below
3974 // the dock window, then the frames we computed for the window it is
3975 // attached to can not be used because the dock is effectively part
3976 // of the underlying window and the attached window is floating on top
3977 // of the whole thing. So, we ignore the attached window and explicitly
3978 // compute the frames that would be appropriate without the dock.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08003979 df.left = of.left = cf.left = vf.left = mDockLeft;
3980 df.top = of.top = cf.top = vf.top = mDockTop;
3981 df.right = of.right = cf.right = vf.right = mDockRight;
3982 df.bottom = of.bottom = cf.bottom = vf.bottom = mDockBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003983 } else {
3984 // The effective display frame of the attached window depends on
3985 // whether it is taking care of insetting its content. If not,
3986 // we need to use the parent's content frame so that the entire
3987 // window is positioned within that content. Otherwise we can use
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003988 // the overscan frame and let the attached window take care of
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003989 // positioning its content appropriately.
Dianne Hackborndea3ef72010-10-28 14:24:22 -07003990 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Wale Ogunwale393b1c12014-10-18 16:22:01 -07003991 // Set the content frame of the attached window to the parent's decor frame
3992 // (same as content frame when IME isn't present) if specifically requested by
3993 // setting {@link WindowManager.LayoutParams#FLAG_LAYOUT_ATTACHED_IN_DECOR} flag.
3994 // Otherwise, use the overscan frame.
3995 cf.set((fl & FLAG_LAYOUT_ATTACHED_IN_DECOR) != 0
3996 ? attached.getContentFrameLw() : attached.getOverscanFrameLw());
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08003997 } else {
3998 // If the window is resizing, then we want to base the content
3999 // frame on our attached content frame to resize... however,
4000 // things can be tricky if the attached window is NOT in resize
4001 // mode, in which case its content frame will be larger.
4002 // Ungh. So to deal with that, make sure the content frame
4003 // we end up using is not covering the IM dock.
4004 cf.set(attached.getContentFrameLw());
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004005 if (attached.isVoiceInteraction()) {
4006 if (cf.left < mVoiceContentLeft) cf.left = mVoiceContentLeft;
4007 if (cf.top < mVoiceContentTop) cf.top = mVoiceContentTop;
4008 if (cf.right > mVoiceContentRight) cf.right = mVoiceContentRight;
4009 if (cf.bottom > mVoiceContentBottom) cf.bottom = mVoiceContentBottom;
4010 } else if (attached.getSurfaceLayer() < mDockLayer) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004011 if (cf.left < mContentLeft) cf.left = mContentLeft;
4012 if (cf.top < mContentTop) cf.top = mContentTop;
4013 if (cf.right > mContentRight) cf.right = mContentRight;
4014 if (cf.bottom > mContentBottom) cf.bottom = mContentBottom;
4015 }
4016 }
4017 df.set(insetDecors ? attached.getDisplayFrameLw() : cf);
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004018 of.set(insetDecors ? attached.getOverscanFrameLw() : cf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004019 vf.set(attached.getVisibleFrameLw());
4020 }
4021 // The LAYOUT_IN_SCREEN flag is used to determine whether the attached
4022 // window should be positioned relative to its parent or the entire
4023 // screen.
4024 pf.set((fl & FLAG_LAYOUT_IN_SCREEN) == 0
4025 ? attached.getFrameLw() : df);
4026 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004027
4028 private void applyStableConstraints(int sysui, int fl, Rect r) {
4029 if ((sysui & View.SYSTEM_UI_FLAG_LAYOUT_STABLE) != 0) {
4030 // If app is requesting a stable layout, don't let the
4031 // content insets go below the stable values.
4032 if ((fl & FLAG_FULLSCREEN) != 0) {
4033 if (r.left < mStableFullscreenLeft) r.left = mStableFullscreenLeft;
4034 if (r.top < mStableFullscreenTop) r.top = mStableFullscreenTop;
4035 if (r.right > mStableFullscreenRight) r.right = mStableFullscreenRight;
4036 if (r.bottom > mStableFullscreenBottom) r.bottom = mStableFullscreenBottom;
4037 } else {
4038 if (r.left < mStableLeft) r.left = mStableLeft;
4039 if (r.top < mStableTop) r.top = mStableTop;
4040 if (r.right > mStableRight) r.right = mStableRight;
4041 if (r.bottom > mStableBottom) r.bottom = mStableBottom;
4042 }
4043 }
4044 }
4045
Jorim Jaggiaa806142015-05-20 18:04:16 -07004046 private boolean canReceiveInput(WindowState win) {
4047 boolean notFocusable =
4048 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE) != 0;
4049 boolean altFocusableIm =
4050 (win.getAttrs().flags & WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM) != 0;
4051 boolean notFocusableForIm = notFocusable ^ altFocusableIm;
4052 return !notFocusableForIm;
4053 }
4054
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004055 /** {@inheritDoc} */
Craig Mautner69b08182012-09-05 13:07:13 -07004056 @Override
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004057 public void layoutWindowLw(WindowState win, WindowState attached) {
Jorim Jaggiaa806142015-05-20 18:04:16 -07004058 // We've already done the navigation bar and status bar. If the status bar can receive
4059 // input, we need to layout it again to accomodate for the IME window.
4060 if ((win == mStatusBar && !canReceiveInput(win)) || win == mNavigationBar) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004061 return;
4062 }
Jorim Jaggiaa806142015-05-20 18:04:16 -07004063 final WindowManager.LayoutParams attrs = win.getAttrs();
Craig Mautner69b08182012-09-05 13:07:13 -07004064 final boolean isDefaultDisplay = win.isDefaultDisplay();
4065 final boolean needsToOffsetInputMethodTarget = isDefaultDisplay &&
satok1bc0a492012-04-25 22:47:12 +09004066 (win == mLastInputMethodTargetWindow && mLastInputMethodWindow != null);
4067 if (needsToOffsetInputMethodTarget) {
Craig Mautnereda67292013-04-28 13:50:14 -07004068 if (DEBUG_LAYOUT) Slog.i(TAG, "Offset ime target window by the last ime window state");
satok1bc0a492012-04-25 22:47:12 +09004069 offsetInputMethodWindowLw(mLastInputMethodWindow);
4070 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004071
John Spurlockc6d1c602014-01-17 15:22:06 -05004072 final int fl = PolicyControl.getWindowFlags(win, attrs);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004073 final int sim = attrs.softInputMode;
John Spurlock1db8b682014-02-18 11:18:59 -05004074 final int sysUiFl = PolicyControl.getSystemUiVisibility(win, null);
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004075
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004076 final Rect pf = mTmpParentFrame;
4077 final Rect df = mTmpDisplayFrame;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004078 final Rect of = mTmpOverscanFrame;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004079 final Rect cf = mTmpContentFrame;
4080 final Rect vf = mTmpVisibleFrame;
John Spurlock46646232013-09-30 22:32:42 -04004081 final Rect dcf = mTmpDecorFrame;
Adrian Roosfa104232014-06-20 16:10:14 -07004082 final Rect sf = mTmpStableFrame;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004083 Rect osf = null;
John Spurlock46646232013-09-30 22:32:42 -04004084 dcf.setEmpty();
Craig Mautner69b08182012-09-05 13:07:13 -07004085
4086 final boolean hasNavBar = (isDefaultDisplay && mHasNavigationBar
Daniel Sandler36412a72011-08-04 09:35:13 -04004087 && mNavigationBar != null && mNavigationBar.isVisibleLw());
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004088
Craig Mautnerf683b562012-10-02 11:10:57 -07004089 final int adjust = sim & SOFT_INPUT_MASK_ADJUST;
4090
Adrian Roosfa104232014-06-20 16:10:14 -07004091 if (isDefaultDisplay) {
4092 sf.set(mStableLeft, mStableTop, mStableRight, mStableBottom);
4093 } else {
4094 sf.set(mOverscanLeft, mOverscanTop, mOverscanRight, mOverscanBottom);
4095 }
4096
Craig Mautner69b08182012-09-05 13:07:13 -07004097 if (!isDefaultDisplay) {
4098 if (attached != null) {
4099 // If this window is attached to another, our display
4100 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004101 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
Craig Mautner69b08182012-09-05 13:07:13 -07004102 } else {
4103 // Give the window full screen.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004104 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4105 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4106 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004107 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004108 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004109 = mOverscanScreenTop + mOverscanScreenHeight;
Craig Mautner69b08182012-09-05 13:07:13 -07004110 }
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004111 } else if (attrs.type == TYPE_INPUT_METHOD) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004112 pf.left = df.left = of.left = cf.left = vf.left = mDockLeft;
4113 pf.top = df.top = of.top = cf.top = vf.top = mDockTop;
4114 pf.right = df.right = of.right = cf.right = vf.right = mDockRight;
John Spurlockc68d5772013-10-08 11:47:58 -04004115 // IM dock windows layout below the nav bar...
John Spurlock57beb3b2013-10-10 10:27:44 -04004116 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlockc68d5772013-10-08 11:47:58 -04004117 // ...with content insets above the nav bar
4118 cf.bottom = vf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004119 // IM dock windows always go to the bottom of the screen.
4120 attrs.gravity = Gravity.BOTTOM;
4121 mDockLayer = win.getSurfaceLayer();
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004122 } else if (attrs.type == TYPE_VOICE_INTERACTION) {
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004123 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004124 pf.top = df.top = of.top = mUnrestrictedScreenTop;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004125 pf.right = df.right = of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4126 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004127 cf.bottom = vf.bottom = mStableBottom;
Stefan Kuhne2f280d062015-06-18 07:20:33 -10004128 // Note: In Phone landscape mode, the button bar should also be excluded.
4129 cf.right = vf.right = mStableRight;
4130 cf.left = vf.left = mStableLeft;
Jorim Jaggi225d3b52015-04-01 11:18:57 -07004131 cf.top = vf.top = mStableTop;
Jorim Jaggiaa806142015-05-20 18:04:16 -07004132 } else if (win == mStatusBar) {
Jorim Jaggie0700182014-08-21 01:12:37 +02004133 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4134 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4135 pf.right = df.right = of.right = mUnrestrictedScreenWidth + mUnrestrictedScreenLeft;
4136 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenHeight + mUnrestrictedScreenTop;
4137 cf.left = vf.left = mStableLeft;
4138 cf.top = vf.top = mStableTop;
4139 cf.right = vf.right = mStableRight;
4140 vf.bottom = mStableBottom;
Adrian Roosdc5b4532016-01-06 20:49:41 +01004141
4142 if (adjust == SOFT_INPUT_ADJUST_RESIZE) {
4143 cf.bottom = mContentBottom;
4144 } else {
4145 cf.bottom = mDockBottom;
4146 vf.bottom = mContentBottom;
4147 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004148 } else {
John Spurlock46646232013-09-30 22:32:42 -04004149
4150 // Default policy decor for the default display
4151 dcf.left = mSystemLeft;
4152 dcf.top = mSystemTop;
4153 dcf.right = mSystemRight;
4154 dcf.bottom = mSystemBottom;
John Spurlockbd957402013-10-03 11:38:39 -04004155 final boolean inheritTranslucentDecor = (attrs.privateFlags
4156 & WindowManager.LayoutParams.PRIVATE_FLAG_INHERIT_TRANSLUCENT_DECOR) != 0;
John Spurlock65567d42013-10-08 10:08:32 -04004157 final boolean isAppWindow =
4158 attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW &&
4159 attrs.type <= WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
4160 final boolean topAtRest =
4161 win == mTopFullscreenOpaqueWindowState && !win.isAnimatingLw();
4162 if (isAppWindow && !inheritTranslucentDecor && !topAtRest) {
John Spurlockbd957402013-10-03 11:38:39 -04004163 if ((sysUiFl & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0
4164 && (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004165 && (fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS) == 0
4166 && (fl & WindowManager.LayoutParams.
Jorim Jaggi4fa78922015-11-30 17:13:56 -08004167 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0
4168 && !mForceWindowDrawsStatusBarBackground) {
John Spurlock46646232013-09-30 22:32:42 -04004169 // Ensure policy decor includes status bar
4170 dcf.top = mStableTop;
4171 }
John Spurlockbd957402013-10-03 11:38:39 -04004172 if ((fl & WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) == 0
Adrian Roosea562512014-05-05 13:33:03 +02004173 && (sysUiFl & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
4174 && (fl & WindowManager.LayoutParams.
4175 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) == 0) {
John Spurlock46646232013-09-30 22:32:42 -04004176 // Ensure policy decor includes navigation bar
4177 dcf.bottom = mStableBottom;
4178 dcf.right = mStableRight;
4179 }
4180 }
4181
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004182 if ((fl & (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR))
4183 == (FLAG_LAYOUT_IN_SCREEN | FLAG_LAYOUT_INSET_DECOR)) {
RoboErik8a2cfc32014-05-16 11:19:38 -07004184 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004185 + "): IN_SCREEN, INSET_DECOR");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004186 // This is the case for a normal activity window: we want it
4187 // to cover all of the screen space, and it can take care of
4188 // moving its contents to account for screen decorations that
4189 // intrude into that space.
4190 if (attached != null) {
4191 // If this window is attached to another, our display
4192 // frame is the same as the one we are attached to.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004193 setAttachedWindowFrames(win, fl, adjust, attached, true, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004194 } else {
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004195 if (attrs.type == TYPE_STATUS_BAR_PANEL
4196 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL) {
Joe Onorato29fc2c92010-11-24 10:26:50 -08004197 // Status bar panels are the only windows who can go on top of
4198 // the status bar. They are protected by the STATUS_BAR_SERVICE
4199 // permission, so they have the same privileges as the status
4200 // bar itself.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004201 //
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004202 // However, they should still dodge the navigation bar if it exists.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004203
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004204 pf.left = df.left = of.left = hasNavBar
4205 ? mDockLeft : mUnrestrictedScreenLeft;
4206 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4207 pf.right = df.right = of.right = hasNavBar
4208 ? mRestrictedScreenLeft+mRestrictedScreenWidth
4209 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4210 pf.bottom = df.bottom = of.bottom = hasNavBar
4211 ? mRestrictedScreenTop+mRestrictedScreenHeight
4212 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004213
Craig Mautnereda67292013-04-28 13:50:14 -07004214 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004215 "Laying out status bar window: (%d,%d - %d,%d)",
4216 pf.left, pf.top, pf.right, pf.bottom));
John Spurlock46646232013-09-30 22:32:42 -04004217 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004218 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4219 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4220 // Asking to layout into the overscan region, so give it that pure
4221 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004222 pf.left = df.left = of.left = mOverscanScreenLeft;
4223 pf.top = df.top = of.top = mOverscanScreenTop;
4224 pf.right = df.right = of.right = mOverscanScreenLeft + mOverscanScreenWidth;
4225 pf.bottom = df.bottom = of.bottom = mOverscanScreenTop
4226 + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004227 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004228 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004229 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4230 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004231 // Asking for layout as if the nav bar is hidden, lets the
Dianne Hackbornc652de82013-02-15 16:32:56 -08004232 // application extend into the unrestricted overscan screen area. We
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004233 // only do this for application windows to ensure no window that
4234 // can be above the nav bar can do this.
Dianne Hackborn313440842013-02-19 19:22:59 -08004235 pf.left = df.left = mOverscanScreenLeft;
4236 pf.top = df.top = mOverscanScreenTop;
4237 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4238 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004239 // We need to tell the app about where the frame inside the overscan
4240 // is, so it can inset its content by that amount -- it didn't ask
4241 // to actually extend itself into the overscan region.
4242 of.left = mUnrestrictedScreenLeft;
4243 of.top = mUnrestrictedScreenTop;
4244 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4245 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004246 } else {
Dianne Hackborn313440842013-02-19 19:22:59 -08004247 pf.left = df.left = mRestrictedOverscanScreenLeft;
4248 pf.top = df.top = mRestrictedOverscanScreenTop;
4249 pf.right = df.right = mRestrictedOverscanScreenLeft
4250 + mRestrictedOverscanScreenWidth;
4251 pf.bottom = df.bottom = mRestrictedOverscanScreenTop
4252 + mRestrictedOverscanScreenHeight;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004253 // We need to tell the app about where the frame inside the overscan
4254 // is, so it can inset its content by that amount -- it didn't ask
4255 // to actually extend itself into the overscan region.
4256 of.left = mUnrestrictedScreenLeft;
4257 of.top = mUnrestrictedScreenTop;
4258 of.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4259 of.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004260 }
Craig Mautner69b08182012-09-05 13:07:13 -07004261
John Spurlock46646232013-09-30 22:32:42 -04004262 if ((fl & FLAG_FULLSCREEN) == 0) {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004263 if (win.isVoiceInteraction()) {
4264 cf.left = mVoiceContentLeft;
4265 cf.top = mVoiceContentTop;
4266 cf.right = mVoiceContentRight;
4267 cf.bottom = mVoiceContentBottom;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004268 } else {
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004269 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4270 cf.left = mDockLeft;
4271 cf.top = mDockTop;
4272 cf.right = mDockRight;
4273 cf.bottom = mDockBottom;
4274 } else {
4275 cf.left = mContentLeft;
4276 cf.top = mContentTop;
4277 cf.right = mContentRight;
4278 cf.bottom = mContentBottom;
4279 }
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004280 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004281 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004282 // Full screen windows are always given a layout that is as if the
4283 // status bar and other transient decors are gone. This is to avoid
4284 // bad states when moving from a window that is not hding the
4285 // status bar to one that is.
4286 cf.left = mRestrictedScreenLeft;
4287 cf.top = mRestrictedScreenTop;
4288 cf.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4289 cf.bottom = mRestrictedScreenTop + mRestrictedScreenHeight;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004290 }
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004291 applyStableConstraints(sysUiFl, fl, cf);
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004292 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4293 vf.left = mCurLeft;
4294 vf.top = mCurTop;
4295 vf.right = mCurRight;
4296 vf.bottom = mCurBottom;
4297 } else {
4298 vf.set(cf);
4299 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004300 }
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004301 } else if ((fl & FLAG_LAYOUT_IN_SCREEN) != 0 || (sysUiFl
4302 & (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
4303 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION)) != 0) {
Craig Mautnereda67292013-04-28 13:50:14 -07004304 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4305 "): IN_SCREEN");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004306 // A window that has requested to fill the entire screen just
4307 // gets everything, period.
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004308 if (attrs.type == TYPE_STATUS_BAR_PANEL
John Spurlock67a0f852015-06-15 15:35:47 -04004309 || attrs.type == TYPE_STATUS_BAR_SUB_PANEL
4310 || attrs.type == TYPE_VOLUME_OVERLAY) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004311 pf.left = df.left = of.left = cf.left = hasNavBar
4312 ? mDockLeft : mUnrestrictedScreenLeft;
4313 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4314 pf.right = df.right = of.right = cf.right = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004315 ? mRestrictedScreenLeft+mRestrictedScreenWidth
Dianne Hackbornc652de82013-02-15 16:32:56 -08004316 : mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004317 pf.bottom = df.bottom = of.bottom = cf.bottom = hasNavBar
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004318 ? mRestrictedScreenTop+mRestrictedScreenHeight
Dianne Hackbornc652de82013-02-15 16:32:56 -08004319 : mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004320 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler36412a72011-08-04 09:35:13 -04004321 "Laying out IN_SCREEN status bar window: (%d,%d - %d,%d)",
4322 pf.left, pf.top, pf.right, pf.bottom));
Jim Millere898ac52012-04-06 17:10:57 -07004323 } else if (attrs.type == TYPE_NAVIGATION_BAR
4324 || attrs.type == TYPE_NAVIGATION_BAR_PANEL) {
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004325 // The navigation bar has Real Ultimate Power.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004326 pf.left = df.left = of.left = mUnrestrictedScreenLeft;
4327 pf.top = df.top = of.top = mUnrestrictedScreenTop;
4328 pf.right = df.right = of.right = mUnrestrictedScreenLeft
4329 + mUnrestrictedScreenWidth;
4330 pf.bottom = df.bottom = of.bottom = mUnrestrictedScreenTop
4331 + mUnrestrictedScreenHeight;
Craig Mautnereda67292013-04-28 13:50:14 -07004332 if (DEBUG_LAYOUT) Slog.v(TAG, String.format(
Daniel Sandler8e8b4152011-07-21 01:16:43 -04004333 "Laying out navigation bar window: (%d,%d - %d,%d)",
4334 pf.left, pf.top, pf.right, pf.bottom));
Dianne Hackborn01011c32012-02-21 13:54:21 -08004335 } else if ((attrs.type == TYPE_SECURE_SYSTEM_OVERLAY
4336 || attrs.type == TYPE_BOOT_PROGRESS)
Jeff Brownbfcb60a2011-09-08 18:51:14 -07004337 && ((fl & FLAG_FULLSCREEN) != 0)) {
4338 // Fullscreen secure system overlays get what they ask for.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004339 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4340 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4341 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4342 + mOverscanScreenWidth;
4343 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4344 + mOverscanScreenHeight;
Craig Mautner165be0c2015-01-27 15:16:58 -08004345 } else if (attrs.type == TYPE_BOOT_PROGRESS) {
Dianne Hackborn01011c32012-02-21 13:54:21 -08004346 // Boot progress screen always covers entire display.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004347 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4348 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4349 pf.right = df.right = of.right = cf.right = mOverscanScreenLeft
4350 + mOverscanScreenWidth;
4351 pf.bottom = df.bottom = of.bottom = cf.bottom = mOverscanScreenTop
4352 + mOverscanScreenHeight;
John Spurlockef4adae2013-08-26 17:58:58 -04004353 } else if (attrs.type == TYPE_WALLPAPER) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004354 // The wallpaper also has Real Ultimate Power, but we want to tell
4355 // it about the overscan area.
4356 pf.left = df.left = mOverscanScreenLeft;
4357 pf.top = df.top = mOverscanScreenTop;
4358 pf.right = df.right = mOverscanScreenLeft + mOverscanScreenWidth;
4359 pf.bottom = df.bottom = mOverscanScreenTop + mOverscanScreenHeight;
4360 of.left = cf.left = mUnrestrictedScreenLeft;
4361 of.top = cf.top = mUnrestrictedScreenTop;
4362 of.right = cf.right = mUnrestrictedScreenLeft + mUnrestrictedScreenWidth;
4363 of.bottom = cf.bottom = mUnrestrictedScreenTop + mUnrestrictedScreenHeight;
John Spurlock46646232013-09-30 22:32:42 -04004364 } else if ((fl & FLAG_LAYOUT_IN_OVERSCAN) != 0
Dianne Hackbornc652de82013-02-15 16:32:56 -08004365 && attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4366 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
4367 // Asking to layout into the overscan region, so give it that pure
4368 // unrestricted area.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004369 pf.left = df.left = of.left = cf.left = mOverscanScreenLeft;
4370 pf.top = df.top = of.top = cf.top = mOverscanScreenTop;
4371 pf.right = df.right = of.right = cf.right
Dianne Hackbornc652de82013-02-15 16:32:56 -08004372 = mOverscanScreenLeft + mOverscanScreenWidth;
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004373 pf.bottom = df.bottom = of.bottom = cf.bottom
Dianne Hackbornc652de82013-02-15 16:32:56 -08004374 = mOverscanScreenTop + mOverscanScreenHeight;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07004375 } else if (canHideNavigationBar()
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004376 && (sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION) != 0
Craig Mautnerbeac1062014-06-03 14:38:57 -07004377 && (attrs.type == TYPE_STATUS_BAR
4378 || attrs.type == TYPE_TOAST
Jorim Jaggi81fe2d12015-12-21 14:45:18 +01004379 || attrs.type == TYPE_DOCK_DIVIDER
Jorim Jaggi2fdeeab2015-04-01 15:13:03 -07004380 || attrs.type == TYPE_VOICE_INTERACTION_STARTING
John Spurlock34e13d92013-08-10 06:52:28 -04004381 || (attrs.type >= WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW
4382 && attrs.type <= WindowManager.LayoutParams.LAST_SUB_WINDOW))) {
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004383 // Asking for layout as if the nav bar is hidden, lets the
4384 // application extend into the unrestricted screen area. We
John Spurlock34e13d92013-08-10 06:52:28 -04004385 // only do this for application windows (or toasts) to ensure no window that
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004386 // can be above the nav bar can do this.
4387 // XXX This assumes that an app asking for this will also
4388 // ask for layout in only content. We can't currently figure out
4389 // what the screen would be if only laying out to hide the nav bar.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004390 pf.left = df.left = of.left = cf.left = mUnrestrictedScreenLeft;
4391 pf.top = df.top = of.top = cf.top = mUnrestrictedScreenTop;
4392 pf.right = df.right = of.right = cf.right = mUnrestrictedScreenLeft
4393 + mUnrestrictedScreenWidth;
4394 pf.bottom = df.bottom = of.bottom = cf.bottom = mUnrestrictedScreenTop
4395 + mUnrestrictedScreenHeight;
Jorim Jaggi9f6798a2016-02-10 22:16:06 -08004396 } else if ((sysUiFl & View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) != 0) {
4397 pf.left = df.left = of.left = mRestrictedScreenLeft;
4398 pf.top = df.top = of.top = mRestrictedScreenTop;
4399 pf.right = df.right = of.right = mRestrictedScreenLeft + mRestrictedScreenWidth;
4400 pf.bottom = df.bottom = of.bottom = mRestrictedScreenTop
4401 + mRestrictedScreenHeight;
4402 if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
4403 cf.left = mDockLeft;
4404 cf.top = mDockTop;
4405 cf.right = mDockRight;
4406 cf.bottom = mDockBottom;
4407 } else {
4408 cf.left = mContentLeft;
4409 cf.top = mContentTop;
4410 cf.right = mContentRight;
4411 cf.bottom = mContentBottom;
4412 }
Joe Onorato29fc2c92010-11-24 10:26:50 -08004413 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004414 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4415 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4416 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4417 + mRestrictedScreenWidth;
4418 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4419 + mRestrictedScreenHeight;
Joe Onorato29fc2c92010-11-24 10:26:50 -08004420 }
Craig Mautner69b08182012-09-05 13:07:13 -07004421
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07004422 applyStableConstraints(sysUiFl, fl, cf);
Craig Mautner69b08182012-09-05 13:07:13 -07004423
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004424 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4425 vf.left = mCurLeft;
4426 vf.top = mCurTop;
4427 vf.right = mCurRight;
4428 vf.bottom = mCurBottom;
4429 } else {
4430 vf.set(cf);
4431 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004432 } else if (attached != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004433 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4434 "): attached to " + attached);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004435 // A child window should be placed inside of the same visible
4436 // frame that its parent had.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004437 setAttachedWindowFrames(win, fl, adjust, attached, false, pf, df, of, cf, vf);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004438 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004439 if (DEBUG_LAYOUT) Slog.v(TAG, "layoutWindowLw(" + attrs.getTitle() +
4440 "): normal window");
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004441 // Otherwise, a normal window must be placed inside the content
4442 // of all screen decorations.
John Spurlock67a0f852015-06-15 15:35:47 -04004443 if (attrs.type == TYPE_STATUS_BAR_PANEL || attrs.type == TYPE_VOLUME_OVERLAY) {
4444 // Status bar panels and the volume dialog are the only windows who can go on
4445 // top of the status bar. They are protected by the STATUS_BAR_SERVICE
Dianne Hackborna239c842011-06-01 12:28:20 -07004446 // permission, so they have the same privileges as the status
4447 // bar itself.
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004448 pf.left = df.left = of.left = cf.left = mRestrictedScreenLeft;
4449 pf.top = df.top = of.top = cf.top = mRestrictedScreenTop;
4450 pf.right = df.right = of.right = cf.right = mRestrictedScreenLeft
4451 + mRestrictedScreenWidth;
4452 pf.bottom = df.bottom = of.bottom = cf.bottom = mRestrictedScreenTop
4453 + mRestrictedScreenHeight;
John Spurlock67a0f852015-06-15 15:35:47 -04004454 } else if (attrs.type == TYPE_TOAST || attrs.type == TYPE_SYSTEM_ALERT) {
John Spurlock414c1f02013-12-04 13:47:36 -05004455 // These dialogs are stable to interim decor changes.
John Spurlockbd957402013-10-03 11:38:39 -04004456 pf.left = df.left = of.left = cf.left = mStableLeft;
4457 pf.top = df.top = of.top = cf.top = mStableTop;
4458 pf.right = df.right = of.right = cf.right = mStableRight;
4459 pf.bottom = df.bottom = of.bottom = cf.bottom = mStableBottom;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004460 } else {
Dianne Hackborna239c842011-06-01 12:28:20 -07004461 pf.left = mContentLeft;
4462 pf.top = mContentTop;
4463 pf.right = mContentRight;
4464 pf.bottom = mContentBottom;
Dianne Hackborn20d94742014-05-29 18:35:45 -07004465 if (win.isVoiceInteraction()) {
4466 df.left = of.left = cf.left = mVoiceContentLeft;
4467 df.top = of.top = cf.top = mVoiceContentTop;
4468 df.right = of.right = cf.right = mVoiceContentRight;
4469 df.bottom = of.bottom = cf.bottom = mVoiceContentBottom;
4470 } else if (adjust != SOFT_INPUT_ADJUST_RESIZE) {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004471 df.left = of.left = cf.left = mDockLeft;
4472 df.top = of.top = cf.top = mDockTop;
4473 df.right = of.right = cf.right = mDockRight;
4474 df.bottom = of.bottom = cf.bottom = mDockBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004475 } else {
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004476 df.left = of.left = cf.left = mContentLeft;
4477 df.top = of.top = cf.top = mContentTop;
4478 df.right = of.right = cf.right = mContentRight;
4479 df.bottom = of.bottom = cf.bottom = mContentBottom;
Dianne Hackborna239c842011-06-01 12:28:20 -07004480 }
4481 if (adjust != SOFT_INPUT_ADJUST_NOTHING) {
4482 vf.left = mCurLeft;
4483 vf.top = mCurTop;
4484 vf.right = mCurRight;
4485 vf.bottom = mCurBottom;
4486 } else {
4487 vf.set(cf);
4488 }
Dianne Hackborndea3ef72010-10-28 14:24:22 -07004489 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004490 }
4491 }
Craig Mautner69b08182012-09-05 13:07:13 -07004492
Craig Mautnerb816bed2013-07-23 10:26:17 -07004493 // TYPE_SYSTEM_ERROR is above the NavigationBar so it can't be allowed to extend over it.
4494 if ((fl & FLAG_LAYOUT_NO_LIMITS) != 0 && attrs.type != TYPE_SYSTEM_ERROR) {
Dianne Hackborn067e5f62014-09-07 23:14:30 -07004495 df.left = df.top = -10000;
4496 df.right = df.bottom = 10000;
4497 if (attrs.type != TYPE_WALLPAPER) {
4498 of.left = of.top = cf.left = cf.top = vf.left = vf.top = -10000;
4499 of.right = of.bottom = cf.right = cf.bottom = vf.right = vf.bottom = 10000;
4500 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004501 }
4502
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004503 // If the device has a chin (e.g. some watches), a dead area at the bottom of the screen we
4504 // need to provide information to the clients that want to pretend that you can draw there.
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004505 // We only want to apply outsets to certain types of windows. For example, we never want to
4506 // apply the outsets to floating dialogs, because they wouldn't make sense there.
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004507 final boolean useOutsets = shouldUseOutsets(attrs, fl);
Filip Gruszczynskib0c673b2015-06-05 09:43:06 -07004508 if (isDefaultDisplay && useOutsets) {
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004509 osf = mTmpOutsetFrame;
4510 osf.set(cf.left, cf.top, cf.right, cf.bottom);
4511 int outset = ScreenShapeHelper.getWindowOutsetBottomPx(mContext.getResources());
4512 if (outset > 0) {
Filip Gruszczynski2987f612015-06-30 15:03:30 -07004513 int rotation = mDisplayRotation;
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004514 if (rotation == Surface.ROTATION_0) {
4515 osf.bottom += outset;
4516 } else if (rotation == Surface.ROTATION_90) {
4517 osf.right += outset;
4518 } else if (rotation == Surface.ROTATION_180) {
4519 osf.top -= outset;
4520 } else if (rotation == Surface.ROTATION_270) {
4521 osf.left -= outset;
4522 }
4523 if (DEBUG_LAYOUT) Slog.v(TAG, "applying bottom outset of " + outset
4524 + " with rotation " + rotation + ", result: " + osf);
4525 }
4526 }
4527
Craig Mautnereda67292013-04-28 13:50:14 -07004528 if (DEBUG_LAYOUT) Slog.v(TAG, "Compute frame " + attrs.getTitle()
The Android Open Source Project11267662009-03-18 17:39:47 -07004529 + ": sim=#" + Integer.toHexString(sim)
RoboErik8a2cfc32014-05-16 11:19:38 -07004530 + " attach=" + attached + " type=" + attrs.type
Daniel Sandler8956dbb2011-04-22 07:55:02 -04004531 + String.format(" flags=0x%08x", fl)
The Android Open Source Project11267662009-03-18 17:39:47 -07004532 + " pf=" + pf.toShortString() + " df=" + df.toShortString()
Dianne Hackbornc4aad012013-02-22 15:05:25 -08004533 + " of=" + of.toShortString()
John Spurlock46646232013-09-30 22:32:42 -04004534 + " cf=" + cf.toShortString() + " vf=" + vf.toShortString()
Adrian Roosfa104232014-06-20 16:10:14 -07004535 + " dcf=" + dcf.toShortString()
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004536 + " sf=" + sf.toShortString()
4537 + " osf=" + (osf == null ? "null" : osf.toShortString()));
Craig Mautner69b08182012-09-05 13:07:13 -07004538
Filip Gruszczynski2217f612015-05-26 11:32:08 -07004539 win.computeFrameLw(pf, df, of, cf, vf, dcf, sf, osf);
Craig Mautner69b08182012-09-05 13:07:13 -07004540
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004541 // Dock windows carve out the bottom of the screen, so normal windows
4542 // can't appear underneath them.
Craig Mautner8bd206b2012-10-03 10:32:02 -07004543 if (attrs.type == TYPE_INPUT_METHOD && win.isVisibleOrBehindKeyguardLw()
4544 && !win.getGivenInsetsPendingLw()) {
satok1bc0a492012-04-25 22:47:12 +09004545 setLastInputMethodWindowLw(null, null);
4546 offsetInputMethodWindowLw(win);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004547 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004548 if (attrs.type == TYPE_VOICE_INTERACTION && win.isVisibleOrBehindKeyguardLw()
4549 && !win.getGivenInsetsPendingLw()) {
4550 offsetVoiceInputWindowLw(win);
4551 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004552 }
4553
satok1bc0a492012-04-25 22:47:12 +09004554 private void offsetInputMethodWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004555 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
satok1bc0a492012-04-25 22:47:12 +09004556 top += win.getGivenContentInsetsLw().top;
4557 if (mContentBottom > top) {
4558 mContentBottom = top;
4559 }
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004560 if (mVoiceContentBottom > top) {
4561 mVoiceContentBottom = top;
4562 }
satok1bc0a492012-04-25 22:47:12 +09004563 top = win.getVisibleFrameLw().top;
4564 top += win.getGivenVisibleInsetsLw().top;
4565 if (mCurBottom > top) {
4566 mCurBottom = top;
4567 }
Craig Mautnereda67292013-04-28 13:50:14 -07004568 if (DEBUG_LAYOUT) Slog.v(TAG, "Input method: mDockBottom="
satok1bc0a492012-04-25 22:47:12 +09004569 + mDockBottom + " mContentBottom="
4570 + mContentBottom + " mCurBottom=" + mCurBottom);
4571 }
4572
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004573 private void offsetVoiceInputWindowLw(WindowState win) {
Craig Mautner4774f6a2015-03-23 11:42:55 -07004574 int top = Math.max(win.getDisplayFrameLw().top, win.getContentFrameLw().top);
Dianne Hackbornae6688b2015-02-11 17:02:41 -08004575 top += win.getGivenContentInsetsLw().top;
4576 if (mVoiceContentBottom > top) {
4577 mVoiceContentBottom = top;
Dianne Hackborne30e02f2014-05-27 18:24:45 -07004578 }
4579 }
4580
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004581 /** {@inheritDoc} */
Craig Mautner61ac6bb2012-02-02 17:29:33 -08004582 @Override
4583 public void finishLayoutLw() {
4584 return;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004585 }
4586
4587 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004588 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004589 public void beginPostLayoutPolicyLw(int displayWidth, int displayHeight) {
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004590 mTopFullscreenOpaqueWindowState = null;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004591 mTopFullscreenOpaqueOrDimmingWindowState = null;
Jorim Jaggi86905582016-02-09 21:36:09 -08004592 mTopDockedOpaqueWindowState = null;
4593 mTopDockedOpaqueOrDimmingWindowState = null;
Craig Mautner2bc789b2014-03-19 19:48:38 -07004594 mAppsToBeHidden.clear();
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004595 mAppsThatDismissKeyguard.clear();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004596 mForceStatusBar = false;
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004597 mForceStatusBarFromKeyguard = false;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004598 mForceStatusBarTransparent = false;
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004599 mForcingShowNavBar = false;
4600 mForcingShowNavBarLayer = -1;
RoboErik8a2cfc32014-05-16 11:19:38 -07004601
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004602 mHideLockScreen = false;
4603 mAllowLockscreenWhenOn = false;
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004604 mDismissKeyguard = DISMISS_KEYGUARD_NONE;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004605 mShowingLockscreen = false;
4606 mShowingDream = false;
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004607 mWinShowWhenLocked = null;
Jim Millerab954542014-10-10 18:21:49 -07004608 mKeyguardSecure = isKeyguardSecure();
4609 mKeyguardSecureIncludingHidden = mKeyguardSecure
4610 && (mKeyguardDelegate != null && mKeyguardDelegate.isShowing());
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004611 }
4612
4613 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004614 @Override
Yohei Yukawad1a09222015-06-30 16:22:05 -07004615 public void applyPostLayoutPolicyLw(WindowState win, WindowManager.LayoutParams attrs,
4616 WindowState attached) {
Dianne Hackbornbc1aa7b2011-09-20 11:20:31 -07004617 if (DEBUG_LAYOUT) Slog.i(TAG, "Win " + win + ": isVisibleOrBehindKeyguardLw="
4618 + win.isVisibleOrBehindKeyguardLw());
John Spurlockc6d1c602014-01-17 15:22:06 -05004619 final int fl = PolicyControl.getWindowFlags(win, attrs);
John Spurlock414c1f02013-12-04 13:47:36 -05004620 if (mTopFullscreenOpaqueWindowState == null
4621 && win.isVisibleLw() && attrs.type == TYPE_INPUT_METHOD) {
4622 mForcingShowNavBar = true;
4623 mForcingShowNavBarLayer = win.getSurfaceLayer();
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08004624 }
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004625 if (attrs.type == TYPE_STATUS_BAR) {
4626 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
4627 mForceStatusBarFromKeyguard = true;
Jorim Jaggie1de9f62015-09-23 14:59:50 -07004628 mShowingLockscreen = true;
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004629 }
4630 if ((attrs.privateFlags & PRIVATE_FLAG_FORCE_STATUS_BAR_VISIBLE_TRANSPARENT) != 0) {
4631 mForceStatusBarTransparent = true;
4632 }
Jorim Jaggiafd4a552014-04-08 15:13:05 +02004633 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004634
4635 boolean appWindow = attrs.type >= FIRST_APPLICATION_WINDOW
4636 && attrs.type < FIRST_SYSTEM_WINDOW;
4637 final boolean showWhenLocked = (fl & FLAG_SHOW_WHEN_LOCKED) != 0;
4638 final boolean dismissKeyguard = (fl & FLAG_DISMISS_KEYGUARD) != 0;
Jorim Jaggi86905582016-02-09 21:36:09 -08004639 final int stackId = win.getStackId();
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004640 if (mTopFullscreenOpaqueWindowState == null &&
Dianne Hackborn01b02a72012-01-12 14:05:03 -08004641 win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw()) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004642 if ((fl & FLAG_FORCE_NOT_FULLSCREEN) != 0) {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004643 if ((attrs.privateFlags & PRIVATE_FLAG_KEYGUARD) != 0) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004644 mForceStatusBarFromKeyguard = true;
4645 } else {
4646 mForceStatusBar = true;
4647 }
4648 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004649 if (attrs.type == TYPE_DREAM) {
Jeff Brownc8018eb2012-10-29 21:33:27 -07004650 // If the lockscreen was showing when the dream started then wait
4651 // for the dream to draw before hiding the lockscreen.
4652 if (!mDreamingLockscreen
4653 || (win.isVisibleLw() && win.hasDrawnLw())) {
4654 mShowingDream = true;
Craig Mautnerab55e522014-03-03 13:26:03 -08004655 appWindow = true;
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004656 }
4657 }
Craig Mautnerab55e522014-03-03 13:26:03 -08004658
Yohei Yukawad1a09222015-06-30 16:22:05 -07004659 final IApplicationToken appToken = win.getAppToken();
4660
4661 // For app windows that are not attached, we decide if all windows in the app they
4662 // represent should be hidden or if we should hide the lockscreen. For attached app
4663 // windows we defer the decision to the window it is attached to.
4664 if (appWindow && attached == null) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004665 if (showWhenLocked) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004666 // Remove any previous windows with the same appToken.
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004667 mAppsToBeHidden.remove(appToken);
4668 mAppsThatDismissKeyguard.remove(appToken);
Craig Mautnerca0a1242014-12-02 12:25:14 -08004669 if (mAppsToBeHidden.isEmpty()) {
Craig Mautner192d6042014-12-02 23:24:48 -08004670 if (dismissKeyguard && !mKeyguardSecure) {
4671 mAppsThatDismissKeyguard.add(appToken);
Selim Cinek90b5e072015-08-28 17:05:56 -07004672 } else if (win.isDrawnLw() || win.hasAppShownWindows()) {
Craig Mautnerca0a1242014-12-02 12:25:14 -08004673 mWinShowWhenLocked = win;
4674 mHideLockScreen = true;
4675 mForceStatusBarFromKeyguard = false;
Craig Mautnerca0a1242014-12-02 12:25:14 -08004676 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004677 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004678 } else if (dismissKeyguard) {
Jim Millerab954542014-10-10 18:21:49 -07004679 if (mKeyguardSecure) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004680 mAppsToBeHidden.add(appToken);
4681 } else {
4682 mAppsToBeHidden.remove(appToken);
4683 }
4684 mAppsThatDismissKeyguard.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004685 } else {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004686 mAppsToBeHidden.add(appToken);
Craig Mautner2bc789b2014-03-19 19:48:38 -07004687 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004688 if (isFullscreen(attrs) && StackId.normallyFullscreenWindows(stackId)) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004689 if (DEBUG_LAYOUT) Slog.v(TAG, "Fullscreen window: " + win);
4690 mTopFullscreenOpaqueWindowState = win;
Adrian Rooscd3884d2015-02-18 17:25:23 +01004691 if (mTopFullscreenOpaqueOrDimmingWindowState == null) {
4692 mTopFullscreenOpaqueOrDimmingWindowState = win;
4693 }
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004694 if (!mAppsThatDismissKeyguard.isEmpty() &&
4695 mDismissKeyguard == DISMISS_KEYGUARD_NONE) {
4696 if (DEBUG_LAYOUT) Slog.v(TAG,
4697 "Setting mDismissKeyguard true by win " + win);
tingna_sunge785ffa2015-05-12 13:23:15 +08004698 mDismissKeyguard = (mWinDismissingKeyguard == win
4699 && mSecureDismissingKeyguard == mKeyguardSecure)
4700 ? DISMISS_KEYGUARD_CONTINUE : DISMISS_KEYGUARD_START;
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004701 mWinDismissingKeyguard = win;
tingna_sunge785ffa2015-05-12 13:23:15 +08004702 mSecureDismissingKeyguard = mKeyguardSecure;
Jim Millerab954542014-10-10 18:21:49 -07004703 mForceStatusBarFromKeyguard = mShowingLockscreen && mKeyguardSecure;
Selim Cinek90b5e072015-08-28 17:05:56 -07004704 } else if (mAppsToBeHidden.isEmpty() && showWhenLocked
4705 && (win.isDrawnLw() || win.hasAppShownWindows())) {
Jorim Jaggic13fcac2014-09-11 17:36:57 +02004706 if (DEBUG_LAYOUT) Slog.v(TAG,
4707 "Setting mHideLockScreen to true by win " + win);
4708 mHideLockScreen = true;
4709 mForceStatusBarFromKeyguard = false;
Craig Mautnerab55e522014-03-03 13:26:03 -08004710 }
Craig Mautner00156ec2014-03-06 22:29:02 -08004711 if ((fl & FLAG_ALLOW_LOCK_WHILE_SCREEN_ON) != 0) {
Craig Mautnerab55e522014-03-03 13:26:03 -08004712 mAllowLockscreenWhenOn = true;
4713 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004714 }
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004715
4716 if (mWinShowWhenLocked != null &&
Adrian Roos602c68e2015-04-24 16:03:47 -07004717 mWinShowWhenLocked.getAppToken() != win.getAppToken() &&
4718 (attrs.flags & FLAG_SHOW_WHEN_LOCKED) == 0) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004719 win.hideLw(false);
4720 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004721 }
Adrian Roos602c68e2015-04-24 16:03:47 -07004722 } else if (mTopFullscreenOpaqueWindowState == null && mWinShowWhenLocked == null) {
4723 // No TopFullscreenOpaqueWindow is showing, but we found a SHOW_WHEN_LOCKED window
4724 // that is being hidden in an animation - keep the
4725 // keyguard hidden until the new window shows up and
4726 // we know whether to show the keyguard or not.
Adrian Roosb85e1ec2015-05-29 15:23:18 -07004727 if (win.isAnimatingLw() && appWindow && showWhenLocked && mKeyguardHidden) {
Adrian Roos602c68e2015-04-24 16:03:47 -07004728 mHideLockScreen = true;
4729 mWinShowWhenLocked = win;
4730 }
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004731 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004732
4733 // Keep track of the window if it's dimming but not necessarily fullscreen.
4734 final boolean reallyVisible = win.isVisibleOrBehindKeyguardLw() && !win.isGoneForLayoutLw();
4735 if (mTopFullscreenOpaqueOrDimmingWindowState == null && reallyVisible
4736 && win.isDimming() && StackId.normallyFullscreenWindows(stackId)) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01004737 mTopFullscreenOpaqueOrDimmingWindowState = win;
4738 }
Jorim Jaggi86905582016-02-09 21:36:09 -08004739
4740 // We need to keep track of the top "fullscreen" opaque window for the docked stack
4741 // separately, because both the "real fullscreen" opaque window and the one for the docked
4742 // stack can control View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR.
4743 if (mTopDockedOpaqueWindowState == null && reallyVisible && appWindow && attached == null
4744 && isFullscreen(attrs) && stackId == DOCKED_STACK_ID) {
4745 mTopDockedOpaqueWindowState = win;
4746 if (mTopDockedOpaqueOrDimmingWindowState == null) {
4747 mTopDockedOpaqueOrDimmingWindowState = win;
4748 }
4749 }
4750
4751 // Also keep track of any windows that are dimming but not necessarily fullscreen in the
4752 // docked stack.
4753 if (mTopDockedOpaqueOrDimmingWindowState == null && reallyVisible && win.isDimming()
4754 && stackId == DOCKED_STACK_ID) {
4755 mTopDockedOpaqueOrDimmingWindowState = win;
4756 }
4757 }
4758
4759 private boolean isFullscreen(WindowManager.LayoutParams attrs) {
4760 return attrs.x == 0 && attrs.y == 0
4761 && attrs.width == WindowManager.LayoutParams.MATCH_PARENT
4762 && attrs.height == WindowManager.LayoutParams.MATCH_PARENT;
Dianne Hackborn5f3063e2010-03-10 16:01:58 -08004763 }
4764
4765 /** {@inheritDoc} */
Craig Mautnerad09bcc2012-10-08 13:33:11 -07004766 @Override
Craig Mautner39834192012-09-02 07:47:24 -07004767 public int finishPostLayoutPolicyLw() {
Craig Mautnerc5e73bf2015-04-21 15:41:26 +00004768 if (mWinShowWhenLocked != null && mTopFullscreenOpaqueWindowState != null &&
4769 mWinShowWhenLocked.getAppToken() != mTopFullscreenOpaqueWindowState.getAppToken()
4770 && isKeyguardLocked()) {
Craig Mautnerc9457fa2014-06-06 14:27:48 -07004771 // A dialog is dismissing the keyguard. Put the wallpaper behind it and hide the
4772 // fullscreen window.
4773 // TODO: Make sure FLAG_SHOW_WALLPAPER is restored when dialog is dismissed. Or not.
4774 mWinShowWhenLocked.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4775 mTopFullscreenOpaqueWindowState.hideLw(false);
4776 mTopFullscreenOpaqueWindowState = mWinShowWhenLocked;
4777 }
4778
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004779 int changes = 0;
Joe Onorato93056472010-09-10 10:30:46 -04004780 boolean topIsFullscreen = false;
Daniel Sandlere02d8082010-10-08 15:13:22 -04004781
4782 final WindowManager.LayoutParams lp = (mTopFullscreenOpaqueWindowState != null)
4783 ? mTopFullscreenOpaqueWindowState.getAttrs()
4784 : null;
4785
Jeff Brownc8018eb2012-10-29 21:33:27 -07004786 // If we are not currently showing a dream then remember the current
4787 // lockscreen state. We will use this to determine whether the dream
4788 // started while the lockscreen was showing and remember this state
4789 // while the dream is showing.
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004790 if (!mShowingDream) {
4791 mDreamingLockscreen = mShowingLockscreen;
Jeff Brown061ea992015-04-17 19:55:47 -07004792 if (mDreamingSleepTokenNeeded) {
4793 mDreamingSleepTokenNeeded = false;
4794 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 0, 1).sendToTarget();
4795 }
4796 } else {
4797 if (!mDreamingSleepTokenNeeded) {
4798 mDreamingSleepTokenNeeded = true;
4799 mHandler.obtainMessage(MSG_UPDATE_DREAMING_SLEEP_TOKEN, 1, 1).sendToTarget();
4800 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07004801 }
4802
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004803 if (mStatusBar != null) {
Craig Mautnereda67292013-04-28 13:50:14 -07004804 if (DEBUG_LAYOUT) Slog.i(TAG, "force=" + mForceStatusBar
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07004805 + " forcefkg=" + mForceStatusBarFromKeyguard
Dianne Hackbornd70bc2f2009-10-06 23:25:51 -07004806 + " top=" + mTopFullscreenOpaqueWindowState);
Selim Cinek4a4a2bddc2015-05-07 12:50:19 -07004807 boolean shouldBeTransparent = mForceStatusBarTransparent
4808 && !mForceStatusBar
4809 && !mForceStatusBarFromKeyguard;
4810 if (!shouldBeTransparent) {
4811 mStatusBarController.setShowTransparent(false /* transparent */);
4812 } else if (!mStatusBar.isVisibleLw()) {
4813 mStatusBarController.setShowTransparent(true /* transparent */);
4814 }
4815 if (mForceStatusBar || mForceStatusBarFromKeyguard || mForceStatusBarTransparent) {
Craig Mautnereda67292013-04-28 13:50:14 -07004816 if (DEBUG_LAYOUT) Slog.v(TAG, "Showing status bar: forced");
John Spurlock27735a42013-08-14 17:57:38 -04004817 if (mStatusBarController.setBarShowingLw(true)) {
4818 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4819 }
Craig Mautner81defc72013-10-29 11:10:42 -07004820 // Maintain fullscreen layout until incoming animation is complete.
4821 topIsFullscreen = mTopIsFullscreen && mStatusBar.isAnimatingLw();
John Spurlockf92b6162013-11-11 15:01:16 -05004822 // Transient status bar on the lockscreen is not allowed
4823 if (mForceStatusBarFromKeyguard && mStatusBarController.isTransientShowing()) {
4824 mStatusBarController.updateVisibilityLw(false /*transientAllowed*/,
4825 mLastSystemUiFlags, mLastSystemUiFlags);
4826 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004827 } else if (mTopFullscreenOpaqueWindowState != null) {
John Spurlockc6d1c602014-01-17 15:22:06 -05004828 final int fl = PolicyControl.getWindowFlags(null, lp);
Joe Onorato93056472010-09-10 10:30:46 -04004829 if (localLOGV) {
Craig Mautnereda67292013-04-28 13:50:14 -07004830 Slog.d(TAG, "frame: " + mTopFullscreenOpaqueWindowState.getFrameLw()
Filip Gruszczynski2a6a2c22015-10-14 12:00:53 -07004831 + " shown position: "
4832 + mTopFullscreenOpaqueWindowState.getShownPositionLw());
Craig Mautnereda67292013-04-28 13:50:14 -07004833 Slog.d(TAG, "attr: " + mTopFullscreenOpaqueWindowState.getAttrs()
John Spurlockc6d1c602014-01-17 15:22:06 -05004834 + " lp.flags=0x" + Integer.toHexString(fl));
Joe Onorato93056472010-09-10 10:30:46 -04004835 }
John Spurlockc6d1c602014-01-17 15:22:06 -05004836 topIsFullscreen = (fl & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004837 || (mLastSystemUiFlags & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Joe Onorato93056472010-09-10 10:30:46 -04004838 // The subtle difference between the window for mTopFullscreenOpaqueWindowState
Mark Dolinerd0646dc2014-08-27 16:04:02 -07004839 // and mTopIsFullscreen is that mTopIsFullscreen is set only if the window
Joe Onorato93056472010-09-10 10:30:46 -04004840 // has the FLAG_FULLSCREEN set. Not sure if there is another way that to be the
4841 // case though.
John Spurlock27735a42013-08-14 17:57:38 -04004842 if (mStatusBarController.isTransientShowing()) {
4843 if (mStatusBarController.setBarShowingLw(true)) {
John Spurlock32beb2c2013-03-11 10:16:47 -04004844 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4845 }
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07004846 } else if (topIsFullscreen
4847 && !mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID)
4848 && !mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID)) {
Craig Mautnereda67292013-04-28 13:50:14 -07004849 if (DEBUG_LAYOUT) Slog.v(TAG, "** HIDING status bar");
John Spurlock27735a42013-08-14 17:57:38 -04004850 if (mStatusBarController.setBarShowingLw(false)) {
Dianne Hackbornf87d1962012-04-04 12:48:24 -07004851 changes |= FINISH_LAYOUT_REDO_LAYOUT;
Craig Mautnereda67292013-04-28 13:50:14 -07004852 } else {
Craig Mautnerc5a6e442013-06-05 17:22:35 -07004853 if (DEBUG_LAYOUT) Slog.v(TAG, "Status bar already hiding");
Daniel Sandler40427442010-07-16 11:44:52 -04004854 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004855 } else {
Craig Mautnereda67292013-04-28 13:50:14 -07004856 if (DEBUG_LAYOUT) Slog.v(TAG, "** SHOWING status bar: top is not fullscreen");
John Spurlock27735a42013-08-14 17:57:38 -04004857 if (mStatusBarController.setBarShowingLw(true)) {
4858 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4859 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004860 }
4861 }
4862 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004863
Craig Mautner81defc72013-10-29 11:10:42 -07004864 if (mTopIsFullscreen != topIsFullscreen) {
4865 if (!topIsFullscreen) {
4866 // Force another layout when status bar becomes fully shown.
4867 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4868 }
4869 mTopIsFullscreen = topIsFullscreen;
4870 }
Daniel Sandlere02d8082010-10-08 15:13:22 -04004871
Craig Mautner39834192012-09-02 07:47:24 -07004872 // Hide the key guard if a visible window explicitly specifies that it wants to be
4873 // displayed when the screen is locked.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004874 if (mKeyguardDelegate != null && mStatusBar != null) {
4875 if (localLOGV) Slog.v(TAG, "finishPostLayoutPolicyLw: mHideKeyguard="
4876 + mHideLockScreen);
Jim Millerab954542014-10-10 18:21:49 -07004877 if (mDismissKeyguard != DISMISS_KEYGUARD_NONE && !mKeyguardSecure) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004878 mKeyguardHidden = true;
Jim Millerab954542014-10-10 18:21:49 -07004879 if (setKeyguardOccludedLw(true)) {
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004880 changes |= FINISH_LAYOUT_REDO_LAYOUT
4881 | FINISH_LAYOUT_REDO_CONFIG
4882 | FINISH_LAYOUT_REDO_WALLPAPER;
4883 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004884 if (mKeyguardDelegate.isShowing()) {
4885 mHandler.post(new Runnable() {
4886 @Override
4887 public void run() {
4888 mKeyguardDelegate.keyguardDone(false, false);
4889 }
4890 });
4891 }
4892 } else if (mHideLockScreen) {
4893 mKeyguardHidden = true;
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004894 mWinDismissingKeyguard = null;
Jim Millerab954542014-10-10 18:21:49 -07004895 if (setKeyguardOccludedLw(true)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004896 changes |= FINISH_LAYOUT_REDO_LAYOUT
4897 | FINISH_LAYOUT_REDO_CONFIG
4898 | FINISH_LAYOUT_REDO_WALLPAPER;
4899 }
4900 } else if (mDismissKeyguard != DISMISS_KEYGUARD_NONE) {
Jorim Jaggi7d85ea92015-05-20 17:20:40 -07004901 mKeyguardHidden = false;
4902 if (setKeyguardOccludedLw(false)) {
4903 changes |= FINISH_LAYOUT_REDO_LAYOUT
4904 | FINISH_LAYOUT_REDO_CONFIG
4905 | FINISH_LAYOUT_REDO_WALLPAPER;
4906 }
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004907 if (mDismissKeyguard == DISMISS_KEYGUARD_START) {
4908 // Only launch the next keyguard unlock window once per window.
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004909 mHandler.post(new Runnable() {
4910 @Override
4911 public void run() {
4912 mKeyguardDelegate.dismiss();
4913 }
4914 });
4915 }
4916 } else {
4917 mWinDismissingKeyguard = null;
tingna_sunge785ffa2015-05-12 13:23:15 +08004918 mSecureDismissingKeyguard = false;
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004919 mKeyguardHidden = false;
Jim Millerab954542014-10-10 18:21:49 -07004920 if (setKeyguardOccludedLw(false)) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01004921 changes |= FINISH_LAYOUT_REDO_LAYOUT
4922 | FINISH_LAYOUT_REDO_CONFIG
4923 | FINISH_LAYOUT_REDO_WALLPAPER;
4924 }
Suchi Amalapurapu9cdc9032009-05-14 18:01:07 -07004925 }
4926 }
Joe Onorato664644d2011-01-23 17:53:23 -08004927
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004928 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004929 // If the navigation bar has been hidden or shown, we need to do another
4930 // layout pass to update that window.
4931 changes |= FINISH_LAYOUT_REDO_LAYOUT;
4932 }
Joe Onorato664644d2011-01-23 17:53:23 -08004933
Mike Lockwood28569302010-01-28 11:54:40 -05004934 // update since mAllowLockscreenWhenOn might have changed
4935 updateLockScreenTimeout();
Dianne Hackborn39c2d712009-09-22 11:41:31 -07004936 return changes;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08004937 }
4938
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004939 /**
Jim Millerab954542014-10-10 18:21:49 -07004940 * Updates the occluded state of the Keyguard.
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004941 *
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004942 * @return Whether the flags have changed and we have to redo the layout.
4943 */
Jim Millerab954542014-10-10 18:21:49 -07004944 private boolean setKeyguardOccludedLw(boolean isOccluded) {
4945 boolean wasOccluded = mKeyguardOccluded;
4946 boolean showing = mKeyguardDelegate.isShowing();
4947 if (wasOccluded && !isOccluded && showing) {
4948 mKeyguardOccluded = false;
4949 mKeyguardDelegate.setOccluded(false);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004950 mStatusBar.getAttrs().privateFlags |= PRIVATE_FLAG_KEYGUARD;
4951 mStatusBar.getAttrs().flags |= FLAG_SHOW_WALLPAPER;
4952 return true;
Jim Millerab954542014-10-10 18:21:49 -07004953 } else if (!wasOccluded && isOccluded && showing) {
4954 mKeyguardOccluded = true;
4955 mKeyguardDelegate.setOccluded(true);
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004956 mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
4957 mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
4958 return true;
4959 } else {
4960 return false;
4961 }
4962 }
4963
4964 private boolean isStatusBarKeyguard() {
4965 return mStatusBar != null
4966 && (mStatusBar.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0;
4967 }
4968
Jose Lima9546b202014-07-02 17:21:51 -07004969 @Override
Dianne Hackborn08743722009-12-21 12:16:51 -08004970 public boolean allowAppAnimationsLw() {
Jorim Jaggi380ecb82014-03-14 17:25:20 +01004971 if (isStatusBarKeyguard() || mShowingDream) {
Craig Mautner28816302013-10-10 20:31:00 -07004972 // If keyguard or dreams is currently visible, no reason to animate behind it.
Dianne Hackborn08743722009-12-21 12:16:51 -08004973 return false;
4974 }
Dianne Hackborn08743722009-12-21 12:16:51 -08004975 return true;
4976 }
4977
Jose Lima9546b202014-07-02 17:21:51 -07004978 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07004979 public int focusChangedLw(WindowState lastFocus, WindowState newFocus) {
Joe Onorato664644d2011-01-23 17:53:23 -08004980 mFocusedWindow = newFocus;
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07004981 if ((updateSystemUiVisibilityLw()&SYSTEM_UI_CHANGING_LAYOUT) != 0) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07004982 // If the navigation bar has been hidden or shown, we need to do another
4983 // layout pass to update that window.
4984 return FINISH_LAYOUT_REDO_LAYOUT;
4985 }
4986 return 0;
Joe Onorato664644d2011-01-23 17:53:23 -08004987 }
4988
Dianne Hackborn0ecadf72009-03-31 18:00:37 -07004989 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07004990 @Override
Jeff Brown46b9ac02010-04-22 18:58:52 -07004991 public void notifyLidSwitchChanged(long whenNanos, boolean lidOpen) {
4992 // lid changed state
Jeff Brownc458ce92012-04-30 14:58:40 -07004993 final int newLidState = lidOpen ? LID_OPEN : LID_CLOSED;
4994 if (newLidState == mLidState) {
4995 return;
4996 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07004997
Jeff Brownc458ce92012-04-30 14:58:40 -07004998 mLidState = newLidState;
4999 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07005000 updateRotation(true);
Jeff Brownc458ce92012-04-30 14:58:40 -07005001
5002 if (lidOpen) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005003 wakeUp(SystemClock.uptimeMillis(), mAllowTheaterModeWakeFromLidSwitch,
5004 "android.policy:LID");
Jeff Brownc458ce92012-04-30 14:58:40 -07005005 } else if (!mLidControlsSleep) {
Jeff Brown96307042012-07-27 15:51:34 -07005006 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
Jeff Brown46b9ac02010-04-22 18:58:52 -07005007 }
5008 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005009
Michael Wright3818c922014-09-02 13:59:07 -07005010 @Override
5011 public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered) {
5012 int lensCoverState = lensCovered ? CAMERA_LENS_COVERED : CAMERA_LENS_UNCOVERED;
5013 if (mCameraLensCoverState == lensCoverState) {
5014 return;
5015 }
5016 if (mCameraLensCoverState == CAMERA_LENS_COVERED &&
5017 lensCoverState == CAMERA_LENS_UNCOVERED) {
5018 Intent intent;
5019 final boolean keyguardActive = mKeyguardDelegate == null ? false :
5020 mKeyguardDelegate.isShowing();
5021 if (keyguardActive) {
5022 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
5023 } else {
5024 intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
5025 }
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005026 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromCameraLens,
5027 "android.policy:CAMERA_COVER");
Bart Sears8b1c27c2015-03-18 23:51:02 +00005028 startActivityAsUser(intent, UserHandle.CURRENT_OR_SELF);
Michael Wright3818c922014-09-02 13:59:07 -07005029 }
5030 mCameraLensCoverState = lensCoverState;
5031 }
5032
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005033 void setHdmiPlugged(boolean plugged) {
5034 if (mHdmiPlugged != plugged) {
5035 mHdmiPlugged = plugged;
Dianne Hackbornf87d1962012-04-04 12:48:24 -07005036 updateRotation(true, true);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005037 Intent intent = new Intent(ACTION_HDMI_PLUGGED);
Joe Onoratodc100302011-01-11 17:07:41 -08005038 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005039 intent.putExtra(EXTRA_HDMI_PLUGGED_STATE, plugged);
Dianne Hackborn5ac72a22012-08-29 18:32:08 -07005040 mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);
Dianne Hackbornad7fa7f2011-01-07 14:06:50 -08005041 }
5042 }
5043
Joe Onoratoea495d42011-04-06 11:41:11 -07005044 void initializeHdmiState() {
Joe Onorato7ba631f2011-05-04 15:28:00 -07005045 boolean plugged = false;
Joe Onoratoea495d42011-04-06 11:41:11 -07005046 // watch for HDMI plug messages if the hdmi switch exists
5047 if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
5048 mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
5049
Joe Onoratoea495d42011-04-06 11:41:11 -07005050 final String filename = "/sys/class/switch/hdmi/state";
5051 FileReader reader = null;
5052 try {
5053 reader = new FileReader(filename);
5054 char[] buf = new char[15];
5055 int n = reader.read(buf);
5056 if (n > 1) {
5057 plugged = 0 != Integer.parseInt(new String(buf, 0, n-1));
5058 }
5059 } catch (IOException ex) {
5060 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5061 } catch (NumberFormatException ex) {
5062 Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
5063 } finally {
5064 if (reader != null) {
5065 try {
5066 reader.close();
5067 } catch (IOException ex) {
5068 }
Joe Onoratodc100302011-01-11 17:07:41 -08005069 }
5070 }
5071 }
Joe Onorato7ba631f2011-05-04 15:28:00 -07005072 // This dance forces the code in setHdmiPlugged to run.
5073 // Always do this so the sticky intent is stuck (to false) if there is no hdmi.
5074 mHdmiPlugged = !plugged;
5075 setHdmiPlugged(!mHdmiPlugged);
Joe Onoratodc100302011-01-11 17:07:41 -08005076 }
5077
Dianne Hackbornc0e3f242011-08-19 14:19:10 -07005078 final Object mScreenshotLock = new Object();
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005079 ServiceConnection mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005080
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005081 final Runnable mScreenshotTimeout = new Runnable() {
5082 @Override public void run() {
5083 synchronized (mScreenshotLock) {
5084 if (mScreenshotConnection != null) {
5085 mContext.unbindService(mScreenshotConnection);
5086 mScreenshotConnection = null;
Dianne Hackbornfc8fa632011-08-17 16:20:47 -07005087 }
Winson Chung9112ec32011-06-27 13:15:32 -07005088 }
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005089 }
5090 };
5091
5092 // Assume this is called from the Handler thread.
5093 private void takeScreenshot() {
5094 synchronized (mScreenshotLock) {
5095 if (mScreenshotConnection != null) {
5096 return;
5097 }
5098 ComponentName cn = new ComponentName("com.android.systemui",
5099 "com.android.systemui.screenshot.TakeScreenshotService");
5100 Intent intent = new Intent();
5101 intent.setComponent(cn);
5102 ServiceConnection conn = new ServiceConnection() {
5103 @Override
5104 public void onServiceConnected(ComponentName name, IBinder service) {
5105 synchronized (mScreenshotLock) {
5106 if (mScreenshotConnection != this) {
5107 return;
5108 }
5109 Messenger messenger = new Messenger(service);
5110 Message msg = Message.obtain(null, 1);
5111 final ServiceConnection myConn = this;
5112 Handler h = new Handler(mHandler.getLooper()) {
5113 @Override
5114 public void handleMessage(Message msg) {
5115 synchronized (mScreenshotLock) {
5116 if (mScreenshotConnection == myConn) {
5117 mContext.unbindService(mScreenshotConnection);
5118 mScreenshotConnection = null;
5119 mHandler.removeCallbacks(mScreenshotTimeout);
5120 }
5121 }
5122 }
5123 };
5124 msg.replyTo = new Messenger(h);
Winson Chunga63bb842011-10-17 10:26:28 -07005125 msg.arg1 = msg.arg2 = 0;
5126 if (mStatusBar != null && mStatusBar.isVisibleLw())
5127 msg.arg1 = 1;
5128 if (mNavigationBar != null && mNavigationBar.isVisibleLw())
5129 msg.arg2 = 1;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005130 try {
5131 messenger.send(msg);
5132 } catch (RemoteException e) {
5133 }
5134 }
5135 }
5136 @Override
5137 public void onServiceDisconnected(ComponentName name) {}
5138 };
Amith Yamasani27b89e62013-01-16 12:30:11 -08005139 if (mContext.bindServiceAsUser(
5140 intent, conn, Context.BIND_AUTO_CREATE, UserHandle.CURRENT)) {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005141 mScreenshotConnection = conn;
5142 mHandler.postDelayed(mScreenshotTimeout, 10000);
5143 }
5144 }
Winson Chung9112ec32011-06-27 13:15:32 -07005145 }
5146
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005147 /** {@inheritDoc} */
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005148 @Override
Jeff Brown037c33e2014-04-09 00:31:55 -07005149 public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags) {
Jeff Brown96307042012-07-27 15:51:34 -07005150 if (!mSystemBooted) {
5151 // If we have not yet booted, don't let key events do anything.
5152 return 0;
5153 }
5154
Jeff Brown037c33e2014-04-09 00:31:55 -07005155 final boolean interactive = (policyFlags & FLAG_INTERACTIVE) != 0;
Jeff Brown1f245102010-11-18 20:53:46 -08005156 final boolean down = event.getAction() == KeyEvent.ACTION_DOWN;
5157 final boolean canceled = event.isCanceled();
5158 final int keyCode = event.getKeyCode();
Jeff Browne20c9e02010-10-11 14:20:19 -07005159
Jeff Brown3122e442010-10-11 23:32:49 -07005160 final boolean isInjected = (policyFlags & WindowManagerPolicy.FLAG_INJECTED) != 0;
Jeff Brown3122e442010-10-11 23:32:49 -07005161
Mike Lockwoodc72b15f2009-11-28 20:58:22 -05005162 // If screen is off then we treat the case where the keyguard is open but hidden
5163 // the same as if it were open and in front.
5164 // This will prevent any keys other than the power button from waking the screen
5165 // when the keyguard is hidden by another activity.
Jim Miller5ecd8112013-01-09 18:50:26 -08005166 final boolean keyguardActive = (mKeyguardDelegate == null ? false :
Jeff Brown037c33e2014-04-09 00:31:55 -07005167 (interactive ?
Jim Millerab954542014-10-10 18:21:49 -07005168 isKeyguardShowingAndNotOccluded() :
Jim Miller5ecd8112013-01-09 18:50:26 -08005169 mKeyguardDelegate.isShowing()));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005170
Jeff Brown40013652012-05-16 21:22:36 -07005171 if (DEBUG_INPUT) {
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005172 Log.d(TAG, "interceptKeyTq keycode=" + keyCode
Jeff Brown037c33e2014-04-09 00:31:55 -07005173 + " interactive=" + interactive + " keyguardActive=" + keyguardActive
Jeff Brown26875502014-01-30 21:47:47 -08005174 + " policyFlags=" + Integer.toHexString(policyFlags));
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005175 }
5176
Jeff Brown037c33e2014-04-09 00:31:55 -07005177 // Basic policy based on interactive state.
Jeff Brown4d396052010-10-29 21:50:21 -07005178 int result;
Michael Wright337d9d22014-04-22 15:03:48 -07005179 boolean isWakeKey = (policyFlags & WindowManagerPolicy.FLAG_WAKE) != 0
5180 || event.isWakeKey();
Michael Wrightfc01f042014-09-08 14:12:24 -07005181 if (interactive || (isInjected && !isWakeKey)) {
RoboErikde9ba392014-09-26 12:51:01 -07005182 // When the device is interactive or the key is injected pass the
5183 // key to the application.
Jeff Brown4d396052010-10-29 21:50:21 -07005184 result = ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005185 isWakeKey = false;
Michael Wrightfc01f042014-09-08 14:12:24 -07005186 } else if (!interactive && shouldDispatchInputWhenNonInteractive()) {
5187 // If we're currently dozing with the screen on and the keyguard showing, pass the key
5188 // to the application but preserve its wake key status to make sure we still move
5189 // from dozing to fully interactive if we would normally go from off to fully
5190 // interactive.
5191 result = ACTION_PASS_TO_USER;
Jeff Brown4d396052010-10-29 21:50:21 -07005192 } else {
5193 // When the screen is off and the key is not injected, determine whether
5194 // to wake the device but don't pass the key to the application.
5195 result = 0;
Jeff Brown26875502014-01-30 21:47:47 -08005196 if (isWakeKey && (!down || !isWakeKeyWhenScreenOff(keyCode))) {
5197 isWakeKey = false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005198 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005199 }
5200
Justin Kohd378ad72013-04-01 12:18:26 -07005201 // If the key would be handled globally, just return the result, don't worry about special
5202 // key processing.
Jeff Brown13f00f02014-10-31 14:45:50 -07005203 if (isValidGlobalKey(keyCode)
5204 && mGlobalKeyManager.shouldHandleGlobalKey(keyCode, event)) {
Michael Wright85b1af62014-06-04 14:51:58 -07005205 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005206 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Michael Wright85b1af62014-06-04 14:51:58 -07005207 }
Justin Kohd378ad72013-04-01 12:18:26 -07005208 return result;
5209 }
5210
Jeff Brownbae8e772014-06-12 19:59:45 -07005211 boolean useHapticFeedback = down
5212 && (policyFlags & WindowManagerPolicy.FLAG_VIRTUAL) != 0
5213 && event.getRepeatCount() == 0;
5214
Jeff Brown4d396052010-10-29 21:50:21 -07005215 // Handle special keys.
5216 switch (keyCode) {
5217 case KeyEvent.KEYCODE_VOLUME_DOWN:
Jeff Brownb0418da2010-11-01 15:24:01 -07005218 case KeyEvent.KEYCODE_VOLUME_UP:
5219 case KeyEvent.KEYCODE_VOLUME_MUTE: {
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005220 if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
5221 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005222 if (interactive && !mScreenshotChordVolumeDownKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005223 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005224 mScreenshotChordVolumeDownKeyTriggered = true;
5225 mScreenshotChordVolumeDownKeyTime = event.getDownTime();
5226 mScreenshotChordVolumeDownKeyConsumed = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005227 cancelPendingPowerKeyAction();
5228 interceptScreenshotChord();
5229 }
5230 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005231 mScreenshotChordVolumeDownKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005232 cancelPendingScreenshotChordAction();
5233 }
5234 } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
5235 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005236 if (interactive && !mScreenshotChordVolumeUpKeyTriggered
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005237 && (event.getFlags() & KeyEvent.FLAG_FALLBACK) == 0) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005238 mScreenshotChordVolumeUpKeyTriggered = true;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005239 cancelPendingPowerKeyAction();
5240 cancelPendingScreenshotChordAction();
5241 }
5242 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005243 mScreenshotChordVolumeUpKeyTriggered = false;
Jeff Brownd5bb82d2011-10-12 13:57:59 -07005244 cancelPendingScreenshotChordAction();
5245 }
5246 }
Jeff Brown4d396052010-10-29 21:50:21 -07005247 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005248 TelecomManager telecomManager = getTelecommService();
5249 if (telecomManager != null) {
5250 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005251 // If an incoming call is ringing, either VOLUME key means
5252 // "silence ringer". We handle these keys here, rather than
5253 // in the InCallScreen, to make sure we'll respond to them
5254 // even if the InCallScreen hasn't come to the foreground yet.
5255 // Look for the DOWN event here, to agree with the "fallback"
5256 // behavior in the InCallScreen.
5257 Log.i(TAG, "interceptKeyBeforeQueueing:"
5258 + " VOLUME key-down while ringing: Silence ringer!");
Jeff Brown4d396052010-10-29 21:50:21 -07005259
Santos Cordon6848f722014-05-21 15:22:12 -07005260 // Silence the ringer. (It's safe to call this
5261 // even if the ringer has already been silenced.)
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005262 telecomManager.silenceRinger();
Jeff Brown4d396052010-10-29 21:50:21 -07005263
Santos Cordon6848f722014-05-21 15:22:12 -07005264 // And *don't* pass this key thru to the current activity
5265 // (which is probably the InCallScreen.)
5266 result &= ~ACTION_PASS_TO_USER;
5267 break;
5268 }
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005269 if (telecomManager.isInCall()
Santos Cordon6848f722014-05-21 15:22:12 -07005270 && (result & ACTION_PASS_TO_USER) == 0) {
5271 // If we are in call but we decided not to pass the key to
RoboErik430fc482014-06-12 15:49:20 -07005272 // the application, just pass it to the session service.
5273
5274 MediaSessionLegacyHelper.getHelper(mContext)
RoboErik3c45c292014-07-08 16:47:31 -07005275 .sendVolumeKeyEvent(event, false);
Santos Cordon6848f722014-05-21 15:22:12 -07005276 break;
Jeff Brown4d396052010-10-29 21:50:21 -07005277 }
5278 }
Jaewan Kim765487f2016-01-12 14:45:42 +09005279 }
5280 if (mUseTvRouting) {
5281 // On TVs, defer special key handlings to
5282 // {@link interceptKeyBeforeDispatching()}.
5283 result |= ACTION_PASS_TO_USER;
5284 } else if ((result & ACTION_PASS_TO_USER) == 0) {
5285 // If we aren't passing to the user and no one else
5286 // handled it send it to the session manager to
5287 // figure out.
5288 MediaSessionLegacyHelper.getHelper(mContext)
5289 .sendVolumeKeyEvent(event, true);
Jeff Brown4d396052010-10-29 21:50:21 -07005290 }
5291 break;
5292 }
5293
5294 case KeyEvent.KEYCODE_ENDCALL: {
5295 result &= ~ACTION_PASS_TO_USER;
5296 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005297 TelecomManager telecomManager = getTelecommService();
Jeff Brown4d396052010-10-29 21:50:21 -07005298 boolean hungUp = false;
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005299 if (telecomManager != null) {
5300 hungUp = telecomManager.endCall();
Jeff Brown4d396052010-10-29 21:50:21 -07005301 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005302 if (interactive && !hungUp) {
5303 mEndCallKeyHandled = false;
5304 mHandler.postDelayed(mEndCallLongPress,
5305 ViewConfiguration.get(mContext).getDeviceGlobalActionKeyTimeout());
5306 } else {
5307 mEndCallKeyHandled = true;
5308 }
Jeff Brown4d396052010-10-29 21:50:21 -07005309 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005310 if (!mEndCallKeyHandled) {
5311 mHandler.removeCallbacks(mEndCallLongPress);
5312 if (!canceled) {
5313 if ((mEndcallBehavior
5314 & Settings.System.END_BUTTON_BEHAVIOR_HOME) != 0) {
5315 if (goHome()) {
5316 break;
5317 }
Dianne Hackborn0041e972009-07-24 17:14:43 -07005318 }
Jeff Brown13f00f02014-10-31 14:45:50 -07005319 if ((mEndcallBehavior
5320 & Settings.System.END_BUTTON_BEHAVIOR_SLEEP) != 0) {
5321 mPowerManager.goToSleep(event.getEventTime(),
5322 PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON, 0);
5323 isWakeKey = false;
5324 }
Jeff Brown4d396052010-10-29 21:50:21 -07005325 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005326 }
Jeff Brown4d396052010-10-29 21:50:21 -07005327 }
5328 break;
5329 }
5330
5331 case KeyEvent.KEYCODE_POWER: {
5332 result &= ~ACTION_PASS_TO_USER;
Jeff Brown13f00f02014-10-31 14:45:50 -07005333 isWakeKey = false; // wake-up will be handled separately
Jeff Brown4d396052010-10-29 21:50:21 -07005334 if (down) {
Jeff Brown13f00f02014-10-31 14:45:50 -07005335 interceptPowerKeyDown(event, interactive);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005336 } else {
Jeff Brown13f00f02014-10-31 14:45:50 -07005337 interceptPowerKeyUp(event, interactive, canceled);
Jeff Brown4d396052010-10-29 21:50:21 -07005338 }
5339 break;
5340 }
5341
Jeff Brown6212a492014-03-07 13:58:47 -08005342 case KeyEvent.KEYCODE_SLEEP: {
5343 result &= ~ACTION_PASS_TO_USER;
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00005344 isWakeKey = false;
Jeff Brownbae8e772014-06-12 19:59:45 -07005345 if (!mPowerManager.isInteractive()) {
5346 useHapticFeedback = false; // suppress feedback if already non-interactive
5347 }
Nick Vaccarob593a812015-05-15 11:23:05 -07005348 if (down) {
5349 sleepPress(event.getEventTime());
5350 } else {
5351 sleepRelease(event.getEventTime());
5352 }
Jeff Brown6212a492014-03-07 13:58:47 -08005353 break;
5354 }
5355
Nick Armstrong-Crews56ecfcc2015-09-07 21:46:50 -07005356 case KeyEvent.KEYCODE_SOFT_SLEEP: {
5357 result &= ~ACTION_PASS_TO_USER;
5358 isWakeKey = false;
5359 if (!down) {
5360 mPowerManagerInternal.setUserInactiveOverrideFromWindowManager();
5361 }
5362 break;
5363 }
5364
Jeff Brown6212a492014-03-07 13:58:47 -08005365 case KeyEvent.KEYCODE_WAKEUP: {
5366 result &= ~ACTION_PASS_TO_USER;
Jose Lima9546b202014-07-02 17:21:51 -07005367 isWakeKey = true;
Jeff Brown6212a492014-03-07 13:58:47 -08005368 break;
5369 }
5370
Jeff Brown4d396052010-10-29 21:50:21 -07005371 case KeyEvent.KEYCODE_MEDIA_PLAY:
5372 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5373 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
Jeff Brown4d396052010-10-29 21:50:21 -07005374 case KeyEvent.KEYCODE_HEADSETHOOK:
5375 case KeyEvent.KEYCODE_MUTE:
5376 case KeyEvent.KEYCODE_MEDIA_STOP:
5377 case KeyEvent.KEYCODE_MEDIA_NEXT:
5378 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5379 case KeyEvent.KEYCODE_MEDIA_REWIND:
5380 case KeyEvent.KEYCODE_MEDIA_RECORD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005381 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
5382 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK: {
RoboErikde9ba392014-09-26 12:51:01 -07005383 if (MediaSessionLegacyHelper.getHelper(mContext).isGlobalPriorityActive()) {
5384 // If the global session is active pass all media keys to it
5385 // instead of the active window.
5386 result &= ~ACTION_PASS_TO_USER;
5387 }
Jeff Brown4d396052010-10-29 21:50:21 -07005388 if ((result & ACTION_PASS_TO_USER) == 0) {
5389 // Only do this if we would otherwise not pass it to the user. In that
5390 // case, the PhoneWindow class will do the same thing, except it will
5391 // only do it if the showing app doesn't process the key on its own.
Jeff Brown40013652012-05-16 21:22:36 -07005392 // Note that we need to make a copy of the key event here because the
5393 // original key event will be recycled when we return.
Jeff Brown4d396052010-10-29 21:50:21 -07005394 mBroadcastWakeLock.acquire();
Jeff Brown40013652012-05-16 21:22:36 -07005395 Message msg = mHandler.obtainMessage(MSG_DISPATCH_MEDIA_KEY_WITH_WAKE_LOCK,
5396 new KeyEvent(event));
5397 msg.setAsynchronous(true);
5398 msg.sendToTarget();
Jeff Brown4d396052010-10-29 21:50:21 -07005399 }
5400 break;
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005401 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005402
Jeff Brown4d396052010-10-29 21:50:21 -07005403 case KeyEvent.KEYCODE_CALL: {
5404 if (down) {
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005405 TelecomManager telecomManager = getTelecommService();
5406 if (telecomManager != null) {
5407 if (telecomManager.isRinging()) {
Santos Cordon6848f722014-05-21 15:22:12 -07005408 Log.i(TAG, "interceptKeyBeforeQueueing:"
5409 + " CALL key-down while ringing: Answer the call!");
Tyler Gunnef9f6f92014-09-12 22:16:17 -07005410 telecomManager.acceptRingingCall();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005411
Santos Cordon6848f722014-05-21 15:22:12 -07005412 // And *don't* pass this key thru to the current activity
5413 // (which is presumably the InCallScreen.)
5414 result &= ~ACTION_PASS_TO_USER;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005415 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005416 }
Jeff Brown00fa7bd2010-07-02 15:37:36 -07005417 }
Jeff Brown4d396052010-10-29 21:50:21 -07005418 break;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005419 }
Michael Wright869a67c2014-08-26 19:33:06 -07005420 case KeyEvent.KEYCODE_VOICE_ASSIST: {
5421 // Only do this if we would otherwise not pass it to the user. In that case,
5422 // interceptKeyBeforeDispatching would apply a similar but different policy in
5423 // order to invoke voice assist actions. Note that we need to make a copy of the
5424 // key event here because the original key event will be recycled when we return.
5425 if ((result & ACTION_PASS_TO_USER) == 0 && !down) {
5426 mBroadcastWakeLock.acquire();
5427 Message msg = mHandler.obtainMessage(MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK,
5428 keyguardActive ? 1 : 0, 0);
5429 msg.setAsynchronous(true);
5430 msg.sendToTarget();
5431 }
Jaewan Kim49117872016-01-19 17:24:08 +09005432 break;
5433 }
5434 case KeyEvent.KEYCODE_WINDOW: {
5435 if (mShortPressWindowBehavior == SHORT_PRESS_WINDOW_PICTURE_IN_PICTURE) {
5436 if (!down) {
Jaewan Kimc552b042016-01-18 16:08:45 +09005437 requestTvPictureInPicture(event);
Jaewan Kim49117872016-01-19 17:24:08 +09005438 }
5439 result &= ~ACTION_PASS_TO_USER;
5440 }
5441 break;
Michael Wright869a67c2014-08-26 19:33:06 -07005442 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005443 }
Jeff Brown26875502014-01-30 21:47:47 -08005444
Jeff Brownbae8e772014-06-12 19:59:45 -07005445 if (useHapticFeedback) {
5446 performHapticFeedbackLw(null, HapticFeedbackConstants.VIRTUAL_KEY, false);
5447 }
5448
Jeff Brown26875502014-01-30 21:47:47 -08005449 if (isWakeKey) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005450 wakeUp(event.getEventTime(), mAllowTheaterModeWakeFromKey, "android.policy:KEY");
Jeff Brown26875502014-01-30 21:47:47 -08005451 }
Bryce Lee584a4452014-10-21 15:55:55 -07005452
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005453 return result;
5454 }
5455
Jeff Brown1c2e4942012-11-06 16:32:01 -08005456 /**
Jeff Brown13f00f02014-10-31 14:45:50 -07005457 * Returns true if the key can have global actions attached to it.
5458 * We reserve all power management keys for the system since they require
5459 * very careful handling.
5460 */
5461 private static boolean isValidGlobalKey(int keyCode) {
5462 switch (keyCode) {
5463 case KeyEvent.KEYCODE_POWER:
5464 case KeyEvent.KEYCODE_WAKEUP:
5465 case KeyEvent.KEYCODE_SLEEP:
5466 return false;
5467 default:
5468 return true;
5469 }
5470 }
5471
5472 /**
Jeff Brown1c2e4942012-11-06 16:32:01 -08005473 * When the screen is off we ignore some keys that might otherwise typically
5474 * be considered wake keys. We filter them out here.
5475 *
5476 * {@link KeyEvent#KEYCODE_POWER} is notably absent from this list because it
5477 * is always considered a wake key.
5478 */
5479 private boolean isWakeKeyWhenScreenOff(int keyCode) {
5480 switch (keyCode) {
5481 // ignore volume keys unless docked
5482 case KeyEvent.KEYCODE_VOLUME_UP:
5483 case KeyEvent.KEYCODE_VOLUME_DOWN:
5484 case KeyEvent.KEYCODE_VOLUME_MUTE:
5485 return mDockMode != Intent.EXTRA_DOCK_STATE_UNDOCKED;
5486
5487 // ignore media and camera keys
5488 case KeyEvent.KEYCODE_MUTE:
5489 case KeyEvent.KEYCODE_HEADSETHOOK:
5490 case KeyEvent.KEYCODE_MEDIA_PLAY:
5491 case KeyEvent.KEYCODE_MEDIA_PAUSE:
5492 case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
5493 case KeyEvent.KEYCODE_MEDIA_STOP:
5494 case KeyEvent.KEYCODE_MEDIA_NEXT:
5495 case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
5496 case KeyEvent.KEYCODE_MEDIA_REWIND:
5497 case KeyEvent.KEYCODE_MEDIA_RECORD:
5498 case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
Jaekyun Seokbfdad8e2013-07-08 13:53:21 +09005499 case KeyEvent.KEYCODE_MEDIA_AUDIO_TRACK:
Jeff Brown1c2e4942012-11-06 16:32:01 -08005500 case KeyEvent.KEYCODE_CAMERA:
5501 return false;
5502 }
5503 return true;
5504 }
5505
5506
Jeff Brown56194eb2011-03-02 19:23:13 -08005507 /** {@inheritDoc} */
5508 @Override
Michael Wright70af00a2014-09-03 19:30:20 -07005509 public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags) {
5510 if ((policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005511 if (wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotion,
5512 "android.policy:MOTION")) {
Bryce Lee5c138322014-11-03 08:26:09 -08005513 return 0;
5514 }
Michael Wright70af00a2014-09-03 19:30:20 -07005515 }
Bryce Lee5c138322014-11-03 08:26:09 -08005516
Michael Wright70af00a2014-09-03 19:30:20 -07005517 if (shouldDispatchInputWhenNonInteractive()) {
5518 return ACTION_PASS_TO_USER;
5519 }
Bryce Lee5c138322014-11-03 08:26:09 -08005520
Bryce Lee812d7022014-11-10 13:33:28 -08005521 // If we have not passed the action up and we are in theater mode without dreaming,
5522 // there will be no dream to intercept the touch and wake into ambient. The device should
5523 // wake up in this case.
5524 if (isTheaterModeEnabled() && (policyFlags & FLAG_WAKE) != 0) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005525 wakeUp(whenNanos / 1000000, mAllowTheaterModeWakeFromMotionWhenNotDreaming,
5526 "android.policy:MOTION");
Bryce Lee812d7022014-11-10 13:33:28 -08005527 }
5528
Jeff Brown037c33e2014-04-09 00:31:55 -07005529 return 0;
Jeff Brown56194eb2011-03-02 19:23:13 -08005530 }
5531
Michael Wright70af00a2014-09-03 19:30:20 -07005532 private boolean shouldDispatchInputWhenNonInteractive() {
Joe LaPennaf2b9b2d2015-11-17 22:22:37 +00005533 // Send events to keyguard while the screen is on.
5534 if (isKeyguardShowingAndNotOccluded() && mDisplay != null
5535 && mDisplay.getState() != Display.STATE_OFF) {
Bryce Lee5c138322014-11-03 08:26:09 -08005536 return true;
5537 }
5538
5539 // Send events to a dozing dream even if the screen is off since the dream
5540 // is in control of the state of the screen.
5541 IDreamManager dreamManager = getDreamManager();
5542
5543 try {
5544 if (dreamManager != null && dreamManager.isDreaming()) {
5545 return true;
5546 }
5547 } catch (RemoteException e) {
5548 Slog.e(TAG, "RemoteException when checking if dreaming", e);
5549 }
5550
5551 // Otherwise, consume events since the user can't see what is being
5552 // interacted with.
5553 return false;
Michael Wright70af00a2014-09-03 19:30:20 -07005554 }
5555
RoboErik001c59c2015-01-26 15:53:51 -08005556 private void dispatchDirectAudioEvent(KeyEvent event) {
5557 if (event.getAction() != KeyEvent.ACTION_DOWN) {
5558 return;
5559 }
5560 int keyCode = event.getKeyCode();
John Spurlockb94f2d62015-03-17 14:11:57 -04005561 int flags = AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND
5562 | AudioManager.FLAG_FROM_KEY;
RoboErik001c59c2015-01-26 15:53:51 -08005563 String pkgName = mContext.getOpPackageName();
5564 switch (keyCode) {
5565 case KeyEvent.KEYCODE_VOLUME_UP:
5566 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005567 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_RAISE,
John Spurlock90874332015-03-10 16:00:54 -04005568 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005569 } catch (RemoteException e) {
5570 Log.e(TAG, "Error dispatching volume up in dispatchTvAudioEvent.", e);
5571 }
5572 break;
5573 case KeyEvent.KEYCODE_VOLUME_DOWN:
5574 try {
John Spurlockee5ad722015-03-03 16:17:21 -05005575 getAudioService().adjustSuggestedStreamVolume(AudioManager.ADJUST_LOWER,
John Spurlock90874332015-03-10 16:00:54 -04005576 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005577 } catch (RemoteException e) {
5578 Log.e(TAG, "Error dispatching volume down in dispatchTvAudioEvent.", e);
5579 }
5580 break;
5581 case KeyEvent.KEYCODE_VOLUME_MUTE:
5582 try {
5583 if (event.getRepeatCount() == 0) {
John Spurlockee5ad722015-03-03 16:17:21 -05005584 getAudioService().adjustSuggestedStreamVolume(
5585 AudioManager.ADJUST_TOGGLE_MUTE,
John Spurlock90874332015-03-10 16:00:54 -04005586 AudioManager.USE_DEFAULT_STREAM_TYPE, flags, pkgName, TAG);
RoboErik001c59c2015-01-26 15:53:51 -08005587 }
5588 } catch (RemoteException e) {
5589 Log.e(TAG, "Error dispatching mute in dispatchTvAudioEvent.", e);
5590 }
5591 break;
5592 }
5593 }
5594
Jeff Brown40013652012-05-16 21:22:36 -07005595 void dispatchMediaKeyWithWakeLock(KeyEvent event) {
5596 if (DEBUG_INPUT) {
5597 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: " + event);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005598 }
5599
Jeff Brown40013652012-05-16 21:22:36 -07005600 if (mHavePendingMediaKeyRepeatWithWakeLock) {
5601 if (DEBUG_INPUT) {
5602 Slog.d(TAG, "dispatchMediaKeyWithWakeLock: canceled repeat");
5603 }
5604
5605 mHandler.removeMessages(MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK);
5606 mHavePendingMediaKeyRepeatWithWakeLock = false;
5607 mBroadcastWakeLock.release(); // pending repeat was holding onto the wake lock
5608 }
5609
5610 dispatchMediaKeyWithWakeLockToAudioService(event);
5611
5612 if (event.getAction() == KeyEvent.ACTION_DOWN
5613 && event.getRepeatCount() == 0) {
5614 mHavePendingMediaKeyRepeatWithWakeLock = true;
5615
5616 Message msg = mHandler.obtainMessage(
5617 MSG_DISPATCH_MEDIA_KEY_REPEAT_WITH_WAKE_LOCK, event);
5618 msg.setAsynchronous(true);
5619 mHandler.sendMessageDelayed(msg, ViewConfiguration.getKeyRepeatTimeout());
5620 } else {
5621 mBroadcastWakeLock.release();
5622 }
5623 }
5624
5625 void dispatchMediaKeyRepeatWithWakeLock(KeyEvent event) {
5626 mHavePendingMediaKeyRepeatWithWakeLock = false;
5627
5628 KeyEvent repeatEvent = KeyEvent.changeTimeRepeat(event,
5629 SystemClock.uptimeMillis(), 1, event.getFlags() | KeyEvent.FLAG_LONG_PRESS);
5630 if (DEBUG_INPUT) {
5631 Slog.d(TAG, "dispatchMediaKeyRepeatWithWakeLock: " + repeatEvent);
5632 }
5633
5634 dispatchMediaKeyWithWakeLockToAudioService(repeatEvent);
5635 mBroadcastWakeLock.release();
5636 }
5637
5638 void dispatchMediaKeyWithWakeLockToAudioService(KeyEvent event) {
5639 if (ActivityManagerNative.isSystemReady()) {
RoboErik430fc482014-06-12 15:49:20 -07005640 MediaSessionLegacyHelper.getHelper(mContext).sendMediaButtonEvent(event, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005641 }
5642 }
5643
Michael Wright869a67c2014-08-26 19:33:06 -07005644 void launchVoiceAssistWithWakeLock(boolean keyguardActive) {
Dianne Hackbornb6683c42015-06-18 17:40:33 -07005645 IDeviceIdleController dic = IDeviceIdleController.Stub.asInterface(
5646 ServiceManager.getService(Context.DEVICE_IDLE_CONTROLLER));
5647 if (dic != null) {
5648 try {
5649 dic.exitIdle("voice-search");
5650 } catch (RemoteException e) {
5651 }
5652 }
Michael Wright869a67c2014-08-26 19:33:06 -07005653 Intent voiceIntent =
5654 new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
5655 voiceIntent.putExtra(RecognizerIntent.EXTRA_SECURE, keyguardActive);
Bart Sears8b1c27c2015-03-18 23:51:02 +00005656 startActivityAsUser(voiceIntent, UserHandle.CURRENT_OR_SELF);
Michael Wright869a67c2014-08-26 19:33:06 -07005657 mBroadcastWakeLock.release();
5658 }
5659
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005660 BroadcastReceiver mDockReceiver = new BroadcastReceiver() {
Craig Mautnereee29c42013-01-17 14:44:34 -08005661 @Override
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005662 public void onReceive(Context context, Intent intent) {
Dianne Hackborn867ab6472010-04-29 13:28:56 -07005663 if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
5664 mDockMode = intent.getIntExtra(Intent.EXTRA_DOCK_STATE,
5665 Intent.EXTRA_DOCK_STATE_UNDOCKED);
Daniel Sandler6396c722013-04-16 20:19:09 -04005666 } else {
5667 try {
5668 IUiModeManager uiModeService = IUiModeManager.Stub.asInterface(
5669 ServiceManager.getService(Context.UI_MODE_SERVICE));
5670 mUiMode = uiModeService.getCurrentModeType();
5671 } catch (RemoteException e) {
5672 }
Dianne Hackborn80fa1662009-10-07 14:02:10 -07005673 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07005674 updateRotation(true);
Craig Mautnereee29c42013-01-17 14:44:34 -08005675 synchronized (mLock) {
5676 updateOrientationListenerLp();
5677 }
Mike Lockwood1753f7f2009-08-24 14:49:07 -07005678 }
5679 };
5680
Jeff Brown6aaf2952012-10-05 16:01:08 -07005681 BroadcastReceiver mDreamReceiver = new BroadcastReceiver() {
5682 @Override
5683 public void onReceive(Context context, Intent intent) {
5684 if (Intent.ACTION_DREAMING_STARTED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005685 if (mKeyguardDelegate != null) {
5686 mKeyguardDelegate.onDreamingStarted();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005687 }
5688 } else if (Intent.ACTION_DREAMING_STOPPED.equals(intent.getAction())) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005689 if (mKeyguardDelegate != null) {
5690 mKeyguardDelegate.onDreamingStopped();
Jeff Brown6aaf2952012-10-05 16:01:08 -07005691 }
5692 }
5693 }
5694 };
5695
Christopher Tate5e08af02012-09-21 17:17:22 -07005696 BroadcastReceiver mMultiuserReceiver = new BroadcastReceiver() {
5697 @Override
5698 public void onReceive(Context context, Intent intent) {
5699 if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) {
5700 // tickle the settings observer: this first ensures that we're
5701 // observing the relevant settings for the newly-active user,
5702 // and then updates our own bookkeeping based on the now-
5703 // current user.
5704 mSettingsObserver.onChange(false);
John Spurlockce479d82012-11-29 09:52:21 -05005705
5706 // force a re-application of focused window sysui visibility.
5707 // the window may never have been shown for this user
5708 // e.g. the keyguard when going through the new-user setup flow
John Spurlock04db1762013-05-13 12:46:41 -04005709 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
John Spurlockce479d82012-11-29 09:52:21 -05005710 mLastSystemUiFlags = 0;
5711 updateSystemUiVisibilityLw();
5712 }
Christopher Tate5e08af02012-09-21 17:17:22 -07005713 }
5714 }
5715 };
5716
Adrian Roosddc8b272015-05-21 16:28:27 -07005717 private final Runnable mHiddenNavPanic = new Runnable() {
John Spurlockd9b70bd2014-02-06 17:02:44 -05005718 @Override
5719 public void run() {
Adrian Roosddc8b272015-05-21 16:28:27 -07005720 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
5721 if (!isUserSetupComplete()) {
5722 // Swipe-up for navigation bar is disabled during setup
5723 return;
5724 }
5725 mPendingPanicGestureUptime = SystemClock.uptimeMillis();
5726 mNavigationBarController.showTransient();
5727 }
John Spurlockd9b70bd2014-02-06 17:02:44 -05005728 }
5729 };
5730
John Spurlocke1f366f2013-08-05 12:22:40 -04005731 private void requestTransientBars(WindowState swipeTarget) {
John Spurlock04db1762013-05-13 12:46:41 -04005732 synchronized (mWindowManagerFuncs.getWindowManagerLock()) {
Maurice Lam99c6e072014-04-28 18:24:28 -07005733 if (!isUserSetupComplete()) {
5734 // Swipe-up for navigation bar is disabled during setup
5735 return;
5736 }
John Spurlock27735a42013-08-14 17:57:38 -04005737 boolean sb = mStatusBarController.checkShowTransientBarLw();
5738 boolean nb = mNavigationBarController.checkShowTransientBarLw();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005739 if (sb || nb) {
Adrian Roos62b65e42015-02-25 18:05:34 +01005740 // Don't show status bar when swiping on already visible navigation bar
5741 if (!nb && swipeTarget == mNavigationBar) {
John Spurlocke1f366f2013-08-05 12:22:40 -04005742 if (DEBUG) Slog.d(TAG, "Not showing transient bar, wrong swipe target");
John Spurlockad3e6cb2013-04-30 08:47:43 -04005743 return;
5744 }
John Spurlock27735a42013-08-14 17:57:38 -04005745 if (sb) mStatusBarController.showTransient();
5746 if (nb) mNavigationBarController.showTransient();
John Spurlockf1a36642013-10-12 17:50:42 -04005747 mImmersiveModeConfirmation.confirmCurrentPrompt();
John Spurlockad3e6cb2013-04-30 08:47:43 -04005748 updateSystemUiVisibilityLw();
John Spurlock32beb2c2013-03-11 10:16:47 -04005749 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04005750 }
5751 }
5752
Jeff Brown3ee549c2014-09-22 20:14:39 -07005753 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005754 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005755 public void startedGoingToSleep(int why) {
5756 if (DEBUG_WAKEUP) Slog.i(TAG, "Started going to sleep... (why=" + why + ")");
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005757 if (mKeyguardDelegate != null) {
5758 mKeyguardDelegate.onStartedGoingToSleep(why);
5759 }
Jeff Brown416c49c2015-05-26 19:50:18 -07005760 }
5761
5762 // Called on the PowerManager's Notifier thread.
5763 @Override
5764 public void finishedGoingToSleep(int why) {
Dianne Hackborn74489012009-03-24 20:50:09 -07005765 EventLog.writeEvent(70000, 0);
Jeff Brown416c49c2015-05-26 19:50:18 -07005766 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished going to sleep... (why=" + why + ")");
Chris Wren9bb290b2015-06-29 12:02:13 -04005767 MetricsLogger.histogram(mContext, "screen_timeout", mLockScreenTimeout / 1000);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005768
5769 // We must get this work done here because the power manager will drop
5770 // the wake lock and let the system suspend once this function returns.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005771 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005772 mAwake = false;
Jeff Browna20dda42014-05-27 20:57:24 -07005773 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005774 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005775 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005776 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005777 if (mKeyguardDelegate != null) {
Jorim Jaggid175b6c2015-05-27 15:39:09 -07005778 mKeyguardDelegate.onFinishedGoingToSleep(why);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005779 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005780 }
5781
Jeff Brown3ee549c2014-09-22 20:14:39 -07005782 // Called on the PowerManager's Notifier thread.
Jeff Brownc38c9be2012-10-04 13:16:19 -07005783 @Override
Jeff Brown416c49c2015-05-26 19:50:18 -07005784 public void startedWakingUp() {
Dianne Hackborn74489012009-03-24 20:50:09 -07005785 EventLog.writeEvent(70000, 1);
Jeff Brown416c49c2015-05-26 19:50:18 -07005786 if (DEBUG_WAKEUP) Slog.i(TAG, "Started waking up...");
Craig Mautner8a0da012014-05-31 15:13:37 -07005787
Jeff Brown3ee549c2014-09-22 20:14:39 -07005788 // Since goToSleep performs these functions synchronously, we must
5789 // do the same here. We cannot post this work to a handler because
5790 // that might cause it to become reordered with respect to what
5791 // may happen in a future call to goToSleep.
The Android Open Source Project0727d222009-03-11 12:11:58 -07005792 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005793 mAwake = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005794
Jeff Browna20dda42014-05-27 20:57:24 -07005795 updateWakeGestureListenerLp();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005796 updateOrientationListenerLp();
Mike Lockwood28569302010-01-28 11:54:40 -05005797 updateLockScreenTimeout();
The Android Open Source Project0727d222009-03-11 12:11:58 -07005798 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005799
Jim Miller5ecd8112013-01-09 18:50:26 -08005800 if (mKeyguardDelegate != null) {
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005801 mKeyguardDelegate.onStartedWakingUp();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005802 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005803 }
5804
Jeff Brown416c49c2015-05-26 19:50:18 -07005805 // Called on the PowerManager's Notifier thread.
5806 @Override
5807 public void finishedWakingUp() {
5808 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished waking up...");
5809 }
5810
5811 private void wakeUpFromPowerKey(long eventTime) {
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005812 wakeUp(eventTime, mAllowTheaterModeWakeFromPowerKey, "android.policy:POWER");
Jeff Brown416c49c2015-05-26 19:50:18 -07005813 }
5814
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005815 private boolean wakeUp(long wakeTime, boolean wakeInTheaterMode, String reason) {
Bryce Leed3896842015-06-23 17:06:51 -07005816 final boolean theaterModeEnabled = isTheaterModeEnabled();
5817 if (!wakeInTheaterMode && theaterModeEnabled) {
Jeff Brown416c49c2015-05-26 19:50:18 -07005818 return false;
5819 }
5820
Bryce Leed3896842015-06-23 17:06:51 -07005821 if (theaterModeEnabled) {
5822 Settings.Global.putInt(mContext.getContentResolver(),
5823 Settings.Global.THEATER_MODE_ON, 0);
5824 }
5825
Dianne Hackborn280a64e2015-07-13 14:48:08 -07005826 mPowerManager.wakeUp(wakeTime, reason);
Jeff Brown416c49c2015-05-26 19:50:18 -07005827 return true;
5828 }
5829
Jeff Brown36c4db82014-09-19 12:05:31 -07005830 private void finishKeyguardDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005831 synchronized (mLock) {
Jorim Jaggif3255482015-07-24 12:32:42 -07005832 if (!mScreenOnEarly || mKeyguardDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005833 return; // We are not awake yet or we have already informed of this event.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005834 }
5835
Jeff Brown36c4db82014-09-19 12:05:31 -07005836 mKeyguardDrawComplete = true;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005837 if (mKeyguardDelegate != null) {
5838 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5839 }
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005840 mWindowManagerDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005841 }
5842
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005843 // ... eventually calls finishWindowsDrawn which will finalize our screen turn on
5844 // as well as enabling the orientation change logic/sensor.
5845 mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback,
5846 WAITING_FOR_DRAWN_TIMEOUT);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005847 }
5848
5849 // Called on the DisplayManager's DisplayPowerController thread.
5850 @Override
5851 public void screenTurnedOff() {
5852 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off...");
5853
Jeff Brown48d1b142015-06-10 16:36:03 -07005854 updateScreenOffSleepToken(true);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005855 synchronized (mLock) {
5856 mScreenOnEarly = false;
5857 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005858 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005859 mWindowManagerDrawComplete = false;
5860 mScreenOnListener = null;
5861 updateOrientationListenerLp();
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005862
5863 if (mKeyguardDelegate != null) {
5864 mKeyguardDelegate.onScreenTurnedOff();
5865 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005866 }
5867 }
5868
Jeff Brown3ee549c2014-09-22 20:14:39 -07005869 // Called on the DisplayManager's DisplayPowerController thread.
Jeff Brown36c4db82014-09-19 12:05:31 -07005870 @Override
5871 public void screenTurningOn(final ScreenOnListener screenOnListener) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005872 if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on...");
Jeff Brown36c4db82014-09-19 12:05:31 -07005873
Jeff Brown48d1b142015-06-10 16:36:03 -07005874 updateScreenOffSleepToken(false);
Jeff Brown3ee549c2014-09-22 20:14:39 -07005875 synchronized (mLock) {
5876 mScreenOnEarly = true;
5877 mScreenOnFully = false;
Jorim Jaggi95c6dae2015-07-29 15:17:23 -07005878 mKeyguardDrawComplete = false;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005879 mWindowManagerDrawComplete = false;
5880 mScreenOnListener = screenOnListener;
Jeff Brown36c4db82014-09-19 12:05:31 -07005881
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005882 if (mKeyguardDelegate != null) {
Jorim Jaggia4b51bc2015-08-10 18:20:43 -07005883 mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT);
5884 mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000);
Jorim Jaggi4cfdcf52015-07-09 12:13:59 -07005885 mKeyguardDelegate.onScreenTurningOn(mKeyguardDrawnCallback);
5886 } else {
5887 if (DEBUG_WAKEUP) Slog.d(TAG,
5888 "null mKeyguardDelegate: setting mKeyguardDrawComplete.");
5889 finishKeyguardDrawn();
5890 }
5891 }
Jeff Brown36c4db82014-09-19 12:05:31 -07005892 }
5893
Jorim Jaggi0d210f62015-07-10 14:24:44 -07005894 // Called on the DisplayManager's DisplayPowerController thread.
5895 @Override
5896 public void screenTurnedOn() {
5897 synchronized (mLock) {
5898 if (mKeyguardDelegate != null) {
5899 mKeyguardDelegate.onScreenTurnedOn();
5900 }
5901 }
5902 }
5903
Jeff Brown36c4db82014-09-19 12:05:31 -07005904 private void finishWindowsDrawn() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005905 synchronized (mLock) {
5906 if (!mScreenOnEarly || mWindowManagerDrawComplete) {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005907 return; // Screen is not turned on or we did already handle this case earlier.
Jeff Brown3ee549c2014-09-22 20:14:39 -07005908 }
5909
Jeff Brown36c4db82014-09-19 12:05:31 -07005910 mWindowManagerDrawComplete = true;
Jeff Brown36c4db82014-09-19 12:05:31 -07005911 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005912
5913 finishScreenTurningOn();
Jeff Brownc38c9be2012-10-04 13:16:19 -07005914 }
5915
Craig Mautner8a0da012014-05-31 15:13:37 -07005916 private void finishScreenTurningOn() {
Stefan Kuhne9326dc12015-06-12 09:25:32 -10005917 synchronized (mLock) {
5918 // We have just finished drawing screen content. Since the orientation listener
5919 // gets only installed when all windows are drawn, we try to install it again.
5920 updateOrientationListenerLp();
5921 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005922 final ScreenOnListener listener;
5923 final boolean enableScreen;
Jeff Brown36c4db82014-09-19 12:05:31 -07005924 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005925 if (DEBUG_WAKEUP) Slog.d(TAG,
5926 "finishScreenTurningOn: mAwake=" + mAwake
5927 + ", mScreenOnEarly=" + mScreenOnEarly
5928 + ", mScreenOnFully=" + mScreenOnFully
5929 + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete
5930 + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete);
5931
5932 if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete
5933 || (mAwake && !mKeyguardDrawComplete)) {
5934 return; // spurious or not ready yet
Jeff Brown36c4db82014-09-19 12:05:31 -07005935 }
5936
Jeff Brown3ee549c2014-09-22 20:14:39 -07005937 if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on...");
5938 listener = mScreenOnListener;
Craig Mautner13f6ea72014-06-23 14:57:02 -07005939 mScreenOnListener = null;
Jeff Brown3ee549c2014-09-22 20:14:39 -07005940 mScreenOnFully = true;
5941
5942 // Remember the first time we draw the keyguard so we know when we're done with
5943 // the main part of booting and can enable the screen and hide boot messages.
5944 if (!mKeyguardDrawnOnce && mAwake) {
5945 mKeyguardDrawnOnce = true;
5946 enableScreen = true;
5947 if (mBootMessageNeedsHiding) {
5948 mBootMessageNeedsHiding = false;
5949 hideBootMessages();
5950 }
5951 } else {
5952 enableScreen = false;
5953 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005954 }
5955
Jeff Brown3ee549c2014-09-22 20:14:39 -07005956 if (listener != null) {
5957 listener.onScreenOn();
5958 }
Jeff Brown4fc45272012-10-10 18:28:14 -07005959
Jeff Brown3ee549c2014-09-22 20:14:39 -07005960 if (enableScreen) {
5961 try {
5962 mWindowManager.enableScreenIfNeeded();
5963 } catch (RemoteException unhandled) {
Jeff Brown36c4db82014-09-19 12:05:31 -07005964 }
Craig Mautnera631d492014-08-05 15:16:01 -07005965 }
5966 }
5967
5968 private void handleHideBootMessage() {
Jeff Brown3ee549c2014-09-22 20:14:39 -07005969 synchronized (mLock) {
5970 if (!mKeyguardDrawnOnce) {
5971 mBootMessageNeedsHiding = true;
5972 return; // keyguard hasn't drawn the first time yet, not done booting
5973 }
Craig Mautnera631d492014-08-05 15:16:01 -07005974 }
Jeff Brown3ee549c2014-09-22 20:14:39 -07005975
5976 if (mBootMsgDialog != null) {
5977 if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing");
5978 mBootMsgDialog.dismiss();
5979 mBootMsgDialog = null;
Craig Mautnera631d492014-08-05 15:16:01 -07005980 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005981 }
5982
5983 @Override
Jeff Brown3ee549c2014-09-22 20:14:39 -07005984 public boolean isScreenOn() {
5985 return mScreenOnFully;
Dianne Hackborn08743722009-12-21 12:16:51 -08005986 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07005987
Dianne Hackborn08743722009-12-21 12:16:51 -08005988 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005989 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005990 public void enableKeyguard(boolean enabled) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005991 if (mKeyguardDelegate != null) {
5992 mKeyguardDelegate.setKeyguardEnabled(enabled);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07005993 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005994 }
5995
5996 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07005997 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08005998 public void exitKeyguardSecurely(OnKeyguardExitResult callback) {
Jim Miller5ecd8112013-01-09 18:50:26 -08005999 if (mKeyguardDelegate != null) {
6000 mKeyguardDelegate.verifyUnlock(callback);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006001 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006002 }
6003
Jim Millerab954542014-10-10 18:21:49 -07006004 private boolean isKeyguardShowingAndNotOccluded() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006005 if (mKeyguardDelegate == null) return false;
Jim Millerab954542014-10-10 18:21:49 -07006006 return mKeyguardDelegate.isShowing() && !mKeyguardOccluded;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006007 }
6008
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006009 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006010 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006011 public boolean isKeyguardLocked() {
6012 return keyguardOn();
6013 }
6014
6015 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006016 @Override
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006017 public boolean isKeyguardSecure() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006018 if (mKeyguardDelegate == null) return false;
6019 return mKeyguardDelegate.isSecure();
Mike Lockwood520d8bc2011-02-18 13:23:13 -05006020 }
6021
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006022 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006023 @Override
Adrian Roos461829d2015-06-03 14:41:18 -07006024 public boolean isKeyguardShowingOrOccluded() {
6025 return mKeyguardDelegate == null ? false : mKeyguardDelegate.isShowing();
6026 }
6027
6028 /** {@inheritDoc} */
6029 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006030 public boolean inKeyguardRestrictedKeyInputMode() {
Jim Miller5ecd8112013-01-09 18:50:26 -08006031 if (mKeyguardDelegate == null) return false;
6032 return mKeyguardDelegate.isInputRestricted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006033 }
6034
Jose Lima9546b202014-07-02 17:21:51 -07006035 @Override
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006036 public void dismissKeyguardLw() {
RoboErik8a2cfc32014-05-16 11:19:38 -07006037 if (mKeyguardDelegate != null && mKeyguardDelegate.isShowing()) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006038 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.dismissKeyguardLw");
Daniel Sandler1ce804392012-11-07 15:07:12 -05006039 mHandler.post(new Runnable() {
Jose Lima9546b202014-07-02 17:21:51 -07006040 @Override
Daniel Sandler1ce804392012-11-07 15:07:12 -05006041 public void run() {
Jorim Jaggi8de4311c2014-08-11 22:36:20 +02006042 // ask the keyguard to prompt the user to authenticate if necessary
6043 mKeyguardDelegate.dismiss();
6044 }
6045 });
6046 }
6047 }
6048
6049 public void notifyActivityDrawnForKeyguardLw() {
6050 if (mKeyguardDelegate != null) {
6051 mHandler.post(new Runnable() {
6052 @Override
6053 public void run() {
6054 mKeyguardDelegate.onActivityDrawn();
Daniel Sandler1ce804392012-11-07 15:07:12 -05006055 }
6056 });
Dianne Hackborn90c52de2011-09-23 12:57:44 -07006057 }
6058 }
6059
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006060 @Override
6061 public boolean isKeyguardDrawnLw() {
6062 synchronized (mLock) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006063 return mKeyguardDrawnOnce;
Jorim Jaggicff0acb2014-03-31 16:35:15 +02006064 }
6065 }
6066
Jorim Jaggi0d674622014-05-21 01:34:15 +02006067 @Override
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006068 public void startKeyguardExitAnimation(long startTime, long fadeoutDuration) {
Jorim Jaggi0d674622014-05-21 01:34:15 +02006069 if (mKeyguardDelegate != null) {
Craig Mautnerc0d2d0a2014-10-31 16:25:15 -07006070 if (DEBUG_KEYGUARD) Slog.d(TAG, "PWM.startKeyguardExitAnimation");
Jorim Jaggie29b2db2014-05-30 23:17:03 +02006071 mKeyguardDelegate.startKeyguardExitAnimation(startTime, fadeoutDuration);
Jorim Jaggi0d674622014-05-21 01:34:15 +02006072 }
6073 }
6074
Jorim Jaggi737af722015-12-31 10:42:27 +01006075 @Override
6076 public void getStableInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6077 Rect outInsets) {
6078 outInsets.setEmpty();
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006079
6080 // Navigation bar and status bar.
6081 getNonDecorInsetsLw(displayRotation, displayWidth, displayHeight, outInsets);
Jorim Jaggi737af722015-12-31 10:42:27 +01006082 if (mStatusBar != null) {
6083 outInsets.top = mStatusBarHeight;
6084 }
Jorim Jaggi82c9dc92016-02-05 15:10:33 -08006085 }
6086
6087 @Override
6088 public void getNonDecorInsetsLw(int displayRotation, int displayWidth, int displayHeight,
6089 Rect outInsets) {
6090 outInsets.setEmpty();
6091
6092 // Only navigation bar
Jorim Jaggi737af722015-12-31 10:42:27 +01006093 if (mNavigationBar != null) {
6094 if (isNavigationBarOnBottom(displayWidth, displayHeight)) {
6095 outInsets.bottom = getNavigationBarHeight(displayRotation, mUiMode);
6096 } else {
6097 outInsets.right = getNavigationBarWidth(displayRotation, mUiMode);
6098 }
6099 }
6100 }
6101
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006102 void sendCloseSystemWindows() {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006103 PhoneWindow.sendCloseSystemWindows(mContext, null);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006104 }
6105
6106 void sendCloseSystemWindows(String reason) {
Jorim Jaggib10e33f2015-02-04 21:57:40 +01006107 PhoneWindow.sendCloseSystemWindows(mContext, reason);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006108 }
Mitsuru Oshima831d0d92009-06-16 18:27:18 -07006109
Jeff Brown01a98dd2011-09-20 15:08:29 -07006110 @Override
6111 public int rotationForOrientationLw(int orientation, int lastRotation) {
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006112 if (false) {
6113 Slog.v(TAG, "rotationForOrientationLw(orient="
6114 + orientation + ", last=" + lastRotation
6115 + "); user=" + mUserRotation + " "
6116 + ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED)
6117 ? "USER_ROTATION_LOCKED" : "")
6118 );
6119 }
6120
Craig Mautner46ac6fa2013-08-01 10:06:34 -07006121 if (mForceDefaultOrientation) {
6122 return Surface.ROTATION_0;
6123 }
6124
The Android Open Source Project0727d222009-03-11 12:11:58 -07006125 synchronized (mLock) {
Jeff Brownc0347aa2011-09-23 17:26:09 -07006126 int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
6127 if (sensorRotation < 0) {
Jeff Brown0f862b42012-09-27 21:11:01 -07006128 sensorRotation = lastRotation;
Jeff Brownc0347aa2011-09-23 17:26:09 -07006129 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006130
Jeff Browndec6cf42011-11-15 14:08:20 -08006131 final int preferredRotation;
Jeff Brown2e7760e2012-04-11 15:14:55 -07006132 if (mLidState == LID_OPEN && mLidOpenRotation >= 0) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006133 // Ignore sensor when lid switch is open and rotation is forced.
6134 preferredRotation = mLidOpenRotation;
6135 } else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
Jeff Brownc0347aa2011-09-23 17:26:09 -07006136 && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006137 // Ignore sensor when in car dock unless explicitly enabled.
6138 // This case can override the behavior of NOSENSOR, and can also
6139 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006140 preferredRotation = mCarDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006141 ? sensorRotation : mCarDockRotation;
Jeff Brown1a693182011-11-08 14:44:16 -08006142 } else if ((mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6143 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK
6144 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK)
Jeff Brownc0347aa2011-09-23 17:26:09 -07006145 && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006146 // Ignore sensor when in desk dock unless explicitly enabled.
6147 // This case can override the behavior of NOSENSOR, and can also
6148 // enable 180 degree rotation while docked.
Jeff Brownc0347aa2011-09-23 17:26:09 -07006149 preferredRotation = mDeskDockEnablesAccelerometer
Jeff Brown01a98dd2011-09-20 15:08:29 -07006150 ? sensorRotation : mDeskDockRotation;
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006151 } else if (mHdmiPlugged && mDemoHdmiRotationLock) {
6152 // Ignore sensor when plugged into HDMI when demo HDMI rotation lock enabled.
Jeff Browneb3e4b92011-12-06 19:54:24 -08006153 // Note that the dock orientation overrides the HDMI orientation.
Jeff Brownc82c89ed2013-04-17 17:18:15 -07006154 preferredRotation = mDemoHdmiRotation;
6155 } else if (mHdmiPlugged && mDockMode == Intent.EXTRA_DOCK_STATE_UNDOCKED
6156 && mUndockedHdmiRotation >= 0) {
6157 // Ignore sensor when plugged into HDMI and an undocked orientation has
6158 // been specified in the configuration (only for legacy devices without
6159 // full multi-display support).
6160 // Note that the dock orientation overrides the HDMI orientation.
6161 preferredRotation = mUndockedHdmiRotation;
Chong Zhangae6119ff2014-11-11 18:54:39 -08006162 } else if (mDemoRotationLock) {
6163 // Ignore sensor when demo rotation lock is enabled.
6164 // Note that the dock orientation and HDMI rotation lock override this.
6165 preferredRotation = mDemoRotation;
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006166 } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) {
6167 // Application just wants to remain locked in the last rotation.
6168 preferredRotation = lastRotation;
Jeff Brownbcdfc622014-03-06 19:13:04 -08006169 } else if (!mSupportAutoRotation) {
6170 // If we don't support auto-rotation then bail out here and ignore
6171 // the sensor and any rotation lock settings.
6172 preferredRotation = -1;
Jeff Brown207673cd2012-06-05 17:47:11 -07006173 } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE
Jeff Brown01a98dd2011-09-20 15:08:29 -07006174 && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006175 || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
6176 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
6177 || orientation == ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
6178 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER))
Jeff Brown01a98dd2011-09-20 15:08:29 -07006179 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR
6180 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6181 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
6182 || orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
6183 // Otherwise, use sensor only if requested by the application or enabled
6184 // by default for USER or UNSPECIFIED modes. Does not apply to NOSENSOR.
Jeff Brownd3187e32011-09-21 19:26:44 -07006185 if (mAllowAllRotations < 0) {
6186 // Can't read this during init() because the context doesn't
6187 // have display metrics at that time so we cannot determine
6188 // tablet vs. phone then.
6189 mAllowAllRotations = mContext.getResources().getBoolean(
6190 com.android.internal.R.bool.config_allowAllRotations) ? 1 : 0;
6191 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006192 if (sensorRotation != Surface.ROTATION_180
Jeff Brownd3187e32011-09-21 19:26:44 -07006193 || mAllowAllRotations == 1
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006194 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
6195 || orientation == ActivityInfo.SCREEN_ORIENTATION_FULL_USER) {
Jeff Brown01a98dd2011-09-20 15:08:29 -07006196 preferredRotation = sensorRotation;
6197 } else {
6198 preferredRotation = lastRotation;
6199 }
Jeff Brown207673cd2012-06-05 17:47:11 -07006200 } else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED
6201 && orientation != ActivityInfo.SCREEN_ORIENTATION_NOSENSOR) {
6202 // Apply rotation lock. Does not apply to NOSENSOR.
6203 // The idea is that the user rotation expresses a weak preference for the direction
6204 // of gravity and as NOSENSOR is never affected by gravity, then neither should
6205 // NOSENSOR be affected by rotation lock (although it will be affected by docks).
Jeff Brown4dfce202011-10-05 12:00:10 -07006206 preferredRotation = mUserRotation;
Jeff Browndec6cf42011-11-15 14:08:20 -08006207 } else {
6208 // No overriding preference.
6209 // We will do exactly what the application asked us to do.
6210 preferredRotation = -1;
Jeff Brown01a98dd2011-09-20 15:08:29 -07006211 }
6212
Dianne Hackborne5439f22010-10-02 16:53:50 -07006213 switch (orientation) {
6214 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006215 // Return portrait unless overridden.
6216 if (isAnyPortrait(preferredRotation)) {
6217 return preferredRotation;
6218 }
Dianne Hackborne5439f22010-10-02 16:53:50 -07006219 return mPortraitRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006220
Jeff Brown01a98dd2011-09-20 15:08:29 -07006221 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006222 // Return landscape unless overridden.
6223 if (isLandscapeOrSeascape(preferredRotation)) {
6224 return preferredRotation;
6225 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006226 return mLandscapeRotation;
6227
6228 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
Jeff Browndec6cf42011-11-15 14:08:20 -08006229 // Return reverse portrait unless overridden.
6230 if (isAnyPortrait(preferredRotation)) {
6231 return preferredRotation;
6232 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006233 return mUpsideDownRotation;
6234
6235 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
Jeff Browndec6cf42011-11-15 14:08:20 -08006236 // Return seascape unless overridden.
6237 if (isLandscapeOrSeascape(preferredRotation)) {
6238 return preferredRotation;
6239 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006240 return mSeascapeRotation;
6241
6242 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006243 case ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006244 // Return either landscape rotation.
6245 if (isLandscapeOrSeascape(preferredRotation)) {
6246 return preferredRotation;
6247 }
6248 if (isLandscapeOrSeascape(lastRotation)) {
Jeff Brown4519f072011-01-23 13:16:01 -08006249 return lastRotation;
6250 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006251 return mLandscapeRotation;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006252
Jeff Brown01a98dd2011-09-20 15:08:29 -07006253 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
Dianne Hackbornb9ec1ac2013-04-10 17:34:25 -07006254 case ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT:
Jeff Brown01a98dd2011-09-20 15:08:29 -07006255 // Return either portrait rotation.
6256 if (isAnyPortrait(preferredRotation)) {
6257 return preferredRotation;
6258 }
6259 if (isAnyPortrait(lastRotation)) {
6260 return lastRotation;
6261 }
6262 return mPortraitRotation;
6263
6264 default:
Jeff Brown4dfce202011-10-05 12:00:10 -07006265 // For USER, UNSPECIFIED, NOSENSOR, SENSOR and FULL_SENSOR,
6266 // just return the preferred orientation we already calculated.
Jeff Brown01a98dd2011-09-20 15:08:29 -07006267 if (preferredRotation >= 0) {
6268 return preferredRotation;
6269 }
Dianne Hackborndacea8c2011-04-21 17:26:39 -07006270 return Surface.ROTATION_0;
Daniel Sandlere7e5ac22011-02-22 16:10:21 -05006271 }
6272 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006273 }
6274
Jeff Brown01a98dd2011-09-20 15:08:29 -07006275 @Override
6276 public boolean rotationHasCompatibleMetricsLw(int orientation, int rotation) {
6277 switch (orientation) {
6278 case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
6279 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
6280 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT:
6281 return isAnyPortrait(rotation);
6282
6283 case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
6284 case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
6285 case ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE:
6286 return isLandscapeOrSeascape(rotation);
6287
6288 default:
6289 return true;
6290 }
Steve Howarda7bfe6a2010-09-23 16:47:49 -07006291 }
6292
Jeff Brownc0347aa2011-09-23 17:26:09 -07006293 @Override
6294 public void setRotationLw(int rotation) {
6295 mOrientationListener.setCurrentRotation(rotation);
6296 }
6297
Jeff Brown01a98dd2011-09-20 15:08:29 -07006298 private boolean isLandscapeOrSeascape(int rotation) {
6299 return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006300 }
6301
Jeff Brown01a98dd2011-09-20 15:08:29 -07006302 private boolean isAnyPortrait(int rotation) {
6303 return rotation == mPortraitRotation || rotation == mUpsideDownRotation;
Dianne Hackborne5439f22010-10-02 16:53:50 -07006304 }
6305
Jose Lima9546b202014-07-02 17:21:51 -07006306 @Override
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006307 public int getUserRotationMode() {
6308 return Settings.System.getIntForUser(mContext.getContentResolver(),
Brett Chabot7e55c402013-05-16 19:38:08 -07006309 Settings.System.ACCELEROMETER_ROTATION, 0, UserHandle.USER_CURRENT) != 0 ?
6310 WindowManagerPolicy.USER_ROTATION_FREE :
6311 WindowManagerPolicy.USER_ROTATION_LOCKED;
Svetoslav Ganov80943d82013-01-02 10:25:37 -08006312 }
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006313
6314 // User rotation: to be used when all else fails in assigning an orientation to the device
Jose Lima9546b202014-07-02 17:21:51 -07006315 @Override
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006316 public void setUserRotationMode(int mode, int rot) {
6317 ContentResolver res = mContext.getContentResolver();
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006318
6319 // mUserRotationMode and mUserRotation will be assigned by the content observer
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006320 if (mode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
Christopher Tate5e08af02012-09-21 17:17:22 -07006321 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006322 Settings.System.USER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006323 rot,
6324 UserHandle.USER_CURRENT);
6325 Settings.System.putIntForUser(res,
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05006326 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006327 0,
6328 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006329 } else {
Christopher Tate5e08af02012-09-21 17:17:22 -07006330 Settings.System.putIntForUser(res,
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006331 Settings.System.ACCELEROMETER_ROTATION,
Christopher Tate5e08af02012-09-21 17:17:22 -07006332 1,
6333 UserHandle.USER_CURRENT);
Daniel Sandlerb73617d2010-08-17 00:41:00 -04006334 }
6335 }
6336
Jose Lima9546b202014-07-02 17:21:51 -07006337 @Override
Jeff Brownac143512012-04-05 18:57:33 -07006338 public void setSafeMode(boolean safeMode) {
6339 mSafeMode = safeMode;
6340 performHapticFeedbackLw(null, safeMode
6341 ? HapticFeedbackConstants.SAFE_MODE_ENABLED
6342 : HapticFeedbackConstants.SAFE_MODE_DISABLED, true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006343 }
Craig Mautnereda67292013-04-28 13:50:14 -07006344
Dianne Hackborn181ceb52009-08-27 22:16:40 -07006345 static long[] getLongIntArray(Resources r, int resid) {
6346 int[] ar = r.getIntArray(resid);
6347 if (ar == null) {
6348 return null;
6349 }
6350 long[] out = new long[ar.length];
6351 for (int i=0; i<ar.length; i++) {
6352 out[i] = ar[i];
6353 }
6354 return out;
6355 }
Craig Mautnereda67292013-04-28 13:50:14 -07006356
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006357 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006358 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006359 public void systemReady() {
Jim Millerab954542014-10-10 18:21:49 -07006360 mKeyguardDelegate = new KeyguardServiceDelegate(mContext);
Mike Lockwooded8902d2013-11-15 11:01:47 -08006361 mKeyguardDelegate.onSystemReady();
6362
Michael Wright3818c922014-09-02 13:59:07 -07006363 readCameraLensCoverState();
Jeff Brown4f5fa282014-06-12 19:19:15 -07006364 updateUiMode();
Adrian Roos3542f7d2015-07-13 15:57:53 -07006365 boolean bindKeyguardNow;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006366 synchronized (mLock) {
6367 updateOrientationListenerLp();
Dianne Hackbornc777e072010-02-12 13:07:59 -08006368 mSystemReady = true;
6369 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006370 @Override
Dianne Hackbornc777e072010-02-12 13:07:59 -08006371 public void run() {
6372 updateSettings();
6373 }
6374 });
Adrian Roos3542f7d2015-07-13 15:57:53 -07006375
6376 bindKeyguardNow = mDeferBindKeyguard;
6377 if (bindKeyguardNow) {
6378 // systemBooted ran but wasn't able to bind to the Keyguard, we'll do it now.
6379 mDeferBindKeyguard = false;
6380 }
6381 }
6382
6383 if (bindKeyguardNow) {
6384 mKeyguardDelegate.bindService(mContext);
6385 mKeyguardDelegate.onBootCompleted();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006386 }
Michael Wrighta4d22d72015-09-16 23:19:26 +01006387 mSystemGestures.systemReady();
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006388 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006389
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006390 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006391 @Override
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006392 public void systemBooted() {
Adrian Roos3542f7d2015-07-13 15:57:53 -07006393 boolean bindKeyguardNow = false;
6394 synchronized (mLock) {
6395 // Time to bind Keyguard; take care to only bind it once, either here if ready or
6396 // in systemReady if not.
6397 if (mKeyguardDelegate != null) {
6398 bindKeyguardNow = true;
6399 } else {
6400 // Because mKeyguardDelegate is null, we know that the synchronized block in
6401 // systemReady didn't run yet and setting this will actually have an effect.
6402 mDeferBindKeyguard = true;
6403 }
6404 }
6405 if (bindKeyguardNow) {
Jason Monk5eeebf52014-09-26 12:36:51 -04006406 mKeyguardDelegate.bindService(mContext);
Jim Millere5f910a2013-10-16 18:15:46 -07006407 mKeyguardDelegate.onBootCompleted();
6408 }
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006409 synchronized (mLock) {
6410 mSystemBooted = true;
6411 }
Jeff Brown416c49c2015-05-26 19:50:18 -07006412 startedWakingUp();
Jeff Brown36c4db82014-09-19 12:05:31 -07006413 screenTurningOn(null);
Jorim Jaggic0496072015-08-19 15:14:52 -07006414 screenTurnedOn();
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07006415 }
6416
Dianne Hackborn661cd522011-08-22 00:26:20 -07006417 ProgressDialog mBootMsgDialog = null;
6418
6419 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006420 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006421 public void showBootMessage(final CharSequence msg, final boolean always) {
6422 mHandler.post(new Runnable() {
6423 @Override public void run() {
6424 if (mBootMsgDialog == null) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006425 int theme;
Jaewan Kim49117872016-01-19 17:24:08 +09006426 if (mContext.getPackageManager().hasSystemFeature(FEATURE_WATCH)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006427 theme = com.android.internal.R.style.Theme_Micro_Dialog_Alert;
Jaewan Kim49117872016-01-19 17:24:08 +09006428 } else if (mContext.getPackageManager().hasSystemFeature(FEATURE_TELEVISION)) {
Craig Stout4c0cb8a2014-04-04 13:03:10 -07006429 theme = com.android.internal.R.style.Theme_Leanback_Dialog_Alert;
6430 } else {
6431 theme = 0;
6432 }
Vinod Krishnanfa8fc412014-04-18 14:35:53 -07006433
6434 mBootMsgDialog = new ProgressDialog(mContext, theme) {
Dianne Hackborn295e3c22011-08-25 13:19:08 -07006435 // This dialog will consume all events coming in to
6436 // it, to avoid it trying to do things too early in boot.
6437 @Override public boolean dispatchKeyEvent(KeyEvent event) {
6438 return true;
6439 }
6440 @Override public boolean dispatchKeyShortcutEvent(KeyEvent event) {
6441 return true;
6442 }
6443 @Override public boolean dispatchTouchEvent(MotionEvent ev) {
6444 return true;
6445 }
6446 @Override public boolean dispatchTrackballEvent(MotionEvent ev) {
6447 return true;
6448 }
6449 @Override public boolean dispatchGenericMotionEvent(MotionEvent ev) {
6450 return true;
6451 }
6452 @Override public boolean dispatchPopulateAccessibilityEvent(
6453 AccessibilityEvent event) {
6454 return true;
6455 }
6456 };
Jeff Hao9f60c082014-10-28 18:51:07 -07006457 if (mContext.getPackageManager().isUpgrade()) {
6458 mBootMsgDialog.setTitle(R.string.android_upgrading_title);
6459 } else {
6460 mBootMsgDialog.setTitle(R.string.android_start_title);
6461 }
Dianne Hackborn661cd522011-08-22 00:26:20 -07006462 mBootMsgDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
6463 mBootMsgDialog.setIndeterminate(true);
6464 mBootMsgDialog.getWindow().setType(
Dianne Hackborn29aae6f2011-08-18 18:30:09 -07006465 WindowManager.LayoutParams.TYPE_BOOT_PROGRESS);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006466 mBootMsgDialog.getWindow().addFlags(
6467 WindowManager.LayoutParams.FLAG_DIM_BEHIND
6468 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
6469 mBootMsgDialog.getWindow().setDimAmount(1);
Dianne Hackbornd9efb952011-12-07 14:56:51 -08006470 WindowManager.LayoutParams lp = mBootMsgDialog.getWindow().getAttributes();
6471 lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
6472 mBootMsgDialog.getWindow().setAttributes(lp);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006473 mBootMsgDialog.setCancelable(false);
6474 mBootMsgDialog.show();
6475 }
6476 mBootMsgDialog.setMessage(msg);
6477 }
6478 });
6479 }
6480
6481 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006482 @Override
Dianne Hackborn661cd522011-08-22 00:26:20 -07006483 public void hideBootMessages() {
Craig Mautnera631d492014-08-05 15:16:01 -07006484 mHandler.sendEmptyMessage(MSG_HIDE_BOOT_MESSAGE);
Dianne Hackborn661cd522011-08-22 00:26:20 -07006485 }
6486
Mike Lockwood28569302010-01-28 11:54:40 -05006487 /** {@inheritDoc} */
Jose Lima9546b202014-07-02 17:21:51 -07006488 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006489 public void userActivity() {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006490 // ***************************************
6491 // NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
6492 // ***************************************
6493 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
6494 // WITH ITS LOCKS HELD.
6495 //
6496 // This code must be VERY careful about the locks
6497 // it acquires.
6498 // In fact, the current code acquires way too many,
6499 // and probably has lurking deadlocks.
6500
Mike Lockwood28569302010-01-28 11:54:40 -05006501 synchronized (mScreenLockTimeout) {
6502 if (mLockScreenTimerActive) {
6503 // reset the timer
6504 mHandler.removeCallbacks(mScreenLockTimeout);
6505 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6506 }
6507 }
Daniel Sandler0601eb72011-04-13 01:01:32 -04006508 }
6509
Adam Cohenf7522022012-10-03 20:03:18 -07006510 class ScreenLockTimeout implements Runnable {
6511 Bundle options;
6512
6513 @Override
Mike Lockwood28569302010-01-28 11:54:40 -05006514 public void run() {
6515 synchronized (this) {
6516 if (localLOGV) Log.v(TAG, "mScreenLockTimeout activating keyguard");
Jim Miller5ecd8112013-01-09 18:50:26 -08006517 if (mKeyguardDelegate != null) {
6518 mKeyguardDelegate.doKeyguardTimeout(options);
Mike Lockwood3a74bd32011-08-12 13:55:22 -07006519 }
Mike Lockwood28569302010-01-28 11:54:40 -05006520 mLockScreenTimerActive = false;
Adam Cohenf7522022012-10-03 20:03:18 -07006521 options = null;
Mike Lockwood28569302010-01-28 11:54:40 -05006522 }
6523 }
Mike Lockwood28569302010-01-28 11:54:40 -05006524
Adam Cohenf7522022012-10-03 20:03:18 -07006525 public void setLockOptions(Bundle options) {
6526 this.options = options;
6527 }
6528 }
6529
6530 ScreenLockTimeout mScreenLockTimeout = new ScreenLockTimeout();
6531
Jose Lima9546b202014-07-02 17:21:51 -07006532 @Override
Adam Cohenf7522022012-10-03 20:03:18 -07006533 public void lockNow(Bundle options) {
Jim Miller93c518e2012-01-17 15:55:31 -08006534 mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DEVICE_POWER, null);
6535 mHandler.removeCallbacks(mScreenLockTimeout);
Adam Cohenf7522022012-10-03 20:03:18 -07006536 if (options != null) {
6537 // In case multiple calls are made to lockNow, we don't wipe out the options
6538 // until the runnable actually executes.
6539 mScreenLockTimeout.setLockOptions(options);
6540 }
Jim Miller93c518e2012-01-17 15:55:31 -08006541 mHandler.post(mScreenLockTimeout);
6542 }
6543
Mike Lockwood28569302010-01-28 11:54:40 -05006544 private void updateLockScreenTimeout() {
6545 synchronized (mScreenLockTimeout) {
Jeff Brown3ee549c2014-09-22 20:14:39 -07006546 boolean enable = (mAllowLockscreenWhenOn && mAwake &&
Jim Miller5ecd8112013-01-09 18:50:26 -08006547 mKeyguardDelegate != null && mKeyguardDelegate.isSecure());
Mike Lockwood28569302010-01-28 11:54:40 -05006548 if (mLockScreenTimerActive != enable) {
6549 if (enable) {
6550 if (localLOGV) Log.v(TAG, "setting lockscreen timer");
Jim Miller2967f482016-01-07 15:05:32 -08006551 mHandler.removeCallbacks(mScreenLockTimeout); // remove any pending requests
Mike Lockwood28569302010-01-28 11:54:40 -05006552 mHandler.postDelayed(mScreenLockTimeout, mLockScreenTimeout);
6553 } else {
6554 if (localLOGV) Log.v(TAG, "clearing lockscreen timer");
6555 mHandler.removeCallbacks(mScreenLockTimeout);
6556 }
6557 mLockScreenTimerActive = enable;
6558 }
6559 }
6560 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006561
Jeff Brown061ea992015-04-17 19:55:47 -07006562 private void updateDreamingSleepToken(boolean acquire) {
6563 if (acquire) {
6564 if (mDreamingSleepToken == null) {
6565 mDreamingSleepToken = mActivityManagerInternal.acquireSleepToken("Dream");
6566 }
6567 } else {
6568 if (mDreamingSleepToken != null) {
6569 mDreamingSleepToken.release();
Jeff Brown48d1b142015-06-10 16:36:03 -07006570 mDreamingSleepToken = null;
6571 }
6572 }
6573 }
6574
6575 private void updateScreenOffSleepToken(boolean acquire) {
6576 if (acquire) {
6577 if (mScreenOffSleepToken == null) {
6578 mScreenOffSleepToken = mActivityManagerInternal.acquireSleepToken("ScreenOff");
6579 }
6580 } else {
6581 if (mScreenOffSleepToken != null) {
6582 mScreenOffSleepToken.release();
6583 mScreenOffSleepToken = null;
Jeff Brown061ea992015-04-17 19:55:47 -07006584 }
6585 }
6586 }
6587
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006588 /** {@inheritDoc} */
Craig Mautnereda67292013-04-28 13:50:14 -07006589 @Override
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006590 public void enableScreenAfterBoot() {
6591 readLidState();
Jeff Brownc458ce92012-04-30 14:58:40 -07006592 applyLidSwitchState();
Jeff Brown01a98dd2011-09-20 15:08:29 -07006593 updateRotation(true);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006594 }
Dianne Hackbornf54c8f92009-09-19 14:03:57 -07006595
Jeff Brownc458ce92012-04-30 14:58:40 -07006596 private void applyLidSwitchState() {
Jeff Brownc458ce92012-04-30 14:58:40 -07006597 if (mLidState == LID_CLOSED && mLidControlsSleep) {
Jeff Brown6d8fd272014-05-20 21:24:38 -07006598 mPowerManager.goToSleep(SystemClock.uptimeMillis(),
Jeff Brownc12035c2014-08-13 18:52:25 -07006599 PowerManager.GO_TO_SLEEP_REASON_LID_SWITCH,
Jeff Brown6d8fd272014-05-20 21:24:38 -07006600 PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01006601 } else if (mLidState == LID_CLOSED && mLidControlsScreenLock) {
6602 mWindowManagerFuncs.lockDeviceNow();
Jeff Brownc458ce92012-04-30 14:58:40 -07006603 }
Jeff Browna20dda42014-05-27 20:57:24 -07006604
6605 synchronized (mLock) {
6606 updateWakeGestureListenerLp();
6607 }
Jeff Brown01a98dd2011-09-20 15:08:29 -07006608 }
6609
Jeff Brown4f5fa282014-06-12 19:19:15 -07006610 void updateUiMode() {
6611 if (mUiModeManager == null) {
6612 mUiModeManager = IUiModeManager.Stub.asInterface(
6613 ServiceManager.getService(Context.UI_MODE_SERVICE));
6614 }
6615 try {
6616 mUiMode = mUiModeManager.getCurrentModeType();
6617 } catch (RemoteException e) {
6618 }
6619 }
6620
Jeff Brown01a98dd2011-09-20 15:08:29 -07006621 void updateRotation(boolean alwaysSendConfiguration) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006622 try {
6623 //set orientation on WindowManager
Dianne Hackbornf87d1962012-04-04 12:48:24 -07006624 mWindowManager.updateRotation(alwaysSendConfiguration, false);
6625 } catch (RemoteException e) {
6626 // Ignore
6627 }
6628 }
6629
6630 void updateRotation(boolean alwaysSendConfiguration, boolean forceRelayout) {
6631 try {
6632 //set orientation on WindowManager
6633 mWindowManager.updateRotation(alwaysSendConfiguration, forceRelayout);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006634 } catch (RemoteException e) {
6635 // Ignore
6636 }
6637 }
6638
Daniel Sandler6396c722013-04-16 20:19:09 -04006639 /**
6640 * Return an Intent to launch the currently active dock app as home. Returns
6641 * null if the standard home should be launched, which is the case if any of the following is
6642 * true:
6643 * <ul>
6644 * <li>The device is not in either car mode or desk mode
keunyounga7710492015-09-23 11:33:58 -07006645 * <li>The device is in car mode but mEnableCarDockHomeCapture is false
Daniel Sandler6396c722013-04-16 20:19:09 -04006646 * <li>The device is in desk mode but ENABLE_DESK_DOCK_HOME_CAPTURE is false
6647 * <li>The device is in car mode but there's no CAR_DOCK app with METADATA_DOCK_HOME
6648 * <li>The device is in desk mode but there's no DESK_DOCK app with METADATA_DOCK_HOME
6649 * </ul>
Craig Mautnereda67292013-04-28 13:50:14 -07006650 * @return A dock intent.
Daniel Sandler6396c722013-04-16 20:19:09 -04006651 */
6652 Intent createHomeDockIntent() {
6653 Intent intent = null;
6654
6655 // What home does is based on the mode, not the dock state. That
6656 // is, when in car mode you should be taken to car home regardless
6657 // of whether we are actually in a car dock.
6658 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
keunyounga7710492015-09-23 11:33:58 -07006659 if (mEnableCarDockHomeCapture) {
Daniel Sandler6396c722013-04-16 20:19:09 -04006660 intent = mCarDockIntent;
6661 }
6662 } else if (mUiMode == Configuration.UI_MODE_TYPE_DESK) {
6663 if (ENABLE_DESK_DOCK_HOME_CAPTURE) {
6664 intent = mDeskDockIntent;
6665 }
Jeff Brown4f5fa282014-06-12 19:19:15 -07006666 } else if (mUiMode == Configuration.UI_MODE_TYPE_WATCH
6667 && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
6668 || mDockMode == Intent.EXTRA_DOCK_STATE_HE_DESK
6669 || mDockMode == Intent.EXTRA_DOCK_STATE_LE_DESK)) {
6670 // Always launch dock home from home when watch is docked, if it exists.
6671 intent = mDeskDockIntent;
Daniel Sandler6396c722013-04-16 20:19:09 -04006672 }
6673
6674 if (intent == null) {
6675 return null;
6676 }
6677
6678 ActivityInfo ai = null;
6679 ResolveInfo info = mContext.getPackageManager().resolveActivityAsUser(
6680 intent,
John Spurlockf56bef12013-07-09 09:51:46 -04006681 PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_META_DATA,
Craig Mautnerd625ab22013-09-06 13:40:31 -07006682 mCurrentUserId);
Daniel Sandler6396c722013-04-16 20:19:09 -04006683 if (info != null) {
6684 ai = info.activityInfo;
6685 }
6686 if (ai != null
6687 && ai.metaData != null
6688 && ai.metaData.getBoolean(Intent.METADATA_DOCK_HOME)) {
6689 intent = new Intent(intent);
6690 intent.setClassName(ai.packageName, ai.name);
6691 return intent;
6692 }
6693
6694 return null;
6695 }
6696
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006697 void startDockOrHome(boolean fromHomeKey, boolean awakenFromDreams) {
6698 if (awakenFromDreams) {
6699 awakenDreams();
6700 }
Daniel Sandler6396c722013-04-16 20:19:09 -04006701
6702 Intent dock = createHomeDockIntent();
6703 if (dock != null) {
6704 try {
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006705 if (fromHomeKey) {
6706 dock.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6707 }
Bart Sears8b1c27c2015-03-18 23:51:02 +00006708 startActivityAsUser(dock, UserHandle.CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006709 return;
6710 } catch (ActivityNotFoundException e) {
6711 }
6712 }
6713
Bryce Lee01b0c5f2015-02-05 18:24:04 -08006714 Intent intent;
6715
6716 if (fromHomeKey) {
6717 intent = new Intent(mHomeIntent);
6718 intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
6719 } else {
6720 intent = mHomeIntent;
6721 }
6722
Bryce Lee9fc0b6f2015-03-19 21:37:45 +00006723 startActivityAsUser(intent, UserHandle.CURRENT);
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006724 }
Craig Mautnereda67292013-04-28 13:50:14 -07006725
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006726 /**
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006727 * goes to the home screen
6728 * @return whether it did anything
6729 */
6730 boolean goHome() {
Bart Sears8b1c27c2015-03-18 23:51:02 +00006731 if (!isUserSetupComplete()) {
6732 Slog.i(TAG, "Not going home because user setup is in progress.");
6733 return false;
6734 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006735 if (false) {
6736 // This code always brings home to the front.
Dianne Hackborn256dd3b2009-05-19 18:51:21 -07006737 try {
6738 ActivityManagerNative.getDefault().stopAppSwitches();
6739 } catch (RemoteException e) {
6740 }
Dianne Hackborn94a679d2009-07-28 17:51:07 -07006741 sendCloseSystemWindows();
Filip Gruszczynskia483a1d2015-03-17 19:06:58 +00006742 startDockOrHome(false /*fromHomeKey*/, true /* awakenFromDreams */);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006743 } else {
6744 // This code brings home to the front or, if it is already
6745 // at the front, puts the device to sleep.
6746 try {
Wink Savilled2e6a332010-02-12 12:12:06 -08006747 if (SystemProperties.getInt("persist.sys.uts-test-mode", 0) == 1) {
6748 /// Roll back EndcallBehavior as the cupcake design to pass P1 lab entry.
6749 Log.d(TAG, "UTS-TEST-MODE");
6750 } else {
6751 ActivityManagerNative.getDefault().stopAppSwitches();
6752 sendCloseSystemWindows();
Daniel Sandler6396c722013-04-16 20:19:09 -04006753 Intent dock = createHomeDockIntent();
6754 if (dock != null) {
6755 int result = ActivityManagerNative.getDefault()
6756 .startActivityAsUser(null, null, dock,
6757 dock.resolveTypeIfNeeded(mContext.getContentResolver()),
6758 null, null, 0,
6759 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006760 null, null, UserHandle.USER_CURRENT);
Daniel Sandler6396c722013-04-16 20:19:09 -04006761 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
6762 return false;
6763 }
6764 }
Dianne Hackborn39c2d712009-09-22 11:41:31 -07006765 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006766 int result = ActivityManagerNative.getDefault()
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006767 .startActivityAsUser(null, null, mHomeIntent,
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006768 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
Dianne Hackborna4972e92012-03-14 10:38:05 -07006769 null, null, 0,
6770 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
Jeff Hao1b012d32014-08-20 10:35:34 -07006771 null, null, UserHandle.USER_CURRENT);
Dianne Hackborna4972e92012-03-14 10:38:05 -07006772 if (result == ActivityManager.START_RETURN_INTENT_TO_CALLER) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006773 return false;
6774 }
6775 } catch (RemoteException ex) {
6776 // bummer, the activity manager, which is in this process, is dead
6777 }
6778 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006779 return true;
6780 }
Craig Mautnereda67292013-04-28 13:50:14 -07006781
6782 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006783 public void setCurrentOrientationLw(int newOrientation) {
6784 synchronized (mLock) {
6785 if (newOrientation != mCurrentAppOrientation) {
6786 mCurrentAppOrientation = newOrientation;
6787 updateOrientationListenerLp();
6788 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006789 }
6790 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006791
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006792 private void performAuditoryFeedbackForAccessibilityIfNeed() {
6793 if (!isGlobalAccessibilityGestureEnabled()) {
6794 return;
6795 }
6796 AudioManager audioManager = (AudioManager) mContext.getSystemService(
6797 Context.AUDIO_SERVICE);
6798 if (audioManager.isSilentMode()) {
6799 return;
6800 }
6801 Ringtone ringTone = RingtoneManager.getRingtone(mContext,
6802 Settings.System.DEFAULT_NOTIFICATION_URI);
6803 ringTone.setStreamType(AudioManager.STREAM_MUSIC);
6804 ringTone.play();
6805 }
Craig Mautnereda67292013-04-28 13:50:14 -07006806
Bryce Lee584a4452014-10-21 15:55:55 -07006807 private boolean isTheaterModeEnabled() {
6808 return Settings.Global.getInt(mContext.getContentResolver(),
6809 Settings.Global.THEATER_MODE_ON, 0) == 1;
6810 }
6811
Svetoslav Ganov7befb7d2012-09-27 16:49:23 -07006812 private boolean isGlobalAccessibilityGestureEnabled() {
6813 return Settings.Global.getInt(mContext.getContentResolver(),
6814 Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED, 0) == 1;
6815 }
6816
Craig Mautnereda67292013-04-28 13:50:14 -07006817 @Override
The Android Open Source Project0727d222009-03-11 12:11:58 -07006818 public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean always) {
Svetoslav Ganov96179212012-10-10 14:17:45 -07006819 if (!mVibrator.hasVibrator()) {
6820 return false;
6821 }
Christopher Tate5e08af02012-09-21 17:17:22 -07006822 final boolean hapticsDisabled = Settings.System.getIntForUser(mContext.getContentResolver(),
6823 Settings.System.HAPTIC_FEEDBACK_ENABLED, 0, UserHandle.USER_CURRENT) == 0;
Jeff Brown82379ba2014-07-25 19:03:28 -07006824 if (hapticsDisabled && !always) {
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006825 return false;
6826 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006827 long[] pattern = null;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006828 switch (effectId) {
6829 case HapticFeedbackConstants.LONG_PRESS:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006830 pattern = mLongPressVibePattern;
6831 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006832 case HapticFeedbackConstants.VIRTUAL_KEY:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006833 pattern = mVirtualKeyVibePattern;
6834 break;
6835 case HapticFeedbackConstants.KEYBOARD_TAP:
6836 pattern = mKeyboardTapVibePattern;
6837 break;
Fabrice Di Meglioeeff63a2013-08-05 12:07:24 -07006838 case HapticFeedbackConstants.CLOCK_TICK:
6839 pattern = mClockTickVibePattern;
6840 break;
Fabrice Di Megliobd9152f2013-10-01 11:21:31 -07006841 case HapticFeedbackConstants.CALENDAR_DATE:
6842 pattern = mCalendarDateVibePattern;
6843 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006844 case HapticFeedbackConstants.SAFE_MODE_DISABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006845 pattern = mSafeModeDisabledVibePattern;
6846 break;
Dianne Hackbornb1a79802009-09-29 15:18:31 -07006847 case HapticFeedbackConstants.SAFE_MODE_ENABLED:
Amith Yamasanic33cb712010-02-10 15:21:49 -08006848 pattern = mSafeModeEnabledVibePattern;
6849 break;
Mady Mellore8608912015-06-05 09:02:55 -07006850 case HapticFeedbackConstants.CONTEXT_CLICK:
6851 pattern = mContextClickVibePattern;
Mady Mellore82067b2015-04-30 09:58:35 -07006852 break;
Amith Yamasanic33cb712010-02-10 15:21:49 -08006853 default:
6854 return false;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006855 }
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006856 int owningUid;
6857 String owningPackage;
6858 if (win != null) {
6859 owningUid = win.getOwningUid();
6860 owningPackage = win.getOwningPackage();
6861 } else {
6862 owningUid = android.os.Process.myUid();
Dianne Hackborn95d78532013-09-11 09:51:14 -07006863 owningPackage = mContext.getOpPackageName();
Dianne Hackbornf265ea92013-01-31 15:00:51 -08006864 }
Amith Yamasanic33cb712010-02-10 15:21:49 -08006865 if (pattern.length == 1) {
6866 // One-shot vibration
John Spurlock7b414672014-07-18 13:02:39 -04006867 mVibrator.vibrate(owningUid, owningPackage, pattern[0], VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006868 } else {
6869 // Pattern vibration
John Spurlock7b414672014-07-18 13:02:39 -04006870 mVibrator.vibrate(owningUid, owningPackage, pattern, -1, VIBRATION_ATTRIBUTES);
Amith Yamasanic33cb712010-02-10 15:21:49 -08006871 }
6872 return true;
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006873 }
Jeff Brownc38c9be2012-10-04 13:16:19 -07006874
6875 @Override
6876 public void keepScreenOnStartedLw() {
Daniel Sandler0601eb72011-04-13 01:01:32 -04006877 }
6878
Jeff Brownc38c9be2012-10-04 13:16:19 -07006879 @Override
6880 public void keepScreenOnStoppedLw() {
Jim Millerab954542014-10-10 18:21:49 -07006881 if (isKeyguardShowingAndNotOccluded()) {
Jim Miller25190572013-02-28 17:36:24 -08006882 mPowerManager.userActivity(SystemClock.uptimeMillis(), false);
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08006883 }
6884 }
Mike Lockwoodfcb39242009-10-21 23:01:07 -04006885
Dianne Hackborndf89e652011-10-06 22:35:11 -07006886 private int updateSystemUiVisibilityLw() {
Joe Onorato664644d2011-01-23 17:53:23 -08006887 // If there is no window focused, there will be nobody to handle the events
6888 // anyway, so just hang on in whatever state we're in until things settle down.
Adrian Roos53f28ec2014-10-29 17:26:12 +01006889 final WindowState win = mFocusedWindow != null ? mFocusedWindow
6890 : mTopFullscreenOpaqueWindowState;
John Spurlock79da8332013-09-20 12:04:47 -04006891 if (win == null) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006892 return 0;
6893 }
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006894 if ((win.getAttrs().privateFlags & PRIVATE_FLAG_KEYGUARD) != 0 && mHideLockScreen == true) {
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07006895 // We are updating at a point where the keyguard has gotten
6896 // focus, but we were last in a state where the top window is
6897 // hiding it. This is probably because the keyguard as been
6898 // shown while the top window was displayed, so we want to ignore
6899 // it here because this is just a very transient change and it
6900 // will quickly lose focus once it correctly gets hidden.
6901 return 0;
6902 }
John Spurlock32beb2c2013-03-11 10:16:47 -04006903
John Spurlock1db8b682014-02-18 11:18:59 -05006904 int tmpVisibility = PolicyControl.getSystemUiVisibility(win, null)
Dianne Hackborne26ab702011-10-16 13:21:33 -07006905 & ~mResettingSystemUiFlags
6906 & ~mForceClearedSystemUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006907 if (mForcingShowNavBar && win.getSurfaceLayer() < mForcingShowNavBarLayer) {
John Spurlockc6d1c602014-01-17 15:22:06 -05006908 tmpVisibility &= ~PolicyControl.adjustClearableFlags(win, View.SYSTEM_UI_CLEARABLE_FLAGS);
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08006909 }
Thanh Hai Mai6c009f52015-09-01 16:27:32 -07006910
6911 if (mUiMode == Configuration.UI_MODE_TYPE_CAR) {
6912 tmpVisibility |= StatusBarManager.DISABLE_RECENT;
6913 }
6914
Jorim Jaggi86905582016-02-09 21:36:09 -08006915 final int fullscreenVisibility = updateLightStatusBarLw(0 /* vis */,
6916 mTopFullscreenOpaqueWindowState, mTopFullscreenOpaqueOrDimmingWindowState);
6917 final int dockedVisibility = updateLightStatusBarLw(0 /* vis */,
6918 mTopDockedOpaqueWindowState, mTopDockedOpaqueOrDimmingWindowState);
6919 mWindowManagerFuncs.getStackBounds(HOME_STACK_ID, mNonDockedStackBounds);
6920 mWindowManagerFuncs.getStackBounds(DOCKED_STACK_ID, mDockedStackBounds);
John Spurlock79da8332013-09-20 12:04:47 -04006921 final int visibility = updateSystemBarsLw(win, mLastSystemUiFlags, tmpVisibility);
John Spurlockad3e6cb2013-04-30 08:47:43 -04006922 final int diff = visibility ^ mLastSystemUiFlags;
Jorim Jaggi86905582016-02-09 21:36:09 -08006923 final int fullscreenDiff = fullscreenVisibility ^ mLastFullscreenStackSysUiFlags;
6924 final int dockedDiff = dockedVisibility ^ mLastDockedStackSysUiFlags;
John Spurlock79da8332013-09-20 12:04:47 -04006925 final boolean needsMenu = win.getNeedsMenuLw(mTopFullscreenOpaqueWindowState);
Jorim Jaggi86905582016-02-09 21:36:09 -08006926 if (diff == 0 && fullscreenDiff == 0 && dockedDiff == 0 && mLastFocusNeedsMenu == needsMenu
6927 && mFocusedApp == win.getAppToken()
6928 && mLastNonDockedStackBounds.equals(mNonDockedStackBounds)
6929 && mLastDockedStackBounds.equals(mDockedStackBounds)) {
Dianne Hackborndf89e652011-10-06 22:35:11 -07006930 return 0;
6931 }
Dianne Hackborne26ab702011-10-16 13:21:33 -07006932 mLastSystemUiFlags = visibility;
Jorim Jaggi86905582016-02-09 21:36:09 -08006933 mLastFullscreenStackSysUiFlags = fullscreenVisibility;
6934 mLastDockedStackSysUiFlags = dockedVisibility;
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08006935 mLastFocusNeedsMenu = needsMenu;
John Spurlock79da8332013-09-20 12:04:47 -04006936 mFocusedApp = win.getAppToken();
Jorim Jaggi86905582016-02-09 21:36:09 -08006937 final Rect fullscreenStackBounds = new Rect(mNonDockedStackBounds);
6938 final Rect dockedStackBounds = new Rect(mDockedStackBounds);
Dianne Hackborndf89e652011-10-06 22:35:11 -07006939 mHandler.post(new Runnable() {
Craig Mautnereda67292013-04-28 13:50:14 -07006940 @Override
Dianne Hackborndf89e652011-10-06 22:35:11 -07006941 public void run() {
Jorim Jaggi86905582016-02-09 21:36:09 -08006942 StatusBarManagerInternal statusbar = getStatusBarManagerInternal();
6943 if (statusbar != null) {
6944 statusbar.setSystemUiVisibility(visibility, fullscreenVisibility,
6945 dockedVisibility, 0xffffffff, fullscreenStackBounds,
6946 dockedStackBounds, win.toString());
6947 statusbar.topAppWindowChanged(needsMenu);
Joe Onorato664644d2011-01-23 17:53:23 -08006948 }
Dianne Hackborndf89e652011-10-06 22:35:11 -07006949 }
6950 });
6951 return diff;
Joe Onorato664644d2011-01-23 17:53:23 -08006952 }
6953
Jorim Jaggi86905582016-02-09 21:36:09 -08006954 private int updateLightStatusBarLw(int vis, WindowState opaque, WindowState opaqueOrDimming) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01006955 WindowState statusColorWin = isStatusBarKeyguard() && !mHideLockScreen
6956 ? mStatusBar
Jorim Jaggi86905582016-02-09 21:36:09 -08006957 : opaqueOrDimming;
Adrian Rooscd3884d2015-02-18 17:25:23 +01006958
6959 if (statusColorWin != null) {
Jorim Jaggi86905582016-02-09 21:36:09 -08006960 if (statusColorWin == opaque) {
Adrian Rooscd3884d2015-02-18 17:25:23 +01006961 // If the top fullscreen-or-dimming window is also the top fullscreen, respect
6962 // its light flag.
6963 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6964 vis |= PolicyControl.getSystemUiVisibility(statusColorWin, null)
6965 & View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6966 } else if (statusColorWin != null && statusColorWin.isDimming()) {
6967 // Otherwise if it's dimming, clear the light flag.
6968 vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
6969 }
6970 }
6971 return vis;
6972 }
6973
John Spurlock79da8332013-09-20 12:04:47 -04006974 private int updateSystemBarsLw(WindowState win, int oldVis, int vis) {
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006975 final boolean dockedStackVisible = mWindowManagerInternal.isStackVisible(DOCKED_STACK_ID);
6976 final boolean freeformStackVisible =
6977 mWindowManagerInternal.isStackVisible(FREEFORM_WORKSPACE_STACK_ID);
Jorim Jaggi9511b0f2016-01-29 19:12:44 -08006978 final boolean resizing = mWindowManagerInternal.isDockedDividerResizing();
6979
6980 // We need to force system bars when the docked stack is visible, when the freeform stack
6981 // is visible but also when we are resizing for the transitions when docked stack
6982 // visibility changes.
6983 final boolean forceShowSystemBars = dockedStackVisible || freeformStackVisible || resizing;
Jorim Jaggi4fa78922015-11-30 17:13:56 -08006984 final boolean forceOpaqueSystemBars = forceShowSystemBars && !mForceStatusBarFromKeyguard;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07006985
John Spurlockbd957402013-10-03 11:38:39 -04006986 // apply translucent bar vis flags
Jorim Jaggi380ecb82014-03-14 17:25:20 +01006987 WindowState transWin = isStatusBarKeyguard() && !mHideLockScreen
6988 ? mStatusBar
John Spurlockbd957402013-10-03 11:38:39 -04006989 : mTopFullscreenOpaqueWindowState;
6990 vis = mStatusBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6991 vis = mNavigationBarController.applyTranslucentFlagLw(transWin, vis, oldVis);
6992
John Spurlock27735a42013-08-14 17:57:38 -04006993 // prevent status bar interaction from clearing certain flags
Selim Cinekf83e8242015-05-19 18:08:14 -07006994 int type = win.getAttrs().type;
6995 boolean statusBarHasFocus = type == TYPE_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04006996 if (statusBarHasFocus && !isStatusBarKeyguard()) {
John Spurlockad3e6cb2013-04-30 08:47:43 -04006997 int flags = View.SYSTEM_UI_FLAG_FULLSCREEN
6998 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
John Spurlockcfc359a2013-09-05 10:42:03 -04006999 | View.SYSTEM_UI_FLAG_IMMERSIVE
Jorim Jaggi73fef8d2015-02-16 17:32:28 +01007000 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
7001 | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
John Spurlock08ffcf52014-07-11 10:13:46 -04007002 if (mHideLockScreen) {
Jorim Jaggi5cf17872014-03-26 18:31:48 +01007003 flags |= View.STATUS_BAR_TRANSLUCENT | View.NAVIGATION_BAR_TRANSLUCENT;
7004 }
John Spurlockbd957402013-10-03 11:38:39 -04007005 vis = (vis & ~flags) | (oldVis & flags);
John Spurlockad3e6cb2013-04-30 08:47:43 -04007006 }
John Spurlockad3e6cb2013-04-30 08:47:43 -04007007
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007008 if ((!areTranslucentBarsAllowed() && transWin != mStatusBar)
7009 || forceOpaqueSystemBars) {
Adrian Roosea562512014-05-05 13:33:03 +02007010 vis &= ~(View.NAVIGATION_BAR_TRANSLUCENT | View.STATUS_BAR_TRANSLUCENT
7011 | View.SYSTEM_UI_TRANSPARENT);
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007012 }
7013
Jorim Jaggi4fa78922015-11-30 17:13:56 -08007014 if (mForceWindowDrawsStatusBarBackground) {
7015 vis |= View.STATUS_BAR_TRANSPARENT;
7016 vis &= ~View.STATUS_BAR_TRANSLUCENT;
7017 }
7018
John Spurlock27735a42013-08-14 17:57:38 -04007019 // update status bar
John Spurlockf1a36642013-10-12 17:50:42 -04007020 boolean immersiveSticky =
7021 (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007022 final boolean hideStatusBarWM =
7023 mTopFullscreenOpaqueWindowState != null
7024 && (PolicyControl.getWindowFlags(mTopFullscreenOpaqueWindowState, null)
John Spurlock27735a42013-08-14 17:57:38 -04007025 & WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007026 final boolean hideStatusBarSysui =
John Spurlock27735a42013-08-14 17:57:38 -04007027 (vis & View.SYSTEM_UI_FLAG_FULLSCREEN) != 0;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007028 final boolean hideNavBarSysui =
John Spurlockf1a36642013-10-12 17:50:42 -04007029 (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007030
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007031 final boolean transientStatusBarAllowed = mStatusBar != null
7032 && (statusBarHasFocus || (!forceShowSystemBars
7033 && (hideStatusBarWM || (hideStatusBarSysui && immersiveSticky))));
John Spurlock27735a42013-08-14 17:57:38 -04007034
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007035 final boolean transientNavBarAllowed = mNavigationBar != null
7036 && !forceShowSystemBars && hideNavBarSysui && immersiveSticky;
John Spurlockf1a36642013-10-12 17:50:42 -04007037
Adrian Roosddc8b272015-05-21 16:28:27 -07007038 final long now = SystemClock.uptimeMillis();
7039 final boolean pendingPanic = mPendingPanicGestureUptime != 0
7040 && now - mPendingPanicGestureUptime <= PANIC_GESTURE_EXPIRATION;
7041 if (pendingPanic && hideNavBarSysui && !isStatusBarKeyguard() && mKeyguardDrawComplete) {
7042 // The user performed the panic gesture recently, we're about to hide the bars,
7043 // we're no longer on the Keyguard and the screen is ready. We can now request the bars.
7044 mPendingPanicGestureUptime = 0;
7045 mStatusBarController.showTransient();
7046 mNavigationBarController.showTransient();
7047 }
7048
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007049 final boolean denyTransientStatus = mStatusBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007050 && !transientStatusBarAllowed && hideStatusBarSysui;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007051 final boolean denyTransientNav = mNavigationBarController.isTransientShowRequested()
John Spurlockf1a36642013-10-12 17:50:42 -04007052 && !transientNavBarAllowed;
Wale Ogunwale6e94a9e2015-10-07 15:35:49 -07007053 if (denyTransientStatus || denyTransientNav || forceShowSystemBars) {
John Spurlock27735a42013-08-14 17:57:38 -04007054 // clear the clearable flags instead
John Spurlockf1a36642013-10-12 17:50:42 -04007055 clearClearableFlagsLw();
tiger_huangc58d7562014-10-23 20:24:19 +08007056 vis &= ~View.SYSTEM_UI_CLEARABLE_FLAGS;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007057 }
John Spurlock27735a42013-08-14 17:57:38 -04007058
Selim Cinekf98702e2015-05-20 22:48:40 -07007059 final boolean immersive = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE) != 0;
7060 immersiveSticky = (vis & View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) != 0;
7061 final boolean navAllowedHidden = immersive || immersiveSticky;
7062
Selim Cinekd6623612015-05-22 18:56:22 -07007063 if (hideNavBarSysui && !navAllowedHidden && windowTypeToLayerLw(win.getBaseType())
7064 > windowTypeToLayerLw(TYPE_INPUT_CONSUMER)) {
Selim Cinekf98702e2015-05-20 22:48:40 -07007065 // We can't hide the navbar from this window otherwise the input consumer would not get
7066 // the input events.
7067 vis = (vis & ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
7068 }
7069
John Spurlock27735a42013-08-14 17:57:38 -04007070 vis = mStatusBarController.updateVisibilityLw(transientStatusBarAllowed, oldVis, vis);
7071
7072 // update navigation bar
John Spurlockf1a36642013-10-12 17:50:42 -04007073 boolean oldImmersiveMode = isImmersiveMode(oldVis);
7074 boolean newImmersiveMode = isImmersiveMode(vis);
7075 if (win != null && oldImmersiveMode != newImmersiveMode) {
John Spurlock79da8332013-09-20 12:04:47 -04007076 final String pkg = win.getOwningPackage();
Maurice Lam99c6e072014-04-28 18:24:28 -07007077 mImmersiveModeConfirmation.immersiveModeChanged(pkg, newImmersiveMode,
7078 isUserSetupComplete());
John Spurlock34e13d92013-08-10 06:52:28 -04007079 }
John Spurlock27735a42013-08-14 17:57:38 -04007080
John Spurlockf1a36642013-10-12 17:50:42 -04007081 vis = mNavigationBarController.updateVisibilityLw(transientNavBarAllowed, oldVis, vis);
7082
John Spurlocke1f366f2013-08-05 12:22:40 -04007083 return vis;
John Spurlockad3e6cb2013-04-30 08:47:43 -04007084 }
7085
John Spurlockf1a36642013-10-12 17:50:42 -04007086 private void clearClearableFlagsLw() {
7087 int newVal = mResettingSystemUiFlags | View.SYSTEM_UI_CLEARABLE_FLAGS;
7088 if (newVal != mResettingSystemUiFlags) {
7089 mResettingSystemUiFlags = newVal;
7090 mWindowManagerFuncs.reevaluateStatusBarVisibility();
7091 }
7092 }
7093
7094 private boolean isImmersiveMode(int vis) {
7095 final int flags = View.SYSTEM_UI_FLAG_IMMERSIVE | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
John Spurlock34e13d92013-08-10 06:52:28 -04007096 return mNavigationBar != null
7097 && (vis & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 0
Daniel Sandler900ece52013-10-18 15:53:27 -04007098 && (vis & flags) != 0
7099 && canHideNavigationBar();
John Spurlock34e13d92013-08-10 06:52:28 -04007100 }
7101
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007102 /**
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007103 * @return whether the navigation or status bar can be made translucent
7104 *
7105 * This should return true unless touch exploration is not enabled or
7106 * R.boolean.config_enableTranslucentDecor is false.
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007107 */
Daniel Sandlerdd73ee42013-10-11 22:19:59 -04007108 private boolean areTranslucentBarsAllowed() {
Alan Viverette817f3cd2015-08-13 11:40:14 -04007109 return mTranslucentDecorEnabled;
Alan Viverette5a0f4ec2013-10-07 15:10:29 -07007110 }
7111
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007112 // Use this instead of checking config_showNavigationBar so that it can be consistently
7113 // overridden by qemu.hw.mainkeys in the emulator.
Craig Mautnereda67292013-04-28 13:50:14 -07007114 @Override
Daniel Sandler0c4ccff2011-10-19 16:39:14 -04007115 public boolean hasNavigationBar() {
7116 return mHasNavigationBar;
7117 }
7118
satok1bc0a492012-04-25 22:47:12 +09007119 @Override
7120 public void setLastInputMethodWindowLw(WindowState ime, WindowState target) {
7121 mLastInputMethodWindow = ime;
7122 mLastInputMethodTargetWindow = target;
7123 }
7124
Craig Mautnerf1b67412012-09-19 13:18:29 -07007125 @Override
Satoshi Kataoka658c7b82013-10-10 17:03:51 +09007126 public int getInputMethodWindowVisibleHeightLw() {
7127 return mDockBottom - mCurBottom;
7128 }
7129
7130 @Override
Craig Mautnerf1b67412012-09-19 13:18:29 -07007131 public void setCurrentUserLw(int newUserId) {
Craig Mautnerd625ab22013-09-06 13:40:31 -07007132 mCurrentUserId = newUserId;
Jim Miller5ecd8112013-01-09 18:50:26 -08007133 if (mKeyguardDelegate != null) {
7134 mKeyguardDelegate.setCurrentUser(newUserId);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007135 }
John Spurlock13451a22012-09-28 14:40:41 -04007136 if (mStatusBarService != null) {
7137 try {
7138 mStatusBarService.setCurrentUser(newUserId);
7139 } catch (RemoteException e) {
7140 // oh well
7141 }
7142 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007143 setLastInputMethodWindowLw(null, null);
Craig Mautnerf1b67412012-09-19 13:18:29 -07007144 }
7145
7146 @Override
Svetoslav Ganov545252f2012-12-10 18:29:24 -08007147 public boolean canMagnifyWindow(int windowType) {
7148 switch (windowType) {
7149 case WindowManager.LayoutParams.TYPE_INPUT_METHOD:
7150 case WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG:
7151 case WindowManager.LayoutParams.TYPE_NAVIGATION_BAR:
7152 case WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY: {
7153 return false;
7154 }
7155 }
7156 return true;
7157 }
7158
7159 @Override
7160 public boolean isTopLevelWindow(int windowType) {
7161 if (windowType >= WindowManager.LayoutParams.FIRST_SUB_WINDOW
7162 && windowType <= WindowManager.LayoutParams.LAST_SUB_WINDOW) {
7163 return (windowType == WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG);
7164 }
7165 return true;
7166 }
7167
Jim Miller4eeb4f62012-11-08 00:04:29 -08007168 @Override
Jeff Brownd7a04de2012-06-17 14:17:52 -07007169 public void dump(String prefix, PrintWriter pw, String[] args) {
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007170 pw.print(prefix); pw.print("mSafeMode="); pw.print(mSafeMode);
Dianne Hackbornba24e4d2011-09-01 11:17:06 -07007171 pw.print(" mSystemReady="); pw.print(mSystemReady);
7172 pw.print(" mSystemBooted="); pw.println(mSystemBooted);
Jeff Brown2e7760e2012-04-11 15:14:55 -07007173 pw.print(prefix); pw.print("mLidState="); pw.print(mLidState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007174 pw.print(" mLidOpenRotation="); pw.print(mLidOpenRotation);
Michael Wright3818c922014-09-02 13:59:07 -07007175 pw.print(" mCameraLensCoverState="); pw.print(mCameraLensCoverState);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007176 pw.print(" mHdmiPlugged="); pw.println(mHdmiPlugged);
Dianne Hackborne26ab702011-10-16 13:21:33 -07007177 if (mLastSystemUiFlags != 0 || mResettingSystemUiFlags != 0
7178 || mForceClearedSystemUiFlags != 0) {
7179 pw.print(prefix); pw.print("mLastSystemUiFlags=0x");
7180 pw.print(Integer.toHexString(mLastSystemUiFlags));
7181 pw.print(" mResettingSystemUiFlags=0x");
7182 pw.print(Integer.toHexString(mResettingSystemUiFlags));
7183 pw.print(" mForceClearedSystemUiFlags=0x");
7184 pw.println(Integer.toHexString(mForceClearedSystemUiFlags));
Dianne Hackborndf89e652011-10-06 22:35:11 -07007185 }
Dianne Hackborn4eff8d32011-11-10 19:38:40 -08007186 if (mLastFocusNeedsMenu) {
7187 pw.print(prefix); pw.print("mLastFocusNeedsMenu=");
7188 pw.println(mLastFocusNeedsMenu);
7189 }
Jeff Browna20dda42014-05-27 20:57:24 -07007190 pw.print(prefix); pw.print("mWakeGestureEnabledSetting=");
7191 pw.println(mWakeGestureEnabledSetting);
7192
Jeff Brownbcdfc622014-03-06 19:13:04 -08007193 pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation);
Daniel Sandler6396c722013-04-16 20:19:09 -04007194 pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode);
7195 pw.print(" mDockMode="); pw.print(mDockMode);
keunyounga7710492015-09-23 11:33:58 -07007196 pw.print(" mEnableCarDockHomeCapture="); pw.print(mEnableCarDockHomeCapture);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007197 pw.print(" mCarDockRotation="); pw.print(mCarDockRotation);
7198 pw.print(" mDeskDockRotation="); pw.println(mDeskDockRotation);
7199 pw.print(prefix); pw.print("mUserRotationMode="); pw.print(mUserRotationMode);
7200 pw.print(" mUserRotation="); pw.print(mUserRotation);
Daniel Sandler2ed6ad62011-02-22 14:54:17 -05007201 pw.print(" mAllowAllRotations="); pw.println(mAllowAllRotations);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007202 pw.print(prefix); pw.print("mCurrentAppOrientation="); pw.println(mCurrentAppOrientation);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007203 pw.print(prefix); pw.print("mCarDockEnablesAccelerometer=");
7204 pw.print(mCarDockEnablesAccelerometer);
7205 pw.print(" mDeskDockEnablesAccelerometer=");
7206 pw.println(mDeskDockEnablesAccelerometer);
7207 pw.print(prefix); pw.print("mLidKeyboardAccessibility=");
7208 pw.print(mLidKeyboardAccessibility);
7209 pw.print(" mLidNavigationAccessibility="); pw.print(mLidNavigationAccessibility);
Edward Savage-Jones7def60d2015-11-13 13:27:03 +01007210 pw.print(" mLidControlsScreenLock="); pw.println(mLidControlsScreenLock);
Dianne Hackborn6e2281d2012-06-19 17:48:32 -07007211 pw.print(" mLidControlsSleep="); pw.println(mLidControlsSleep);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007212 pw.print(prefix);
7213 pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior);
7214 pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior);
Jeff Brown13f00f02014-10-31 14:45:50 -07007215 pw.print(prefix);
7216 pw.print("mDoublePressOnPowerBehavior="); pw.print(mDoublePressOnPowerBehavior);
7217 pw.print(" mTriplePressOnPowerBehavior="); pw.println(mTriplePressOnPowerBehavior);
Jeff Brown6d8fd272014-05-20 21:24:38 -07007218 pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput);
Jeff Brown3ee549c2014-09-22 20:14:39 -07007219 pw.print(prefix); pw.print("mAwake="); pw.println(mAwake);
7220 pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly);
7221 pw.print(" mScreenOnFully="); pw.println(mScreenOnFully);
7222 pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete);
7223 pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete);
7224 pw.print(prefix); pw.print("mOrientationSensorEnabled=");
7225 pw.println(mOrientationSensorEnabled);
Dianne Hackbornc652de82013-02-15 16:32:56 -08007226 pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft);
7227 pw.print(","); pw.print(mOverscanScreenTop);
7228 pw.print(") "); pw.print(mOverscanScreenWidth);
7229 pw.print("x"); pw.println(mOverscanScreenHeight);
7230 if (mOverscanLeft != 0 || mOverscanTop != 0
7231 || mOverscanRight != 0 || mOverscanBottom != 0) {
7232 pw.print(prefix); pw.print("mOverscan left="); pw.print(mOverscanLeft);
7233 pw.print(" top="); pw.print(mOverscanTop);
7234 pw.print(" right="); pw.print(mOverscanRight);
7235 pw.print(" bottom="); pw.println(mOverscanBottom);
7236 }
Dianne Hackborn313440842013-02-19 19:22:59 -08007237 pw.print(prefix); pw.print("mRestrictedOverscanScreen=(");
7238 pw.print(mRestrictedOverscanScreenLeft);
7239 pw.print(","); pw.print(mRestrictedOverscanScreenTop);
7240 pw.print(") "); pw.print(mRestrictedOverscanScreenWidth);
7241 pw.print("x"); pw.println(mRestrictedOverscanScreenHeight);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007242 pw.print(prefix); pw.print("mUnrestrictedScreen=("); pw.print(mUnrestrictedScreenLeft);
7243 pw.print(","); pw.print(mUnrestrictedScreenTop);
7244 pw.print(") "); pw.print(mUnrestrictedScreenWidth);
7245 pw.print("x"); pw.println(mUnrestrictedScreenHeight);
7246 pw.print(prefix); pw.print("mRestrictedScreen=("); pw.print(mRestrictedScreenLeft);
7247 pw.print(","); pw.print(mRestrictedScreenTop);
7248 pw.print(") "); pw.print(mRestrictedScreenWidth);
7249 pw.print("x"); pw.println(mRestrictedScreenHeight);
Dianne Hackborn5b5cc4d2012-05-16 13:15:00 -07007250 pw.print(prefix); pw.print("mStableFullscreen=("); pw.print(mStableFullscreenLeft);
7251 pw.print(","); pw.print(mStableFullscreenTop);
7252 pw.print(")-("); pw.print(mStableFullscreenRight);
7253 pw.print(","); pw.print(mStableFullscreenBottom); pw.println(")");
Dianne Hackborn3a3a6cf2012-03-26 10:24:04 -07007254 pw.print(prefix); pw.print("mStable=("); pw.print(mStableLeft);
7255 pw.print(","); pw.print(mStableTop);
7256 pw.print(")-("); pw.print(mStableRight);
7257 pw.print(","); pw.print(mStableBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007258 pw.print(prefix); pw.print("mSystem=("); pw.print(mSystemLeft);
7259 pw.print(","); pw.print(mSystemTop);
7260 pw.print(")-("); pw.print(mSystemRight);
7261 pw.print(","); pw.print(mSystemBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007262 pw.print(prefix); pw.print("mCur=("); pw.print(mCurLeft);
7263 pw.print(","); pw.print(mCurTop);
7264 pw.print(")-("); pw.print(mCurRight);
7265 pw.print(","); pw.print(mCurBottom); pw.println(")");
7266 pw.print(prefix); pw.print("mContent=("); pw.print(mContentLeft);
7267 pw.print(","); pw.print(mContentTop);
7268 pw.print(")-("); pw.print(mContentRight);
7269 pw.print(","); pw.print(mContentBottom); pw.println(")");
Dianne Hackborne30e02f2014-05-27 18:24:45 -07007270 pw.print(prefix); pw.print("mVoiceContent=("); pw.print(mVoiceContentLeft);
7271 pw.print(","); pw.print(mVoiceContentTop);
7272 pw.print(")-("); pw.print(mVoiceContentRight);
7273 pw.print(","); pw.print(mVoiceContentBottom); pw.println(")");
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007274 pw.print(prefix); pw.print("mDock=("); pw.print(mDockLeft);
7275 pw.print(","); pw.print(mDockTop);
7276 pw.print(")-("); pw.print(mDockRight);
7277 pw.print(","); pw.print(mDockBottom); pw.println(")");
Dianne Hackborn5c58de32012-04-28 19:52:37 -07007278 pw.print(prefix); pw.print("mDockLayer="); pw.print(mDockLayer);
7279 pw.print(" mStatusBarLayer="); pw.println(mStatusBarLayer);
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007280 pw.print(prefix); pw.print("mShowingLockscreen="); pw.print(mShowingLockscreen);
7281 pw.print(" mShowingDream="); pw.print(mShowingDream);
Jeff Brown061ea992015-04-17 19:55:47 -07007282 pw.print(" mDreamingLockscreen="); pw.print(mDreamingLockscreen);
7283 pw.print(" mDreamingSleepToken="); pw.println(mDreamingSleepToken);
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007284 if (mLastInputMethodWindow != null) {
7285 pw.print(prefix); pw.print("mLastInputMethodWindow=");
7286 pw.println(mLastInputMethodWindow);
7287 }
7288 if (mLastInputMethodTargetWindow != null) {
7289 pw.print(prefix); pw.print("mLastInputMethodTargetWindow=");
7290 pw.println(mLastInputMethodTargetWindow);
7291 }
7292 if (mStatusBar != null) {
7293 pw.print(prefix); pw.print("mStatusBar=");
Dianne Hackbornae6688b2015-02-11 17:02:41 -08007294 pw.print(mStatusBar); pw.print(" isStatusBarKeyguard=");
7295 pw.println(isStatusBarKeyguard());
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007296 }
7297 if (mNavigationBar != null) {
7298 pw.print(prefix); pw.print("mNavigationBar=");
7299 pw.println(mNavigationBar);
7300 }
Dianne Hackborn2ea9bae2012-11-02 18:43:48 -07007301 if (mFocusedWindow != null) {
7302 pw.print(prefix); pw.print("mFocusedWindow=");
7303 pw.println(mFocusedWindow);
7304 }
7305 if (mFocusedApp != null) {
7306 pw.print(prefix); pw.print("mFocusedApp=");
7307 pw.println(mFocusedApp);
7308 }
7309 if (mWinDismissingKeyguard != null) {
7310 pw.print(prefix); pw.print("mWinDismissingKeyguard=");
7311 pw.println(mWinDismissingKeyguard);
7312 }
7313 if (mTopFullscreenOpaqueWindowState != null) {
7314 pw.print(prefix); pw.print("mTopFullscreenOpaqueWindowState=");
7315 pw.println(mTopFullscreenOpaqueWindowState);
7316 }
Adrian Rooscd3884d2015-02-18 17:25:23 +01007317 if (mTopFullscreenOpaqueOrDimmingWindowState != null) {
7318 pw.print(prefix); pw.print("mTopFullscreenOpaqueOrDimmingWindowState=");
7319 pw.println(mTopFullscreenOpaqueOrDimmingWindowState);
7320 }
Dianne Hackborn891d3fb2013-01-09 18:31:37 -08007321 if (mForcingShowNavBar) {
7322 pw.print(prefix); pw.print("mForcingShowNavBar=");
7323 pw.println(mForcingShowNavBar); pw.print( "mForcingShowNavBarLayer=");
7324 pw.println(mForcingShowNavBarLayer);
7325 }
Dianne Hackborn7ad44382012-10-18 17:46:00 -07007326 pw.print(prefix); pw.print("mTopIsFullscreen="); pw.print(mTopIsFullscreen);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007327 pw.print(" mHideLockScreen="); pw.println(mHideLockScreen);
Dianne Hackborn4c1e3182012-10-05 18:37:54 -07007328 pw.print(prefix); pw.print("mForceStatusBar="); pw.print(mForceStatusBar);
7329 pw.print(" mForceStatusBarFromKeyguard=");
7330 pw.println(mForceStatusBarFromKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007331 pw.print(prefix); pw.print("mDismissKeyguard="); pw.print(mDismissKeyguard);
Craig Mautnerad09bcc2012-10-08 13:33:11 -07007332 pw.print(" mWinDismissingKeyguard="); pw.print(mWinDismissingKeyguard);
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007333 pw.print(" mHomePressed="); pw.println(mHomePressed);
7334 pw.print(prefix); pw.print("mAllowLockscreenWhenOn="); pw.print(mAllowLockscreenWhenOn);
7335 pw.print(" mLockScreenTimeout="); pw.print(mLockScreenTimeout);
7336 pw.print(" mLockScreenTimerActive="); pw.println(mLockScreenTimerActive);
7337 pw.print(prefix); pw.print("mEndcallBehavior="); pw.print(mEndcallBehavior);
7338 pw.print(" mIncallPowerBehavior="); pw.print(mIncallPowerBehavior);
7339 pw.print(" mLongPressOnHomeBehavior="); pw.println(mLongPressOnHomeBehavior);
7340 pw.print(prefix); pw.print("mLandscapeRotation="); pw.print(mLandscapeRotation);
7341 pw.print(" mSeascapeRotation="); pw.println(mSeascapeRotation);
7342 pw.print(prefix); pw.print("mPortraitRotation="); pw.print(mPortraitRotation);
7343 pw.print(" mUpsideDownRotation="); pw.println(mUpsideDownRotation);
Jeff Brownc82c89ed2013-04-17 17:18:15 -07007344 pw.print(prefix); pw.print("mDemoHdmiRotation="); pw.print(mDemoHdmiRotation);
7345 pw.print(" mDemoHdmiRotationLock="); pw.println(mDemoHdmiRotationLock);
7346 pw.print(prefix); pw.print("mUndockedHdmiRotation="); pw.println(mUndockedHdmiRotation);
Jeff Brown600f0032014-05-22 17:06:00 -07007347
Tim Kilbournd7c0c2e2014-05-29 16:08:10 -07007348 mGlobalKeyManager.dump(prefix, pw);
John Spurlock27735a42013-08-14 17:57:38 -04007349 mStatusBarController.dump(pw, prefix);
7350 mNavigationBarController.dump(pw, prefix);
John Spurlockc6d1c602014-01-17 15:22:06 -05007351 PolicyControl.dump(prefix, pw);
Jeff Brown600f0032014-05-22 17:06:00 -07007352
Jeff Browna20dda42014-05-27 20:57:24 -07007353 if (mWakeGestureListener != null) {
7354 mWakeGestureListener.dump(pw, prefix);
7355 }
Jeff Brown600f0032014-05-22 17:06:00 -07007356 if (mOrientationListener != null) {
7357 mOrientationListener.dump(pw, prefix);
7358 }
Filip Gruszczynskicfb31852015-02-25 21:47:12 +00007359 if (mBurnInProtectionHelper != null) {
7360 mBurnInProtectionHelper.dump(prefix, pw);
7361 }
Jorim Jaggi84dc08a2015-09-11 17:45:22 -07007362 if (mKeyguardDelegate != null) {
7363 mKeyguardDelegate.dump(prefix, pw);
7364 }
Dianne Hackbornf99f9c52011-01-12 15:49:25 -08007365 }
The Android Open Source Project1f838aa2009-03-03 19:32:13 -08007366}